Notify hotwording extension of microphone state change.
[chromium-blink-merge.git] / components / user_prefs / user_prefs.cc
blob8ecdfe4bc93abb5d827d0cc07d187336f10fd587
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/user_prefs/user_prefs.h"
7 #include "base/logging.h"
8 #include "base/memory/singleton.h"
9 #include "base/prefs/pref_service.h"
10 #include "content/public/browser/browser_context.h"
12 namespace user_prefs {
14 namespace {
16 void* UserDataKey() {
17 // We just need a unique constant. Use the address of a static that
18 // COMDAT folding won't touch in an optimizing linker.
19 static int data_key = 0;
20 return reinterpret_cast<void*>(&data_key);
23 } // namespace
25 // static
26 PrefService* UserPrefs::Get(content::BrowserContext* context) {
27 DCHECK(context);
28 DCHECK(context->GetUserData(UserDataKey()));
29 return static_cast<UserPrefs*>(
30 context->GetUserData(UserDataKey()))->prefs_;
33 // static
34 void UserPrefs::Set(content::BrowserContext* context, PrefService* prefs) {
35 DCHECK(context);
36 DCHECK(prefs);
37 DCHECK(!context->GetUserData(UserDataKey()));
38 context->SetUserData(UserDataKey(), new UserPrefs(prefs));
41 UserPrefs::UserPrefs(PrefService* prefs) : prefs_(prefs) {
44 UserPrefs::~UserPrefs() {
47 } // namespace user_prefs