It is a history of racism and Jim Crow. The law was passed in the 1920s to deny permits to Latinos, Chinese and non-naturalized residents. Our may-issue system is probably one of the last Jim Crow laws on the books in the US that the courts have not dismantled (yet).
How could this be possible? Here is an article which appeared in the San Francisco Chronicle on July 15th, 1923, giving some of the history of the lobbying for our current may-issue CCW system. This article mentions that California's CCW law was passed specifically to prevent Chinese, Latinos and legal immigrants (non-naturalized permenant residents) from being armed. (Emphasis added.)
Note that this was from a time in California in which Mexicans were segregated into separate public schools. The article seems to take a supportive tone of the idea that government-issued permits should be denied to certain racial minorities. This was a mainstream attitude at the time.
And in 1924, our may-issue CCW law was passed. Looking at it in the context of those other Jim Crow laws, it's quite easy to understand what "sheriff's discretion" meant, and this article in the San Francisco Chronicle makes it explicit and removes all doubt as to the legislative intent.
Stringent regulations against carrying concealed firearms or explosives, and prohibition against possession of other deadly weapons become effective on August 7, under the Hawes bill signed by Governor Richardson.
The new measure will install a uniform licensing system for carrying concealed weapons. Licenses now in existence will become inoperative December 31, 1924.
Aimed at disarming the lawless, the bill provides exemptions and exceptions to preserve the rights of those using firearms for competition or hunting or for protection in outing trips. It was largely on the recommendation of R. T. McKissick, president of the Sacramento Rifle and Revolver Club, that Governor Richardson approved the measure.
McKissick classes it as a measure that introduces "an element of sanity into firearms legislation, so as to provide adequate punishments upon an increasing scale for the habitual gunman and, at the same time, permit law-abiding citizens to continue to own firearms for home defense and other legitimate uses."
The bill, according to McKissick follows almost literally one offered in the United States Senate by Senator Capper and advocated by associations interested in the manufacture, sale and legitimate use of pistols and revolvers, as a model for a uniform bill to be introduced in each State. "It is frankly," he says, "an effort upon the part of those who know something about firearms to forestall the flood of fanatical legislation intended to deprive all citizens of the United States the right to own and use, for legitimate purposes, firearms capable of being concealed upon the person."
The new measures change existing law by making the carrying of barred weapons such as blackjacks, a felony instead of a misdemeanor. The provision against carrying explosive also is new.
Possible unconstitutionality of the provision against possession of weapons by non-naturalized residents was admitted in McKissick's letter to the Governor urging signing of the bill, but he pointed out that if this clause should be held invalid the rest of the act will not be affected and that if it can be sustained that it will have a "salutary effect in checking tong wars among the Chinese and vendettas among our people who are of Latin descent."
The provision for additional sentences where weapons are used in committing a felony is one with a sliding scale. The first time the added penalty is from five to ten years; the second from ten to fifteen; the third from 15 to 25 years, and only on the fourth offense it is possible to add more than 25 years to the sentence imposed for the crime itself.

Thanks Jim!
The court case which finally desegregated California's schools was Mendez vs. Westminster in 1947. See An early blow for equality for more information. But Jim Crow did not end in California with that case in 1947; it continues today in 2009, with our CCW law. California's CCW law is one of the last Jim Crow laws still in force in the United States.

The Ku Klux Klan in a parade in Anaheim, California, in 1924, the same year
California's CCW law passed, with the purpose of disarming Latino and Chinese
legal residents. California's CCW system is still regulated under this
law.