Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1048)

Side by Side Diff: components/user_prefs/user_prefs.cc

Issue 1062083003: Implement BrowserStateKeyedServiceFactory::GetAssociatedPrefRegistry() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add missing include in card_unmask_prompt_controller_impl_unittest.cc Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/user_prefs/user_prefs.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/user_prefs/user_prefs.h" 5 #include "components/user_prefs/user_prefs.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/singleton.h" 8 #include "base/memory/singleton.h"
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "content/public/browser/browser_context.h"
11 10
12 namespace user_prefs { 11 namespace user_prefs {
13 12
14 namespace { 13 namespace {
15 14
16 void* UserDataKey() { 15 void* UserDataKey() {
17 // We just need a unique constant. Use the address of a static that 16 // We just need a unique constant. Use the address of a static that
18 // COMDAT folding won't touch in an optimizing linker. 17 // COMDAT folding won't touch in an optimizing linker.
19 static int data_key = 0; 18 static int data_key = 0;
20 return reinterpret_cast<void*>(&data_key); 19 return reinterpret_cast<void*>(&data_key);
21 } 20 }
22 21
23 } // namespace 22 } // namespace
24 23
25 // static 24 // static
26 PrefService* UserPrefs::Get(content::BrowserContext* context) { 25 PrefService* UserPrefs::Get(base::SupportsUserData* context) {
27 DCHECK(context); 26 DCHECK(context);
28 DCHECK(context->GetUserData(UserDataKey())); 27 DCHECK(context->GetUserData(UserDataKey()));
29 return static_cast<UserPrefs*>( 28 return static_cast<UserPrefs*>(
30 context->GetUserData(UserDataKey()))->prefs_; 29 context->GetUserData(UserDataKey()))->prefs_;
31 } 30 }
32 31
33 // static 32 // static
34 void UserPrefs::Set(content::BrowserContext* context, PrefService* prefs) { 33 void UserPrefs::Set(base::SupportsUserData* context, PrefService* prefs) {
35 DCHECK(context); 34 DCHECK(context);
36 DCHECK(prefs); 35 DCHECK(prefs);
37 DCHECK(!context->GetUserData(UserDataKey())); 36 DCHECK(!context->GetUserData(UserDataKey()));
38 context->SetUserData(UserDataKey(), new UserPrefs(prefs)); 37 context->SetUserData(UserDataKey(), new UserPrefs(prefs));
39 } 38 }
40 39
41 UserPrefs::UserPrefs(PrefService* prefs) : prefs_(prefs) { 40 UserPrefs::UserPrefs(PrefService* prefs) : prefs_(prefs) {
42 } 41 }
43 42
44 UserPrefs::~UserPrefs() { 43 UserPrefs::~UserPrefs() {
45 } 44 }
46 45
47 } // namespace user_prefs 46 } // namespace user_prefs
OLDNEW
« no previous file with comments | « components/user_prefs/user_prefs.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698