Part of the San Francisco Department of Public Health, the Department of Environmental Health inspects every place in San Francisco where prepared food is (legally) sold. This includes, according to their website, "restaurants, bars, markets, bakeries, pushcarts, stadium food facilities and any other facility that serves food to the public." Scores must be posted in public view. If you'd like to look up the current EH score for a particular restaurant, you may do so here.

History

According to California law, health reports must be available upon request, but San Francisco, specifically Supervisor Chris Daly decided to take it one step further. The rating system was implemented in 2005, but I can't seem to find the actual article talking about when it became a law. Well, here's a bunch of other stuff from the Chronicle:

RESTAURANT SAFETY, Making the grade, S.F. Supervisor Daly pushes rating system for restaurants

Supes dump eatery grade idea, Alternate plan for cleanliness symbol OKd

Restaurants honored for inspection scores

Kitchen (not so) confidential, San Francisco's restaurant scores are more public now -- but are they improving food safety?