You should read about transfer pricing. In many cases it is entirely possible to assign where a large firm's income is made for tax purposes by internally transferring intellectual property.
On the point of why would tech companies want to do this instead of helping the community, I argue it may actually help California. Instead of doing the responsible thing and moving the firm to somewhere with a lower state corporate tax rate, the firm can simply avoid taxes. This keeps employees in the area contributing to state income and property taxes. In a world or multinationals, I am not certain corporate income taxes make sense.
I have first hand experience with transfer pricing. My old startup had offices in Australia, India and the USA, income from all over the world, etc.
These tax systems also apply to the smallest of startups operating online. Its just that Google can afford the best advice and are the biggest target.
My concern is that further changes to tax laws that are aimed at Google and Apple could end up affecting smaller companies and startups as collateral damage.
Google and Apple will wriggle their way out of any changes to transfer pricing laws, as they usually always do, while small startups and businesses might not.
On the point of why would tech companies want to do this instead of helping the community, I argue it may actually help California. Instead of doing the responsible thing and moving the firm to somewhere with a lower state corporate tax rate, the firm can simply avoid taxes. This keeps employees in the area contributing to state income and property taxes. In a world or multinationals, I am not certain corporate income taxes make sense.