A San Pablo police officer has been charged with four felonies and two misdemeanors for allegedly buying heroin and cocaine in San Francisco last week while a 2-year-old girl was in his car, police and prosecutors said Sunday.