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

Side by Side Diff: chrome/browser/themes/theme_service.cc

Issue 965233002: Remove deprecated extension notification from theme_service (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove ExtensionRegistryObserver and Call from ExtensionService instead. Created 5 years, 9 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/themes/theme_service.h" 5 #include "chrome/browser/themes/theme_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/ref_counted_memory.h" 10 #include "base/memory/ref_counted_memory.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 const int kChannelTolerance = 9; 89 const int kChannelTolerance = 9;
90 int r = SkColorGetR(color); 90 int r = SkColorGetR(color);
91 int g = SkColorGetG(color); 91 int g = SkColorGetG(color);
92 int b = SkColorGetB(color); 92 int b = SkColorGetB(color);
93 int range = std::max(r, std::max(g, b)) - std::min(r, std::min(g, b)); 93 int range = std::max(r, std::max(g, b)) - std::min(r, std::min(g, b));
94 return range < kChannelTolerance; 94 return range < kChannelTolerance;
95 } 95 }
96 96
97 } // namespace 97 } // namespace
98 98
99 ThemeService::ExtensionObserver::ExtensionObserver(ThemeService& service)
100 : theme_service_(service) {
101 }
102
103 ThemeService::ExtensionObserver::~ExtensionObserver() {
104 }
105
106 void ThemeService::ExtensionObserver::OnExtensionWillBeInstalled(
107 const extensions::Extension* extension) {
108 if (extension->is_theme()) {
109 // The theme may be initially disabled. Wait till it is loaded (if ever).
110 theme_service_.installed_pending_load_id_ = extension->id();
111 }
112 }
113
114 void ThemeService::ExtensionObserver::OnExtensionLoaded(
115 const extensions::Extension* extension) {
116 if (extension->is_theme() &&
117 theme_service_.installed_pending_load_id_ != kDefaultThemeID &&
118 theme_service_.installed_pending_load_id_ == extension->id()) {
119 theme_service_.SetTheme(extension);
120 }
121 theme_service_.installed_pending_load_id_ = kDefaultThemeID;
122 }
123
124 void ThemeService::ExtensionObserver::OnExtensionUnloaded(
125 const extensions::Extension* extension) {
126 if (extension->is_theme() && extension->id() == theme_service_.GetThemeID()) {
127 theme_service_.UseDefaultTheme();
128 }
129 }
130
99 ThemeService::ThemeService() 131 ThemeService::ThemeService()
100 : ready_(false), 132 : ready_(false),
101 rb_(ResourceBundle::GetSharedInstance()), 133 rb_(ResourceBundle::GetSharedInstance()),
102 profile_(NULL), 134 profile_(NULL),
103 installed_pending_load_id_(kDefaultThemeID), 135 installed_pending_load_id_(kDefaultThemeID),
104 number_of_infobars_(0), 136 number_of_infobars_(0),
137 extension_observer_(*this),
105 weak_ptr_factory_(this) { 138 weak_ptr_factory_(this) {
106 } 139 }
107 140
108 ThemeService::~ThemeService() { 141 ThemeService::~ThemeService() {
109 FreePlatformCaches(); 142 FreePlatformCaches();
110 } 143 }
111 144
112 void ThemeService::Init(Profile* profile) { 145 void ThemeService::Init(Profile* profile) {
113 DCHECK(CalledOnValidThread()); 146 DCHECK(CalledOnValidThread());
114 profile_ = profile; 147 profile_ = profile;
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 const content::NotificationSource& source, 294 const content::NotificationSource& source,
262 const content::NotificationDetails& details) { 295 const content::NotificationDetails& details) {
263 using content::Details; 296 using content::Details;
264 switch (type) { 297 switch (type) {
265 case extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED: 298 case extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED:
266 registrar_.Remove(this, 299 registrar_.Remove(this,
267 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED, 300 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED,
268 content::Source<Profile>(profile_)); 301 content::Source<Profile>(profile_));
269 OnExtensionServiceReady(); 302 OnExtensionServiceReady();
270 break; 303 break;
271 case extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED: {
272 // The theme may be initially disabled. Wait till it is loaded (if ever).
273 Details<const extensions::InstalledExtensionInfo> installed_details(
274 details);
275 if (installed_details->extension->is_theme())
276 installed_pending_load_id_ = installed_details->extension->id();
277 break;
278 }
279 case extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: {
280 const Extension* extension = Details<const Extension>(details).ptr();
281 if (extension->is_theme() &&
282 installed_pending_load_id_ != kDefaultThemeID &&
283 installed_pending_load_id_ == extension->id()) {
284 SetTheme(extension);
285 }
286 installed_pending_load_id_ = kDefaultThemeID;
287 break;
288 }
289 case extensions::NOTIFICATION_EXTENSION_ENABLED: { 304 case extensions::NOTIFICATION_EXTENSION_ENABLED: {
290 const Extension* extension = Details<const Extension>(details).ptr(); 305 const Extension* extension = Details<const Extension>(details).ptr();
291 if (extension->is_theme()) 306 if (extension->is_theme())
292 SetTheme(extension); 307 SetTheme(extension);
293 break; 308 break;
294 } 309 }
295 case extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: {
296 Details<const UnloadedExtensionInfo> unloaded_details(details);
297 if (unloaded_details->reason != UnloadedExtensionInfo::REASON_UPDATE &&
298 unloaded_details->reason != UnloadedExtensionInfo::REASON_LOCK_ALL &&
299 unloaded_details->extension->is_theme() &&
300 unloaded_details->extension->id() == GetThemeID()) {
301 UseDefaultTheme();
302 }
303 break;
304 }
305 } 310 }
306 } 311 }
307 312
308 void ThemeService::SetTheme(const Extension* extension) { 313 void ThemeService::SetTheme(const Extension* extension) {
309 DCHECK(extension->is_theme()); 314 DCHECK(extension->is_theme());
310 ExtensionService* service = 315 ExtensionService* service =
311 extensions::ExtensionSystem::Get(profile_)->extension_service(); 316 extensions::ExtensionSystem::Get(profile_)->extension_service();
312 if (!service->IsExtensionEnabled(extension->id())) { 317 if (!service->IsExtensionEnabled(extension->id())) {
313 // |extension| is disabled when reverting to the previous theme via an 318 // |extension| is disabled when reverting to the previous theme via an
314 // infobar. 319 // infobar.
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 // If the ThemeService is not ready yet, the custom theme data pack needs to 527 // If the ThemeService is not ready yet, the custom theme data pack needs to
523 // be recreated from the extension. 528 // be recreated from the extension.
524 MigrateTheme(); 529 MigrateTheme();
525 set_ready(); 530 set_ready();
526 531
527 // Send notification in case anyone requested data and cached it when the 532 // Send notification in case anyone requested data and cached it when the
528 // theme service was not ready yet. 533 // theme service was not ready yet.
529 NotifyThemeChanged(); 534 NotifyThemeChanged();
530 } 535 }
531 536
532 registrar_.Add(
533 this,
534 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED,
535 content::Source<Profile>(profile_));
536 registrar_.Add(this,
537 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
538 content::Source<Profile>(profile_));
539 registrar_.Add(this, 537 registrar_.Add(this,
540 extensions::NOTIFICATION_EXTENSION_ENABLED, 538 extensions::NOTIFICATION_EXTENSION_ENABLED,
541 content::Source<Profile>(profile_)); 539 content::Source<Profile>(profile_));
542 registrar_.Add(this,
543 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
544 content::Source<Profile>(profile_));
545 540
546 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, 541 base::MessageLoop::current()->PostDelayedTask(FROM_HERE,
547 base::Bind(&ThemeService::RemoveUnusedThemes, 542 base::Bind(&ThemeService::RemoveUnusedThemes,
548 weak_ptr_factory_.GetWeakPtr(), 543 weak_ptr_factory_.GetWeakPtr(),
549 false), 544 false),
550 base::TimeDelta::FromSeconds(kRemoveUnusedThemesStartupDelay)); 545 base::TimeDelta::FromSeconds(kRemoveUnusedThemesStartupDelay));
551 } 546 }
552 547
553 void ThemeService::MigrateTheme() { 548 void ThemeService::MigrateTheme() {
554 // TODO(erg): We need to pop up a dialog informing the user that their 549 // TODO(erg): We need to pop up a dialog informing the user that their
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 void ThemeService::OnInfobarDestroyed() { 624 void ThemeService::OnInfobarDestroyed() {
630 number_of_infobars_--; 625 number_of_infobars_--;
631 626
632 if (number_of_infobars_ == 0) 627 if (number_of_infobars_ == 0)
633 RemoveUnusedThemes(false); 628 RemoveUnusedThemes(false);
634 } 629 }
635 630
636 ThemeSyncableService* ThemeService::GetThemeSyncableService() const { 631 ThemeSyncableService* ThemeService::GetThemeSyncableService() const {
637 return theme_syncable_service_.get(); 632 return theme_syncable_service_.get();
638 } 633 }
634
635 ThemeService::ExtensionObserver ThemeService::extension_observer() const {
636 return extension_observer_;
637 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698