I've only met a bear once on a hike, so don't have much experience, but read a couple of books on protecting yourself in bear attacks, and what I took away from it is this:
If a bear is hungry and has either been fed food or got food from a human before, if it really wants food and thinks you may have it, it will attack you.
If you are between a bear and it's hidden food supply, it will attack you in order to protect it's stash.
If you get between momma and her cubs, she will attack you if she thinks you are a threat.
In the Pacific Northwest, anyway, you are more likely to be attacked by a black bear than a grizzly.
You need to practice spraying the can (some companies sell 'practice' cans with water). Wind may blow the spray off course.
You need to be quite close before spraying bear. If bear is charging, you have very little time to hit it in the face before it is on you.
Bear spray may or may not deter the bear.
A firearm is only good if you have time to use it. There are stories, one told here somewhere with a link to a video, of people getting attacked but not having enough time to get their firearm out. Or that they were able to get rounds off but it wasn't enough to take down the bear which still attacked.
After a lot of "Let's try to be nice to the bears" discussion, the conclusion of both books (implied, but not stated) was that your odds are better off with something a little more pointy than a can of bear spray.
Some places offer bear defense courses (firearms related). I've never been, but putting it out there in case it is of interest.