| OLD | NEW |
| 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/browser/profiles/profile.h" | |
| 15 #include "chrome/common/extensions/api/activity_log_private.h" | 14 #include "chrome/common/extensions/api/activity_log_private.h" |
| 16 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
| 16 #include "content/public/browser/browser_context.h" |
| 17 #include "extensions/browser/extension_system.h" | 17 #include "extensions/browser/extension_system.h" |
| 18 #include "extensions/browser/extension_system_provider.h" | 18 #include "extensions/browser/extension_system_provider.h" |
| 19 #include "extensions/browser/extensions_browser_client.h" | 19 #include "extensions/browser/extensions_browser_client.h" |
| 20 #include "extensions/common/features/feature.h" | 20 #include "extensions/common/features/feature.h" |
| 21 #include "extensions/common/features/feature_provider.h" | 21 #include "extensions/common/features/feature_provider.h" |
| 22 | 22 |
| 23 namespace extensions { | 23 namespace extensions { |
| 24 | 24 |
| 25 namespace activity_log_private = api::activity_log_private; | 25 namespace activity_log_private = api::activity_log_private; |
| 26 | 26 |
| 27 using api::activity_log_private::ActivityResultSet; | 27 using api::activity_log_private::ActivityResultSet; |
| 28 using api::activity_log_private::ExtensionActivity; | 28 using api::activity_log_private::ExtensionActivity; |
| 29 using api::activity_log_private::Filter; | 29 using api::activity_log_private::Filter; |
| 30 | 30 |
| 31 static base::LazyInstance<ProfileKeyedAPIFactory<ActivityLogAPI> > | 31 static base::LazyInstance<ProfileKeyedAPIFactory<ActivityLogAPI> > |
| 32 g_factory = LAZY_INSTANCE_INITIALIZER; | 32 g_factory = LAZY_INSTANCE_INITIALIZER; |
| 33 | 33 |
| 34 // static | 34 // static |
| 35 ProfileKeyedAPIFactory<ActivityLogAPI>* ActivityLogAPI::GetFactoryInstance() { | 35 ProfileKeyedAPIFactory<ActivityLogAPI>* ActivityLogAPI::GetFactoryInstance() { |
| 36 return g_factory.Pointer(); | 36 return g_factory.Pointer(); |
| 37 } | 37 } |
| 38 | 38 |
| 39 template<> | 39 template<> |
| 40 void ProfileKeyedAPIFactory<ActivityLogAPI>::DeclareFactoryDependencies() { | 40 void ProfileKeyedAPIFactory<ActivityLogAPI>::DeclareFactoryDependencies() { |
| 41 DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); | 41 DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); |
| 42 DependsOn(ActivityLogFactory::GetInstance()); | 42 DependsOn(ActivityLogFactory::GetInstance()); |
| 43 } | 43 } |
| 44 | 44 |
| 45 ActivityLogAPI::ActivityLogAPI(Profile* profile) | 45 ActivityLogAPI::ActivityLogAPI(content::BrowserContext* context) |
| 46 : profile_(profile), | 46 : browser_context_(context), initialized_(false) { |
| 47 initialized_(false) { | 47 if (!ExtensionSystem::Get(browser_context_) |
| 48 if (!ExtensionSystem::Get(profile_)->event_router()) { // Check for testing. | 48 ->event_router()) { // Check for testing. |
| 49 DVLOG(1) << "ExtensionSystem event_router does not exist."; | 49 DVLOG(1) << "ExtensionSystem event_router does not exist."; |
| 50 return; | 50 return; |
| 51 } | 51 } |
| 52 activity_log_ = extensions::ActivityLog::GetInstance(profile_); | 52 activity_log_ = extensions::ActivityLog::GetInstance(browser_context_); |
| 53 DCHECK(activity_log_); | 53 DCHECK(activity_log_); |
| 54 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( | 54 ExtensionSystem::Get(browser_context_)->event_router()->RegisterObserver( |
| 55 this, activity_log_private::OnExtensionActivity::kEventName); | 55 this, activity_log_private::OnExtensionActivity::kEventName); |
| 56 activity_log_->AddObserver(this); | 56 activity_log_->AddObserver(this); |
| 57 initialized_ = true; | 57 initialized_ = true; |
| 58 } | 58 } |
| 59 | 59 |
| 60 ActivityLogAPI::~ActivityLogAPI() { | 60 ActivityLogAPI::~ActivityLogAPI() { |
| 61 } | 61 } |
| 62 | 62 |
| 63 void ActivityLogAPI::Shutdown() { | 63 void ActivityLogAPI::Shutdown() { |
| 64 if (!initialized_) { // Check for testing. | 64 if (!initialized_) { // Check for testing. |
| 65 DVLOG(1) << "ExtensionSystem event_router does not exist."; | 65 DVLOG(1) << "ExtensionSystem event_router does not exist."; |
| 66 return; | 66 return; |
| 67 } | 67 } |
| 68 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); | 68 ExtensionSystem::Get(browser_context_)->event_router()->UnregisterObserver( |
| 69 this); |
| 69 activity_log_->RemoveObserver(this); | 70 activity_log_->RemoveObserver(this); |
| 70 } | 71 } |
| 71 | 72 |
| 72 // static | 73 // static |
| 73 bool ActivityLogAPI::IsExtensionWhitelisted(const std::string& extension_id) { | 74 bool ActivityLogAPI::IsExtensionWhitelisted(const std::string& extension_id) { |
| 74 return FeatureProvider::GetPermissionFeatures()-> | 75 return FeatureProvider::GetPermissionFeatures()-> |
| 75 GetFeature("activityLogPrivate")->IsIdInWhitelist(extension_id); | 76 GetFeature("activityLogPrivate")->IsIdInWhitelist(extension_id); |
| 76 } | 77 } |
| 77 | 78 |
| 78 void ActivityLogAPI::OnListenerAdded(const EventListenerInfo& details) { | 79 void ActivityLogAPI::OnListenerAdded(const EventListenerInfo& details) { |
| 79 // TODO(felt): Only observe activity_log_ events when we have a customer. | 80 // TODO(felt): Only observe activity_log_ events when we have a customer. |
| 80 } | 81 } |
| 81 | 82 |
| 82 void ActivityLogAPI::OnListenerRemoved(const EventListenerInfo& details) { | 83 void ActivityLogAPI::OnListenerRemoved(const EventListenerInfo& details) { |
| 83 // TODO(felt): Only observe activity_log_ events when we have a customer. | 84 // TODO(felt): Only observe activity_log_ events when we have a customer. |
| 84 } | 85 } |
| 85 | 86 |
| 86 void ActivityLogAPI::OnExtensionActivity(scoped_refptr<Action> activity) { | 87 void ActivityLogAPI::OnExtensionActivity(scoped_refptr<Action> activity) { |
| 87 scoped_ptr<base::ListValue> value(new base::ListValue()); | 88 scoped_ptr<base::ListValue> value(new base::ListValue()); |
| 88 scoped_ptr<ExtensionActivity> activity_arg = | 89 scoped_ptr<ExtensionActivity> activity_arg = |
| 89 activity->ConvertToExtensionActivity(); | 90 activity->ConvertToExtensionActivity(); |
| 90 value->Append(activity_arg->ToValue().release()); | 91 value->Append(activity_arg->ToValue().release()); |
| 91 scoped_ptr<Event> event( | 92 scoped_ptr<Event> event( |
| 92 new Event(activity_log_private::OnExtensionActivity::kEventName, | 93 new Event(activity_log_private::OnExtensionActivity::kEventName, |
| 93 value.Pass())); | 94 value.Pass())); |
| 94 event->restrict_to_browser_context = profile_; | 95 event->restrict_to_browser_context = browser_context_; |
| 95 ExtensionSystem::Get(profile_)->event_router()->BroadcastEvent(event.Pass()); | 96 ExtensionSystem::Get(browser_context_)->event_router()->BroadcastEvent( |
| 97 event.Pass()); |
| 96 } | 98 } |
| 97 | 99 |
| 98 bool ActivityLogPrivateGetExtensionActivitiesFunction::RunImpl() { | 100 bool ActivityLogPrivateGetExtensionActivitiesFunction::RunImpl() { |
| 99 scoped_ptr<activity_log_private::GetExtensionActivities::Params> params( | 101 scoped_ptr<activity_log_private::GetExtensionActivities::Params> params( |
| 100 activity_log_private::GetExtensionActivities::Params::Create(*args_)); | 102 activity_log_private::GetExtensionActivities::Params::Create(*args_)); |
| 101 EXTENSION_FUNCTION_VALIDATE(params.get()); | 103 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 102 | 104 |
| 103 // Get the arguments in the right format. | 105 // Get the arguments in the right format. |
| 104 scoped_ptr<Filter> filter; | 106 scoped_ptr<Filter> filter; |
| 105 filter.reset(¶ms.release()->filter); | 107 filter.reset(¶ms.release()->filter); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 gurls.push_back(GURL(*it)); | 218 gurls.push_back(GURL(*it)); |
| 217 } | 219 } |
| 218 | 220 |
| 219 ActivityLog* activity_log = ActivityLog::GetInstance(GetProfile()); | 221 ActivityLog* activity_log = ActivityLog::GetInstance(GetProfile()); |
| 220 DCHECK(activity_log); | 222 DCHECK(activity_log); |
| 221 activity_log->RemoveURLs(gurls); | 223 activity_log->RemoveURLs(gurls); |
| 222 return true; | 224 return true; |
| 223 } | 225 } |
| 224 | 226 |
| 225 } // namespace extensions | 227 } // namespace extensions |
| OLD | NEW |