Ms. Schaaf worked as a lawyer for two years at a prominent law firm in Oakland before turning to politics. She served several years as an aide to other politicians, including Gov. Jerry Brown when he was mayor of Oakland, and was elected to the City Council in 2010. Four years later she was elected mayor.

As a former lawyer, Ms. Schaaf understands the potential pitfalls in warning unauthorized immigrants of an impending raid. But she approaches the issue in the style of an activist.

Asked what her message was for immigrants who are in Oakland illegally, Ms. Schaaf said: “Your city wants you to be safe, wants to keep your family together and is proud to have you as part of our community.”

Housing affordability has been a concern during her tenure.

The past few years have been a time of wrenching change for Oakland. The wealth generated by the tech industry across the San Francisco Bay is pushing up housing prices and making many neighborhoods unaffordable to any family not earning six figures. The economic pressures have caused the number of homeless people to rise to around 2,800, an increase of more than 25 percent since Ms. Schaaf took office in January 2015.

In the city that gave rise to the Black Panthers, the African-American community has been shrinking drastically, from 47 percent of the population in the 1980 census to less than one quarter today. As black residents have moved out, Latinos and Asian-Americans have moved in.

Ms. Schaaf has had to balance the courting of technology companies with the changes to the traditional working-class character of the city. “Hey, Google: You wouldn’t need all those buses if you’d open an office over here,” she was quoted as saying on the day of her swearing in.

In December 2016, when 36 young people died in a fire at a warehouse that had been converted into an illegal artist colony and party venue, the subtext was that the shortage of affordable housing had pushed artists into dangerous living conditions. In the aftermath of the Ghost Ship fire, as it is known, Ms. Schaaf juggled the competing demands for greater safety with concerns from artists that they might be forced to leave the city if fire codes were strictly enforced. She was criticized for not disciplining or removing the city’s fire chief, who in the years before the Ghost Ship fire had been accused of keeping the department understaffed and disorganized.