That's exactly the point. It is not a selfless good deed, but just another transaction. Spend 20 million (not a huge amount for an ad campaign) get some good PR.
I am not saying that it is evil, shady or even questionable. But it should not be perceived in the same way as an individual donating a part of their income.
An individual donating probably means that they value some other things than money. A corporation donating means that they want "favorable image and ultimately increased sales".
I get your point, but this is a win for two parties (google and the charities) and I don't see any loss for the third party (the public).
http://investor.google.com/corporate/faq.html#dividend
"Does Google pay a cash dividend?
No, we have never declared or paid a cash dividend nor do we expect to pay any dividends in the foreseeable future."