Back then those barons didn't pay as many taxes, and the towns relied on their charity. The Federal government, for example, took 3% in taxes at the beginning of the 20th century.
And I'm pretty sure the robber barons are criticized more than the current Googles of the world.
What you are saying when you say these companies should be doing social projects and planning, is that the cities are failing the citizens to do those projects and planning.
I agree that they can do it from a perception point of view, but I've found that Social Justice is usually 80% distraction and opportunism, and real solutions should be properly architected by the right entities, and usually have the character of benefiting everyone, not just the oppressed group. Just as a couple examples: body cameras and inverting the clasroom, are not particularly "Black lives matter" solutions, more like improving "all lives" and yet they'd help more than Al Sharpton's opportunistic appearances and all that type of activism.
All these movements that make an enemy of those who they should instead try to enlist in the solution, just wind up doing more harm than good. Take for example the BDS movement. And before that, the other "social justice for Palestinians" movements. It's been decades and Palestinians are still stateless. Is BDS gonna topple Israel? No, it's just an outrage-fueled meme to protest Zionism. It doesn't actually help. The way things move forward is not by activists yelling against an enemy, but rather when people constructively get the stakeholders all together and do something that benefits everyone.