OLD | NEW |
(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 |
OLD | NEW |