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

Side by Side Diff: chrome/browser/extensions/api/history/history_api.cc

Issue 166053003: Move ProfileKeyedAPI implementations to take BrowserContext in the constructor (part 2). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: | Created 6 years, 10 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/history/history_api.h" 5 #include "chrome/browser/extensions/api/history/history_api.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 scoped_ptr<base::ListValue> event_args) { 193 scoped_ptr<base::ListValue> event_args) {
194 if (profile && extensions::ExtensionSystem::Get(profile)->event_router()) { 194 if (profile && extensions::ExtensionSystem::Get(profile)->event_router()) {
195 scoped_ptr<extensions::Event> event(new extensions::Event( 195 scoped_ptr<extensions::Event> event(new extensions::Event(
196 event_name, event_args.Pass())); 196 event_name, event_args.Pass()));
197 event->restrict_to_browser_context = profile; 197 event->restrict_to_browser_context = profile;
198 extensions::ExtensionSystem::Get(profile)->event_router()-> 198 extensions::ExtensionSystem::Get(profile)->event_router()->
199 BroadcastEvent(event.Pass()); 199 BroadcastEvent(event.Pass());
200 } 200 }
201 } 201 }
202 202
203 HistoryAPI::HistoryAPI(Profile* profile) : profile_(profile) { 203 HistoryAPI::HistoryAPI(content::BrowserContext* context)
204 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( 204 : browser_context_(context) {
205 ExtensionSystem::Get(browser_context_)->event_router()->RegisterObserver(
205 this, api::history::OnVisited::kEventName); 206 this, api::history::OnVisited::kEventName);
206 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( 207 ExtensionSystem::Get(browser_context_)->event_router()->RegisterObserver(
207 this, api::history::OnVisitRemoved::kEventName); 208 this, api::history::OnVisitRemoved::kEventName);
208 } 209 }
209 210
210 HistoryAPI::~HistoryAPI() { 211 HistoryAPI::~HistoryAPI() {
211 } 212 }
212 213
213 void HistoryAPI::Shutdown() { 214 void HistoryAPI::Shutdown() {
214 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); 215 ExtensionSystem::Get(browser_context_)->event_router()->UnregisterObserver(
216 this);
215 } 217 }
216 218
217 static base::LazyInstance<ProfileKeyedAPIFactory<HistoryAPI> > 219 static base::LazyInstance<ProfileKeyedAPIFactory<HistoryAPI> >
218 g_factory = LAZY_INSTANCE_INITIALIZER; 220 g_factory = LAZY_INSTANCE_INITIALIZER;
219 221
220 // static 222 // static
221 ProfileKeyedAPIFactory<HistoryAPI>* HistoryAPI::GetFactoryInstance() { 223 ProfileKeyedAPIFactory<HistoryAPI>* HistoryAPI::GetFactoryInstance() {
222 return g_factory.Pointer(); 224 return g_factory.Pointer();
223 } 225 }
224 226
225 template<> 227 template<>
226 void ProfileKeyedAPIFactory<HistoryAPI>::DeclareFactoryDependencies() { 228 void ProfileKeyedAPIFactory<HistoryAPI>::DeclareFactoryDependencies() {
227 DependsOn(ActivityLogFactory::GetInstance()); 229 DependsOn(ActivityLogFactory::GetInstance());
228 } 230 }
229 231
230 void HistoryAPI::OnListenerAdded(const EventListenerInfo& details) { 232 void HistoryAPI::OnListenerAdded(const EventListenerInfo& details) {
231 history_event_router_.reset(new HistoryEventRouter(profile_)); 233 history_event_router_.reset(
232 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); 234 new HistoryEventRouter(Profile::FromBrowserContext(browser_context_)));
235 ExtensionSystem::Get(browser_context_)->event_router()->UnregisterObserver(
236 this);
233 } 237 }
234 238
235 void HistoryFunction::Run() { 239 void HistoryFunction::Run() {
236 if (!RunImpl()) { 240 if (!RunImpl()) {
237 SendResponse(false); 241 SendResponse(false);
238 } 242 }
239 } 243 }
240 244
241 bool HistoryFunction::ValidateUrl(const std::string& url_string, GURL* url) { 245 bool HistoryFunction::ValidateUrl(const std::string& url_string, GURL* url) {
242 GURL temp_url(url_string); 246 GURL temp_url(url_string);
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 } 482 }
479 483
480 return true; 484 return true;
481 } 485 }
482 486
483 void HistoryDeleteAllFunction::DeleteComplete() { 487 void HistoryDeleteAllFunction::DeleteComplete() {
484 SendAsyncResponse(); 488 SendAsyncResponse();
485 } 489 }
486 490
487 } // namespace extensions 491 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698