| 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 : context_(context), initialized_(false) { |
| 47 initialized_(false) { | 47 if (!ExtensionSystem::Get(context_)->event_router()) { // Check for testing. |
| 48 if (!ExtensionSystem::Get(profile_)->event_router()) { // Check for testing. | |
| 49 DVLOG(1) << "ExtensionSystem event_router does not exist."; | 48 DVLOG(1) << "ExtensionSystem event_router does not exist."; |
| 50 return; | 49 return; |
| 51 } | 50 } |
| 52 activity_log_ = extensions::ActivityLog::GetInstance(profile_); | 51 activity_log_ = extensions::ActivityLog::GetInstance(context_); |
| 53 DCHECK(activity_log_); | 52 DCHECK(activity_log_); |
| 54 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( | 53 ExtensionSystem::Get(context_)->event_router()->RegisterObserver( |
| 55 this, activity_log_private::OnExtensionActivity::kEventName); | 54 this, activity_log_private::OnExtensionActivity::kEventName); |
| 56 activity_log_->AddObserver(this); | 55 activity_log_->AddObserver(this); |
| 57 initialized_ = true; | 56 initialized_ = true; |
| 58 } | 57 } |
| 59 | 58 |
| 60 ActivityLogAPI::~ActivityLogAPI() { | 59 ActivityLogAPI::~ActivityLogAPI() { |
| 61 } | 60 } |
| 62 | 61 |
| 63 void ActivityLogAPI::Shutdown() { | 62 void ActivityLogAPI::Shutdown() { |
| 64 if (!initialized_) { // Check for testing. | 63 if (!initialized_) { // Check for testing. |
| 65 DVLOG(1) << "ExtensionSystem event_router does not exist."; | 64 DVLOG(1) << "ExtensionSystem event_router does not exist."; |
| 66 return; | 65 return; |
| 67 } | 66 } |
| 68 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); | 67 ExtensionSystem::Get(context_)->event_router()->UnregisterObserver(this); |
| 69 activity_log_->RemoveObserver(this); | 68 activity_log_->RemoveObserver(this); |
| 70 } | 69 } |
| 71 | 70 |
| 72 // static | 71 // static |
| 73 bool ActivityLogAPI::IsExtensionWhitelisted(const std::string& extension_id) { | 72 bool ActivityLogAPI::IsExtensionWhitelisted(const std::string& extension_id) { |
| 74 return FeatureProvider::GetPermissionFeatures()-> | 73 return FeatureProvider::GetPermissionFeatures()-> |
| 75 GetFeature("activityLogPrivate")->IsIdInWhitelist(extension_id); | 74 GetFeature("activityLogPrivate")->IsIdInWhitelist(extension_id); |
| 76 } | 75 } |
| 77 | 76 |
| 78 void ActivityLogAPI::OnListenerAdded(const EventListenerInfo& details) { | 77 void ActivityLogAPI::OnListenerAdded(const EventListenerInfo& details) { |
| 79 // TODO(felt): Only observe activity_log_ events when we have a customer. | 78 // TODO(felt): Only observe activity_log_ events when we have a customer. |
| 80 } | 79 } |
| 81 | 80 |
| 82 void ActivityLogAPI::OnListenerRemoved(const EventListenerInfo& details) { | 81 void ActivityLogAPI::OnListenerRemoved(const EventListenerInfo& details) { |
| 83 // TODO(felt): Only observe activity_log_ events when we have a customer. | 82 // TODO(felt): Only observe activity_log_ events when we have a customer. |
| 84 } | 83 } |
| 85 | 84 |
| 86 void ActivityLogAPI::OnExtensionActivity(scoped_refptr<Action> activity) { | 85 void ActivityLogAPI::OnExtensionActivity(scoped_refptr<Action> activity) { |
| 87 scoped_ptr<base::ListValue> value(new base::ListValue()); | 86 scoped_ptr<base::ListValue> value(new base::ListValue()); |
| 88 scoped_ptr<ExtensionActivity> activity_arg = | 87 scoped_ptr<ExtensionActivity> activity_arg = |
| 89 activity->ConvertToExtensionActivity(); | 88 activity->ConvertToExtensionActivity(); |
| 90 value->Append(activity_arg->ToValue().release()); | 89 value->Append(activity_arg->ToValue().release()); |
| 91 scoped_ptr<Event> event( | 90 scoped_ptr<Event> event( |
| 92 new Event(activity_log_private::OnExtensionActivity::kEventName, | 91 new Event(activity_log_private::OnExtensionActivity::kEventName, |
| 93 value.Pass())); | 92 value.Pass())); |
| 94 event->restrict_to_browser_context = profile_; | 93 event->restrict_to_browser_context = context_; |
| 95 ExtensionSystem::Get(profile_)->event_router()->BroadcastEvent(event.Pass()); | 94 ExtensionSystem::Get(context_)->event_router()->BroadcastEvent(event.Pass()); |
| 96 } | 95 } |
| 97 | 96 |
| 98 bool ActivityLogPrivateGetExtensionActivitiesFunction::RunImpl() { | 97 bool ActivityLogPrivateGetExtensionActivitiesFunction::RunImpl() { |
| 99 scoped_ptr<activity_log_private::GetExtensionActivities::Params> params( | 98 scoped_ptr<activity_log_private::GetExtensionActivities::Params> params( |
| 100 activity_log_private::GetExtensionActivities::Params::Create(*args_)); | 99 activity_log_private::GetExtensionActivities::Params::Create(*args_)); |
| 101 EXTENSION_FUNCTION_VALIDATE(params.get()); | 100 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 102 | 101 |
| 103 // Get the arguments in the right format. | 102 // Get the arguments in the right format. |
| 104 scoped_ptr<Filter> filter; | 103 scoped_ptr<Filter> filter; |
| 105 filter.reset(¶ms.release()->filter); | 104 filter.reset(¶ms.release()->filter); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 gurls.push_back(GURL(*it)); | 215 gurls.push_back(GURL(*it)); |
| 217 } | 216 } |
| 218 | 217 |
| 219 ActivityLog* activity_log = ActivityLog::GetInstance(GetProfile()); | 218 ActivityLog* activity_log = ActivityLog::GetInstance(GetProfile()); |
| 220 DCHECK(activity_log); | 219 DCHECK(activity_log); |
| 221 activity_log->RemoveURLs(gurls); | 220 activity_log->RemoveURLs(gurls); |
| 222 return true; | 221 return true; |
| 223 } | 222 } |
| 224 | 223 |
| 225 } // namespace extensions | 224 } // namespace extensions |
| OLD | NEW |