Thread safe initialization of OSCrypt cache

Clients of OSCrypt run in multiple threads. This creates a race
condition for the lazy initialization of OSCrypt, which currently
isn't thread safe.

Additionally, when a synchronous call to libsecret blocks waiting for
user permission, parallel calls to it do not block on the same prompt.
Rather, they fail. This means that, while the first caller will
correctly identify that encryption should be used, subsequent callers
will behave as if full encryption is not available, until the first
caller gets permission and properly initialises OSCrypt.

Fixing thread safety should fix reported cases of data loss.

BUG=631171

Review-Url: https://codereview.chromium.org/2359803002
Cr-Commit-Position: refs/heads/master@{#421097}
3 files changed