OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/activity_log/activity_log.h" | 5 #include "chrome/browser/extensions/activity_log/activity_log.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <set> | 8 #include <set> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "chrome/browser/prerender/prerender_manager_factory.h" | 28 #include "chrome/browser/prerender/prerender_manager_factory.h" |
29 #include "chrome/browser/profiles/profile.h" | 29 #include "chrome/browser/profiles/profile.h" |
30 #include "chrome/browser/ui/browser.h" | 30 #include "chrome/browser/ui/browser.h" |
31 #include "chrome/common/chrome_constants.h" | 31 #include "chrome/common/chrome_constants.h" |
32 #include "chrome/common/chrome_switches.h" | 32 #include "chrome/common/chrome_switches.h" |
33 #include "chrome/common/pref_names.h" | 33 #include "chrome/common/pref_names.h" |
34 #include "components/syncable_prefs/pref_service_syncable.h" | 34 #include "components/syncable_prefs/pref_service_syncable.h" |
35 #include "content/public/browser/browser_thread.h" | 35 #include "content/public/browser/browser_thread.h" |
36 #include "content/public/browser/notification_service.h" | 36 #include "content/public/browser/notification_service.h" |
37 #include "content/public/browser/notification_source.h" | 37 #include "content/public/browser/notification_source.h" |
| 38 #include "content/public/browser/render_process_host.h" |
38 #include "content/public/browser/web_contents.h" | 39 #include "content/public/browser/web_contents.h" |
39 #include "extensions/browser/api_activity_monitor.h" | 40 #include "extensions/browser/api_activity_monitor.h" |
40 #include "extensions/browser/extension_registry.h" | 41 #include "extensions/browser/extension_registry.h" |
41 #include "extensions/browser/extension_registry_factory.h" | 42 #include "extensions/browser/extension_registry_factory.h" |
42 #include "extensions/browser/extension_system.h" | 43 #include "extensions/browser/extension_system.h" |
43 #include "extensions/browser/extension_system_provider.h" | 44 #include "extensions/browser/extension_system_provider.h" |
44 #include "extensions/browser/extensions_browser_client.h" | 45 #include "extensions/browser/extensions_browser_client.h" |
45 #include "extensions/common/extension.h" | 46 #include "extensions/common/extension.h" |
| 47 #include "extensions/common/extension_messages.h" |
46 #include "extensions/common/one_shot_event.h" | 48 #include "extensions/common/one_shot_event.h" |
47 #include "third_party/re2/src/re2/re2.h" | 49 #include "third_party/re2/src/re2/re2.h" |
48 #include "url/gurl.h" | 50 #include "url/gurl.h" |
49 | 51 |
50 namespace constants = activity_log_constants; | 52 namespace constants = activity_log_constants; |
51 | 53 |
52 namespace extensions { | 54 namespace extensions { |
53 | 55 |
54 namespace { | 56 namespace { |
55 | 57 |
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
832 return; | 834 return; |
833 database_policy_->DeleteDatabase(); | 835 database_policy_->DeleteDatabase(); |
834 } | 836 } |
835 | 837 |
836 void ActivityLog::CheckActive() { | 838 void ActivityLog::CheckActive() { |
837 bool has_db = db_enabled_ && database_policy_; | 839 bool has_db = db_enabled_ && database_policy_; |
838 ActivityLogState& state = g_activity_log_state.Get(); | 840 ActivityLogState& state = g_activity_log_state.Get(); |
839 content::BrowserContext* off_the_record = | 841 content::BrowserContext* off_the_record = |
840 profile_->HasOffTheRecordProfile() ? profile_->GetOffTheRecordProfile() | 842 profile_->HasOffTheRecordProfile() ? profile_->GetOffTheRecordProfile() |
841 : nullptr; | 843 : nullptr; |
| 844 |
| 845 bool old_is_active = is_active_; |
842 if (has_db || IsWatchdogAppActive()) { | 846 if (has_db || IsWatchdogAppActive()) { |
843 if (is_active_) | 847 if (is_active_) |
844 return; // Already enabled. | 848 return; // Already enabled. |
845 state.AddActiveContext(profile_); | 849 state.AddActiveContext(profile_); |
846 if (off_the_record) | 850 if (off_the_record) |
847 state.AddActiveContext(off_the_record); | 851 state.AddActiveContext(off_the_record); |
848 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CREATED, | 852 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CREATED, |
849 content::NotificationService::AllSources()); | 853 content::NotificationService::AllSources()); |
850 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, | 854 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
851 content::NotificationService::AllSources()); | 855 content::NotificationService::AllSources()); |
852 is_active_ = true; | 856 is_active_ = true; |
853 } else if (is_active_) { | 857 } else if (is_active_) { |
854 state.RemoveActiveContext(profile_); | 858 state.RemoveActiveContext(profile_); |
855 if (off_the_record) | 859 if (off_the_record) |
856 state.RemoveActiveContext(off_the_record); | 860 state.RemoveActiveContext(off_the_record); |
857 registrar_.RemoveAll(); | 861 registrar_.RemoveAll(); |
858 is_active_ = false; | 862 is_active_ = false; |
859 } | 863 } |
| 864 |
| 865 if (old_is_active != is_active_) { |
| 866 for (content::RenderProcessHost::iterator iter( |
| 867 content::RenderProcessHost::AllHostsIterator()); |
| 868 !iter.IsAtEnd(); iter.Advance()) { |
| 869 content::RenderProcessHost* host = iter.GetCurrentValue(); |
| 870 if (profile_->IsSameProfile( |
| 871 Profile::FromBrowserContext(host->GetBrowserContext()))) { |
| 872 host->Send(new ExtensionMsg_SetActivityLoggingEnabled(is_active_)); |
| 873 } |
| 874 } |
| 875 } |
860 } | 876 } |
861 | 877 |
862 void ActivityLog::Observe(int type, | 878 void ActivityLog::Observe(int type, |
863 const content::NotificationSource& source, | 879 const content::NotificationSource& source, |
864 const content::NotificationDetails& details) { | 880 const content::NotificationDetails& details) { |
865 DCHECK(is_active_); | 881 DCHECK(is_active_); |
866 switch (type) { | 882 switch (type) { |
867 case chrome::NOTIFICATION_PROFILE_CREATED: { | 883 case chrome::NOTIFICATION_PROFILE_CREATED: { |
868 Profile* profile = content::Source<Profile>(source).ptr(); | 884 Profile* profile = content::Source<Profile>(source).ptr(); |
869 if (profile_->IsSameProfile(profile)) | 885 if (profile_->IsSameProfile(profile)) |
(...skipping 11 matching lines...) Expand all Loading... |
881 } | 897 } |
882 } | 898 } |
883 | 899 |
884 template <> | 900 template <> |
885 void BrowserContextKeyedAPIFactory<ActivityLog>::DeclareFactoryDependencies() { | 901 void BrowserContextKeyedAPIFactory<ActivityLog>::DeclareFactoryDependencies() { |
886 DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); | 902 DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); |
887 DependsOn(ExtensionRegistryFactory::GetInstance()); | 903 DependsOn(ExtensionRegistryFactory::GetInstance()); |
888 } | 904 } |
889 | 905 |
890 } // namespace extensions | 906 } // namespace extensions |
OLD | NEW |