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

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

Issue 12340111: Introduce //components/user_prefs, use to eliminate c/b/prefs dependency in Autofill. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Pure merge of LKGR Created 7 years, 9 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 | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #include "components/user_prefs/user_prefs.h"
6
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"
11
12 namespace components {
13
14 namespace {
15
16 void* UserDataKey() {
17 // We just need a unique constant. Use the address of this static member.
18 return reinterpret_cast<void*>(&UserPrefs::Get);
19 }
20
21 } // namespace
22
23 UserPrefs::UserPrefs(PrefService* prefs) : prefs_(prefs) {
24 }
25
26 UserPrefs::~UserPrefs() {
27 }
28
29 // static
30 PrefService* UserPrefs::Get(content::BrowserContext* context) {
31 DCHECK(context);
32 return static_cast<UserPrefs*>(
33 context->GetUserData(UserDataKey()))->prefs_;
34 }
35
36 // static
37 void UserPrefs::Set(content::BrowserContext* context, PrefService* prefs) {
38 DCHECK(context);
39 DCHECK(prefs);
40 DCHECK(!context->GetUserData(UserDataKey()));
41 context->SetUserData(UserDataKey(), new UserPrefs(prefs));
42 }
43
44 } // namespace components
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698