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

Side by Side Diff: chrome/browser/extensions/api/preference/chrome_direct_setting_api.cc

Issue 178193030: Rename ProfileKeyedAPI to BrowserContextKeyedAPI and GetProfile to Get. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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
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 "chrome/browser/extensions/api/preference/chrome_direct_setting_api.h" 5 #include "chrome/browser/extensions/api/preference/chrome_direct_setting_api.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/containers/hash_tables.h" 8 #include "base/containers/hash_tables.h"
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/prefs/pref_change_registrar.h" 10 #include "base/prefs/pref_change_registrar.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 65
66 private: 66 private:
67 base::hash_set<std::string> whitelist_; 67 base::hash_set<std::string> whitelist_;
68 68
69 DISALLOW_COPY_AND_ASSIGN(PreferenceWhitelist); 69 DISALLOW_COPY_AND_ASSIGN(PreferenceWhitelist);
70 }; 70 };
71 71
72 base::LazyInstance<PreferenceWhitelist> preference_whitelist = 72 base::LazyInstance<PreferenceWhitelist> preference_whitelist =
73 LAZY_INSTANCE_INITIALIZER; 73 LAZY_INSTANCE_INITIALIZER;
74 74
75 static base::LazyInstance<ProfileKeyedAPIFactory<ChromeDirectSettingAPI> > 75 static base::LazyInstance<
76 g_factory = LAZY_INSTANCE_INITIALIZER; 76 BrowserContextKeyedAPIFactory<ChromeDirectSettingAPI> > g_factory =
77 LAZY_INSTANCE_INITIALIZER;
77 78
78 ChromeDirectSettingAPI::ChromeDirectSettingAPI(content::BrowserContext* context) 79 ChromeDirectSettingAPI::ChromeDirectSettingAPI(content::BrowserContext* context)
79 : profile_(Profile::FromBrowserContext(context)) { 80 : profile_(Profile::FromBrowserContext(context)) {
80 preference_whitelist.Get().RegisterEventListeners(profile_, this); 81 preference_whitelist.Get().RegisterEventListeners(profile_, this);
81 } 82 }
82 83
83 ChromeDirectSettingAPI::~ChromeDirectSettingAPI() {} 84 ChromeDirectSettingAPI::~ChromeDirectSettingAPI() {}
84 85
85 // BrowserContextKeyedService implementation. 86 // BrowserContextKeyedService implementation.
86 void ChromeDirectSettingAPI::Shutdown() {} 87 void ChromeDirectSettingAPI::Shutdown() {}
87 88
88 // ProfileKeyedAPI implementation. 89 // BrowserContextKeyedAPI implementation.
89 ProfileKeyedAPIFactory<ChromeDirectSettingAPI>* 90 BrowserContextKeyedAPIFactory<ChromeDirectSettingAPI>*
90 ChromeDirectSettingAPI::GetFactoryInstance() { 91 ChromeDirectSettingAPI::GetFactoryInstance() {
91 return g_factory.Pointer(); 92 return g_factory.Pointer();
92 } 93 }
93 94
94 // EventRouter::Observer implementation. 95 // EventRouter::Observer implementation.
95 void ChromeDirectSettingAPI::OnListenerAdded(const EventListenerInfo& details) { 96 void ChromeDirectSettingAPI::OnListenerAdded(const EventListenerInfo& details) {
96 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); 97 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this);
97 registrar_.Init(profile_->GetPrefs()); 98 registrar_.Init(profile_->GetPrefs());
98 preference_whitelist.Get().RegisterPropertyListeners( 99 preference_whitelist.Get().RegisterPropertyListeners(
99 profile_, 100 profile_,
100 &registrar_, 101 &registrar_,
101 base::Bind(&ChromeDirectSettingAPI::OnPrefChanged, 102 base::Bind(&ChromeDirectSettingAPI::OnPrefChanged,
102 base::Unretained(this), 103 base::Unretained(this),
103 registrar_.prefs())); 104 registrar_.prefs()));
104 } 105 }
105 106
106 bool ChromeDirectSettingAPI::IsPreferenceOnWhitelist( 107 bool ChromeDirectSettingAPI::IsPreferenceOnWhitelist(
107 const std::string& pref_key) { 108 const std::string& pref_key) {
108 return preference_whitelist.Get().IsPreferenceOnWhitelist(pref_key); 109 return preference_whitelist.Get().IsPreferenceOnWhitelist(pref_key);
109 } 110 }
110 111
111 ChromeDirectSettingAPI* ChromeDirectSettingAPI::Get( 112 ChromeDirectSettingAPI* ChromeDirectSettingAPI::Get(
112 content::BrowserContext* context) { 113 content::BrowserContext* context) {
113 return ProfileKeyedAPIFactory<ChromeDirectSettingAPI>::GetForProfile(context); 114 return BrowserContextKeyedAPIFactory<ChromeDirectSettingAPI>::Get(context);
114 } 115 }
115 116
116 // ProfileKeyedAPI implementation. 117 // BrowserContextKeyedAPI implementation.
117 const char* ChromeDirectSettingAPI::service_name() { 118 const char* ChromeDirectSettingAPI::service_name() {
118 return "ChromeDirectSettingAPI"; 119 return "ChromeDirectSettingAPI";
119 } 120 }
120 121
121 void ChromeDirectSettingAPI::OnPrefChanged( 122 void ChromeDirectSettingAPI::OnPrefChanged(
122 PrefService* pref_service, const std::string& pref_key) { 123 PrefService* pref_service, const std::string& pref_key) {
123 std::string event_name = base::StringPrintf(kOnPrefChangeFormat, 124 std::string event_name = base::StringPrintf(kOnPrefChangeFormat,
124 pref_key.c_str()); 125 pref_key.c_str());
125 EventRouter* router = ExtensionSystem::Get(profile_)->event_router(); 126 EventRouter* router = ExtensionSystem::Get(profile_)->event_router();
126 if (router && router->HasEventListener(event_name)) { 127 if (router && router->HasEventListener(event_name)) {
(...skipping 18 matching lines...) Expand all
145 scoped_ptr<Event> event(new Event(event_name, args_copy.Pass())); 146 scoped_ptr<Event> event(new Event(event_name, args_copy.Pass()));
146 router->DispatchEventToExtension(extension_id, event.Pass()); 147 router->DispatchEventToExtension(extension_id, event.Pass());
147 } 148 }
148 } 149 }
149 } 150 }
150 } 151 }
151 } 152 }
152 153
153 } // namespace chromedirectsetting 154 } // namespace chromedirectsetting
154 } // namespace extensions 155 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698