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

Side by Side Diff: chrome/browser/notifications/notifier_state_tracker.cc

Issue 2479593006: Move enable extensions define to a build flag. (Closed)
Patch Set: Merge Created 4 years, 1 month 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/notifications/notifier_state_tracker.h" 5 #include "chrome/browser/notifications/notifier_state_tracker.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "build/build_config.h" 13 #include "build/build_config.h"
14 #include "chrome/browser/permissions/permission_manager.h" 14 #include "chrome/browser/permissions/permission_manager.h"
15 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/common/pref_names.h" 16 #include "chrome/common/pref_names.h"
17 #include "components/pref_registry/pref_registry_syncable.h" 17 #include "components/pref_registry/pref_registry_syncable.h"
18 #include "components/prefs/scoped_user_pref_update.h" 18 #include "components/prefs/scoped_user_pref_update.h"
19 #include "content/public/browser/permission_type.h" 19 #include "content/public/browser/permission_type.h"
20 #include "extensions/features/features.h"
20 #include "ui/message_center/notifier_settings.h" 21 #include "ui/message_center/notifier_settings.h"
21 22
22 #if defined(ENABLE_EXTENSIONS) 23 #if BUILDFLAG(ENABLE_EXTENSIONS)
23 #include "chrome/common/extensions/api/notifications.h" 24 #include "chrome/common/extensions/api/notifications.h"
24 #include "content/public/browser/browser_thread.h" 25 #include "content/public/browser/browser_thread.h"
25 #include "extensions/browser/event_router.h" 26 #include "extensions/browser/event_router.h"
26 #include "extensions/browser/extension_event_histogram_value.h" 27 #include "extensions/browser/extension_event_histogram_value.h"
27 #include "extensions/browser/extension_system.h" 28 #include "extensions/browser/extension_system.h"
28 #include "extensions/browser/extension_util.h" 29 #include "extensions/browser/extension_util.h"
29 #include "extensions/browser/info_map.h" 30 #include "extensions/browser/info_map.h"
30 #endif 31 #endif
31 32
32 using message_center::NotifierId; 33 using message_center::NotifierId;
33 34
34 // static 35 // static
35 void NotifierStateTracker::RegisterProfilePrefs( 36 void NotifierStateTracker::RegisterProfilePrefs(
36 user_prefs::PrefRegistrySyncable* registry) { 37 user_prefs::PrefRegistrySyncable* registry) {
37 registry->RegisterListPref(prefs::kMessageCenterDisabledExtensionIds); 38 registry->RegisterListPref(prefs::kMessageCenterDisabledExtensionIds);
38 registry->RegisterListPref(prefs::kMessageCenterDisabledSystemComponentIds); 39 registry->RegisterListPref(prefs::kMessageCenterDisabledSystemComponentIds);
39 } 40 }
40 41
41 NotifierStateTracker::NotifierStateTracker(Profile* profile) 42 NotifierStateTracker::NotifierStateTracker(Profile* profile)
42 : profile_(profile) 43 : profile_(profile)
43 #if defined(ENABLE_EXTENSIONS) 44 #if BUILDFLAG(ENABLE_EXTENSIONS)
44 , 45 ,
45 extension_registry_observer_(this) 46 extension_registry_observer_(this)
46 #endif 47 #endif
47 { 48 {
48 OnStringListPrefChanged( 49 OnStringListPrefChanged(
49 prefs::kMessageCenterDisabledExtensionIds, &disabled_extension_ids_); 50 prefs::kMessageCenterDisabledExtensionIds, &disabled_extension_ids_);
50 OnStringListPrefChanged( 51 OnStringListPrefChanged(
51 prefs::kMessageCenterDisabledSystemComponentIds, 52 prefs::kMessageCenterDisabledSystemComponentIds,
52 &disabled_system_component_ids_); 53 &disabled_system_component_ids_);
53 54
54 disabled_extension_id_pref_.Init( 55 disabled_extension_id_pref_.Init(
55 prefs::kMessageCenterDisabledExtensionIds, 56 prefs::kMessageCenterDisabledExtensionIds,
56 profile_->GetPrefs(), 57 profile_->GetPrefs(),
57 base::Bind( 58 base::Bind(
58 &NotifierStateTracker::OnStringListPrefChanged, 59 &NotifierStateTracker::OnStringListPrefChanged,
59 base::Unretained(this), 60 base::Unretained(this),
60 base::Unretained(prefs::kMessageCenterDisabledExtensionIds), 61 base::Unretained(prefs::kMessageCenterDisabledExtensionIds),
61 base::Unretained(&disabled_extension_ids_))); 62 base::Unretained(&disabled_extension_ids_)));
62 63
63 disabled_system_component_id_pref_.Init( 64 disabled_system_component_id_pref_.Init(
64 prefs::kMessageCenterDisabledSystemComponentIds, 65 prefs::kMessageCenterDisabledSystemComponentIds,
65 profile_->GetPrefs(), 66 profile_->GetPrefs(),
66 base::Bind( 67 base::Bind(
67 &NotifierStateTracker::OnStringListPrefChanged, 68 &NotifierStateTracker::OnStringListPrefChanged,
68 base::Unretained(this), 69 base::Unretained(this),
69 base::Unretained(prefs::kMessageCenterDisabledSystemComponentIds), 70 base::Unretained(prefs::kMessageCenterDisabledSystemComponentIds),
70 base::Unretained(&disabled_system_component_ids_))); 71 base::Unretained(&disabled_system_component_ids_)));
71 72
72 #if defined(ENABLE_EXTENSIONS) 73 #if BUILDFLAG(ENABLE_EXTENSIONS)
73 extension_registry_observer_.Add( 74 extension_registry_observer_.Add(
74 extensions::ExtensionRegistry::Get(profile_)); 75 extensions::ExtensionRegistry::Get(profile_));
75 #endif 76 #endif
76 } 77 }
77 78
78 NotifierStateTracker::~NotifierStateTracker() { 79 NotifierStateTracker::~NotifierStateTracker() {
79 } 80 }
80 81
81 bool NotifierStateTracker::IsNotifierEnabled( 82 bool NotifierStateTracker::IsNotifierEnabled(
82 const NotifierId& notifier_id) const { 83 const NotifierId& notifier_id) const {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 DCHECK_NE(NotifierId::WEB_PAGE, notifier_id.type); 120 DCHECK_NE(NotifierId::WEB_PAGE, notifier_id.type);
120 121
121 bool add_new_item = false; 122 bool add_new_item = false;
122 const char* pref_name = NULL; 123 const char* pref_name = NULL;
123 std::unique_ptr<base::StringValue> id; 124 std::unique_ptr<base::StringValue> id;
124 switch (notifier_id.type) { 125 switch (notifier_id.type) {
125 case NotifierId::APPLICATION: 126 case NotifierId::APPLICATION:
126 pref_name = prefs::kMessageCenterDisabledExtensionIds; 127 pref_name = prefs::kMessageCenterDisabledExtensionIds;
127 add_new_item = !enabled; 128 add_new_item = !enabled;
128 id.reset(new base::StringValue(notifier_id.id)); 129 id.reset(new base::StringValue(notifier_id.id));
129 #if defined(ENABLE_EXTENSIONS) 130 #if BUILDFLAG(ENABLE_EXTENSIONS)
130 FirePermissionLevelChangedEvent(notifier_id, enabled); 131 FirePermissionLevelChangedEvent(notifier_id, enabled);
131 #endif 132 #endif
132 break; 133 break;
133 case NotifierId::SYSTEM_COMPONENT: 134 case NotifierId::SYSTEM_COMPONENT:
134 #if defined(OS_CHROMEOS) 135 #if defined(OS_CHROMEOS)
135 pref_name = prefs::kMessageCenterDisabledSystemComponentIds; 136 pref_name = prefs::kMessageCenterDisabledSystemComponentIds;
136 add_new_item = !enabled; 137 add_new_item = !enabled;
137 id.reset(new base::StringValue(notifier_id.id)); 138 id.reset(new base::StringValue(notifier_id.id));
138 #else 139 #else
139 return; 140 return;
(...skipping 22 matching lines...) Expand all
162 const base::ListValue* pref_list = pref_service->GetList(pref_name); 163 const base::ListValue* pref_list = pref_service->GetList(pref_name);
163 for (size_t i = 0; i < pref_list->GetSize(); ++i) { 164 for (size_t i = 0; i < pref_list->GetSize(); ++i) {
164 std::string element; 165 std::string element;
165 if (pref_list->GetString(i, &element) && !element.empty()) 166 if (pref_list->GetString(i, &element) && !element.empty())
166 ids_field->insert(element); 167 ids_field->insert(element);
167 else 168 else
168 LOG(WARNING) << i << "-th element is not a string for " << pref_name; 169 LOG(WARNING) << i << "-th element is not a string for " << pref_name;
169 } 170 }
170 } 171 }
171 172
172 #if defined(ENABLE_EXTENSIONS) 173 #if BUILDFLAG(ENABLE_EXTENSIONS)
173 void NotifierStateTracker::OnExtensionUninstalled( 174 void NotifierStateTracker::OnExtensionUninstalled(
174 content::BrowserContext* browser_context, 175 content::BrowserContext* browser_context,
175 const extensions::Extension* extension, 176 const extensions::Extension* extension,
176 extensions::UninstallReason reason) { 177 extensions::UninstallReason reason) {
177 NotifierId notifier_id(NotifierId::APPLICATION, extension->id()); 178 NotifierId notifier_id(NotifierId::APPLICATION, extension->id());
178 if (IsNotifierEnabled(notifier_id)) 179 if (IsNotifierEnabled(notifier_id))
179 return; 180 return;
180 181
181 SetNotifierEnabled(notifier_id, true); 182 SetNotifierEnabled(notifier_id, true);
182 } 183 }
(...skipping 16 matching lines...) Expand all
199 // Tell the IO thread that this extension's permission for notifications 200 // Tell the IO thread that this extension's permission for notifications
200 // has changed. 201 // has changed.
201 extensions::InfoMap* extension_info_map = 202 extensions::InfoMap* extension_info_map =
202 extensions::ExtensionSystem::Get(profile_)->info_map(); 203 extensions::ExtensionSystem::Get(profile_)->info_map();
203 content::BrowserThread::PostTask( 204 content::BrowserThread::PostTask(
204 content::BrowserThread::IO, FROM_HERE, 205 content::BrowserThread::IO, FROM_HERE,
205 base::Bind(&extensions::InfoMap::SetNotificationsDisabled, 206 base::Bind(&extensions::InfoMap::SetNotificationsDisabled,
206 extension_info_map, notifier_id.id, !enabled)); 207 extension_info_map, notifier_id.id, !enabled));
207 } 208 }
208 #endif 209 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698