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

Side by Side Diff: chrome/browser/extensions/api/activity_log_private/activity_log_private_api.cc

Issue 238633009: cleanup: Use EventRouter instead of ExtensionSystem::Get->event_router() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix compile error for chromeos build. Created 6 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
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/activity_log_private/activity_log_privat e_api.h" 5 #include "chrome/browser/extensions/api/activity_log_private/activity_log_privat e_api.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/extensions/event_router_forwarder.h" 12 #include "chrome/browser/extensions/event_router_forwarder.h"
13 #include "chrome/browser/extensions/extension_service.h" 13 #include "chrome/browser/extensions/extension_service.h"
14 #include "chrome/common/extensions/api/activity_log_private.h" 14 #include "chrome/common/extensions/api/activity_log_private.h"
15 #include "chrome/common/pref_names.h" 15 #include "chrome/common/pref_names.h"
16 #include "content/public/browser/browser_context.h" 16 #include "content/public/browser/browser_context.h"
17 #include "extensions/browser/extension_system.h"
18 #include "extensions/browser/extension_system_provider.h" 17 #include "extensions/browser/extension_system_provider.h"
19 #include "extensions/browser/extensions_browser_client.h" 18 #include "extensions/browser/extensions_browser_client.h"
20 #include "extensions/common/features/feature.h" 19 #include "extensions/common/features/feature.h"
21 #include "extensions/common/features/feature_provider.h" 20 #include "extensions/common/features/feature_provider.h"
22 21
23 namespace extensions { 22 namespace extensions {
24 23
25 namespace activity_log_private = api::activity_log_private; 24 namespace activity_log_private = api::activity_log_private;
26 25
27 using api::activity_log_private::ActivityResultSet; 26 using api::activity_log_private::ActivityResultSet;
(...skipping 11 matching lines...) Expand all
39 38
40 template <> 39 template <>
41 void 40 void
42 BrowserContextKeyedAPIFactory<ActivityLogAPI>::DeclareFactoryDependencies() { 41 BrowserContextKeyedAPIFactory<ActivityLogAPI>::DeclareFactoryDependencies() {
43 DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); 42 DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory());
44 DependsOn(ActivityLog::GetFactoryInstance()); 43 DependsOn(ActivityLog::GetFactoryInstance());
45 } 44 }
46 45
47 ActivityLogAPI::ActivityLogAPI(content::BrowserContext* context) 46 ActivityLogAPI::ActivityLogAPI(content::BrowserContext* context)
48 : browser_context_(context), initialized_(false) { 47 : browser_context_(context), initialized_(false) {
49 if (!ExtensionSystem::Get(browser_context_) 48 if (!EventRouter::Get(browser_context_)) { // Check for testing.
50 ->event_router()) { // Check for testing.
51 DVLOG(1) << "ExtensionSystem event_router does not exist."; 49 DVLOG(1) << "ExtensionSystem event_router does not exist.";
52 return; 50 return;
53 } 51 }
54 activity_log_ = extensions::ActivityLog::GetInstance(browser_context_); 52 activity_log_ = extensions::ActivityLog::GetInstance(browser_context_);
55 DCHECK(activity_log_); 53 DCHECK(activity_log_);
56 ExtensionSystem::Get(browser_context_)->event_router()->RegisterObserver( 54 EventRouter::Get(browser_context_)->RegisterObserver(
57 this, activity_log_private::OnExtensionActivity::kEventName); 55 this, activity_log_private::OnExtensionActivity::kEventName);
58 activity_log_->AddObserver(this); 56 activity_log_->AddObserver(this);
59 initialized_ = true; 57 initialized_ = true;
60 } 58 }
61 59
62 ActivityLogAPI::~ActivityLogAPI() { 60 ActivityLogAPI::~ActivityLogAPI() {
63 } 61 }
64 62
65 void ActivityLogAPI::Shutdown() { 63 void ActivityLogAPI::Shutdown() {
66 if (!initialized_) { // Check for testing. 64 if (!initialized_) { // Check for testing.
67 DVLOG(1) << "ExtensionSystem event_router does not exist."; 65 DVLOG(1) << "ExtensionSystem event_router does not exist.";
68 return; 66 return;
69 } 67 }
70 ExtensionSystem::Get(browser_context_)->event_router()->UnregisterObserver( 68 EventRouter::Get(browser_context_)->UnregisterObserver(this);
71 this);
72 activity_log_->RemoveObserver(this); 69 activity_log_->RemoveObserver(this);
73 } 70 }
74 71
75 // static 72 // static
76 bool ActivityLogAPI::IsExtensionWhitelisted(const std::string& extension_id) { 73 bool ActivityLogAPI::IsExtensionWhitelisted(const std::string& extension_id) {
77 return FeatureProvider::GetPermissionFeatures()-> 74 return FeatureProvider::GetPermissionFeatures()->
78 GetFeature("activityLogPrivate")->IsIdInWhitelist(extension_id); 75 GetFeature("activityLogPrivate")->IsIdInWhitelist(extension_id);
79 } 76 }
80 77
81 void ActivityLogAPI::OnListenerAdded(const EventListenerInfo& details) { 78 void ActivityLogAPI::OnListenerAdded(const EventListenerInfo& details) {
82 // TODO(felt): Only observe activity_log_ events when we have a customer. 79 // TODO(felt): Only observe activity_log_ events when we have a customer.
83 } 80 }
84 81
85 void ActivityLogAPI::OnListenerRemoved(const EventListenerInfo& details) { 82 void ActivityLogAPI::OnListenerRemoved(const EventListenerInfo& details) {
86 // TODO(felt): Only observe activity_log_ events when we have a customer. 83 // TODO(felt): Only observe activity_log_ events when we have a customer.
87 } 84 }
88 85
89 void ActivityLogAPI::OnExtensionActivity(scoped_refptr<Action> activity) { 86 void ActivityLogAPI::OnExtensionActivity(scoped_refptr<Action> activity) {
90 scoped_ptr<base::ListValue> value(new base::ListValue()); 87 scoped_ptr<base::ListValue> value(new base::ListValue());
91 scoped_ptr<ExtensionActivity> activity_arg = 88 scoped_ptr<ExtensionActivity> activity_arg =
92 activity->ConvertToExtensionActivity(); 89 activity->ConvertToExtensionActivity();
93 value->Append(activity_arg->ToValue().release()); 90 value->Append(activity_arg->ToValue().release());
94 scoped_ptr<Event> event( 91 scoped_ptr<Event> event(
95 new Event(activity_log_private::OnExtensionActivity::kEventName, 92 new Event(activity_log_private::OnExtensionActivity::kEventName,
96 value.Pass())); 93 value.Pass()));
97 event->restrict_to_browser_context = browser_context_; 94 event->restrict_to_browser_context = browser_context_;
98 ExtensionSystem::Get(browser_context_)->event_router()->BroadcastEvent( 95 EventRouter::Get(browser_context_)->BroadcastEvent(event.Pass());
99 event.Pass());
100 } 96 }
101 97
102 bool ActivityLogPrivateGetExtensionActivitiesFunction::RunImpl() { 98 bool ActivityLogPrivateGetExtensionActivitiesFunction::RunImpl() {
103 scoped_ptr<activity_log_private::GetExtensionActivities::Params> params( 99 scoped_ptr<activity_log_private::GetExtensionActivities::Params> params(
104 activity_log_private::GetExtensionActivities::Params::Create(*args_)); 100 activity_log_private::GetExtensionActivities::Params::Create(*args_));
105 EXTENSION_FUNCTION_VALIDATE(params.get()); 101 EXTENSION_FUNCTION_VALIDATE(params.get());
106 102
107 // Get the arguments in the right format. 103 // Get the arguments in the right format.
108 scoped_ptr<Filter> filter; 104 scoped_ptr<Filter> filter;
109 filter.reset(&params.release()->filter); 105 filter.reset(&params.release()->filter);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 gurls.push_back(GURL(*it)); 216 gurls.push_back(GURL(*it));
221 } 217 }
222 218
223 ActivityLog* activity_log = ActivityLog::GetInstance(GetProfile()); 219 ActivityLog* activity_log = ActivityLog::GetInstance(GetProfile());
224 DCHECK(activity_log); 220 DCHECK(activity_log);
225 activity_log->RemoveURLs(gurls); 221 activity_log->RemoveURLs(gurls);
226 return true; 222 return true;
227 } 223 }
228 224
229 } // namespace extensions 225 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/wallpaper_manager.cc ('k') | chrome/browser/extensions/api/audio/audio_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698