Google has tried to build housing in Mountain View multiple times but their plans have been rejected:
http://www.mv-voice.com/print/story/2012/07/13/google-housin...
In general, it's much easier to build office space than housing. Cities like it because it generates revenue but they don't have to provide additional support services such as schools, police officers, etc.
In the industrial revolution, it wasn't uncommon for major industrialists to build "model villages" [1] to house workers. The best examples include Bournville (Cadbury's chocolate), Saltaire (wool) and Port Sunlight (Lever Bros soap etc).
They were attractive places to live, compared with Victorian slums. You got a healthier, happier workforce living within walking distance of their jobs. Sir Titus Salt's Saltaire is now a World Heritage Site.
There's no reason why Google couldn't do the same, at least for a proportion of its workers. It looks as those Facebook will....
[1] http://en.wikipedia.org/wiki/Model_village