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

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: 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 } 95 }
96 96
97 } // namespace 97 } // namespace
98 98
99 ThemeService::ThemeService() 99 ThemeService::ThemeService()
100 : ready_(false), 100 : ready_(false),
101 rb_(ResourceBundle::GetSharedInstance()), 101 rb_(ResourceBundle::GetSharedInstance()),
102 profile_(NULL), 102 profile_(NULL),
103 installed_pending_load_id_(kDefaultThemeID), 103 installed_pending_load_id_(kDefaultThemeID),
104 number_of_infobars_(0), 104 number_of_infobars_(0),
105 extension_registry_(NULL),
105 weak_ptr_factory_(this) { 106 weak_ptr_factory_(this) {
106 } 107 }
107 108
108 ThemeService::~ThemeService() { 109 ThemeService::~ThemeService() {
109 FreePlatformCaches(); 110 FreePlatformCaches();
110 } 111 }
111 112
112 void ThemeService::Init(Profile* profile) { 113 void ThemeService::Init(Profile* profile) {
113 DCHECK(CalledOnValidThread()); 114 DCHECK(CalledOnValidThread());
114 profile_ = profile; 115 profile_ = profile;
115 116
116 LoadThemePrefs(); 117 LoadThemePrefs();
117 118
119 extension_registry_ = extensions::ExtensionRegistry::Get(profile_);
120
118 registrar_.Add(this, 121 registrar_.Add(this,
119 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED, 122 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED,
120 content::Source<Profile>(profile_)); 123 content::Source<Profile>(profile_));
121 124
122 theme_syncable_service_.reset(new ThemeSyncableService(profile_, this)); 125 theme_syncable_service_.reset(new ThemeSyncableService(profile_, this));
123 } 126 }
124 127
125 gfx::Image ThemeService::GetImageNamed(int id) const { 128 gfx::Image ThemeService::GetImageNamed(int id) const {
126 DCHECK(CalledOnValidThread()); 129 DCHECK(CalledOnValidThread());
127 130
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 const content::NotificationSource& source, 264 const content::NotificationSource& source,
262 const content::NotificationDetails& details) { 265 const content::NotificationDetails& details) {
263 using content::Details; 266 using content::Details;
264 switch (type) { 267 switch (type) {
265 case extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED: 268 case extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED:
266 registrar_.Remove(this, 269 registrar_.Remove(this,
267 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED, 270 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED,
268 content::Source<Profile>(profile_)); 271 content::Source<Profile>(profile_));
269 OnExtensionServiceReady(); 272 OnExtensionServiceReady();
270 break; 273 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: { 274 case extensions::NOTIFICATION_EXTENSION_ENABLED: {
290 const Extension* extension = Details<const Extension>(details).ptr(); 275 const Extension* extension = Details<const Extension>(details).ptr();
291 if (extension->is_theme()) 276 if (extension->is_theme())
292 SetTheme(extension); 277 SetTheme(extension);
293 break; 278 break;
294 } 279 }
295 case extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: { 280 default:
296 Details<const UnloadedExtensionInfo> unloaded_details(details); 281 NOTREACHED();
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 } 282 }
306 } 283 }
307 284
285 void ThemeService::OnExtensionLoaded(content::BrowserContext* browser_context,
286 const Extension* extension) {
287 if (extension->is_theme() && installed_pending_load_id_ != kDefaultThemeID &&
288 installed_pending_load_id_ == extension->id()) {
289 SetTheme(extension);
290 }
291 installed_pending_load_id_ = kDefaultThemeID;
292 }
293
294 void ThemeService::OnExtensionUnloaded(
295 content::BrowserContext* browser_context,
296 const Extension* extension,
297 UnloadedExtensionInfo::Reason reason) {
298 if (reason != UnloadedExtensionInfo::REASON_UPDATE &&
299 reason != UnloadedExtensionInfo::REASON_LOCK_ALL &&
300 extension->is_theme() &&
301 extension->id() == GetThemeID()) {
302 UseDefaultTheme();
303 }
304 }
305
306 void ThemeService::OnExtensionWillBeInstalled(
307 content::BrowserContext* browser_context,
308 const Extension* extension,
309 bool is_update,
310 bool from_ephemeral,
311 const std::string& old_name) {
312 // The theme may be initially disabled. Wait till it is loaded (if ever).
313 if (extension->is_theme())
314 installed_pending_load_id_ = extension->id();
315 }
316
317 void ThemeService::Shutdown() {
318 extension_registry_->RemoveObserver(this);
319 }
320
308 void ThemeService::SetTheme(const Extension* extension) { 321 void ThemeService::SetTheme(const Extension* extension) {
309 DCHECK(extension->is_theme()); 322 DCHECK(extension->is_theme());
310 ExtensionService* service = 323 ExtensionService* service =
311 extensions::ExtensionSystem::Get(profile_)->extension_service(); 324 extensions::ExtensionSystem::Get(profile_)->extension_service();
312 if (!service->IsExtensionEnabled(extension->id())) { 325 if (!service->IsExtensionEnabled(extension->id())) {
313 // |extension| is disabled when reverting to the previous theme via an 326 // |extension| is disabled when reverting to the previous theme via an
314 // infobar. 327 // infobar.
315 service->EnableExtension(extension->id()); 328 service->EnableExtension(extension->id());
316 // Enabling the extension will call back to SetTheme(). 329 // Enabling the extension will call back to SetTheme().
317 return; 330 return;
(...skipping 204 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 535 // If the ThemeService is not ready yet, the custom theme data pack needs to
523 // be recreated from the extension. 536 // be recreated from the extension.
524 MigrateTheme(); 537 MigrateTheme();
525 set_ready(); 538 set_ready();
526 539
527 // Send notification in case anyone requested data and cached it when the 540 // Send notification in case anyone requested data and cached it when the
528 // theme service was not ready yet. 541 // theme service was not ready yet.
529 NotifyThemeChanged(); 542 NotifyThemeChanged();
530 } 543 }
531 544
532 registrar_.Add( 545 extension_registry_->AddObserver(this);
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, 546 registrar_.Add(this,
540 extensions::NOTIFICATION_EXTENSION_ENABLED, 547 extensions::NOTIFICATION_EXTENSION_ENABLED,
541 content::Source<Profile>(profile_)); 548 content::Source<Profile>(profile_));
542 registrar_.Add(this,
543 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
544 content::Source<Profile>(profile_));
545 549
546 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, 550 base::MessageLoop::current()->PostDelayedTask(FROM_HERE,
547 base::Bind(&ThemeService::RemoveUnusedThemes, 551 base::Bind(&ThemeService::RemoveUnusedThemes,
548 weak_ptr_factory_.GetWeakPtr(), 552 weak_ptr_factory_.GetWeakPtr(),
549 false), 553 false),
550 base::TimeDelta::FromSeconds(kRemoveUnusedThemesStartupDelay)); 554 base::TimeDelta::FromSeconds(kRemoveUnusedThemesStartupDelay));
551 } 555 }
552 556
553 void ThemeService::MigrateTheme() { 557 void ThemeService::MigrateTheme() {
554 // TODO(erg): We need to pop up a dialog informing the user that their 558 // 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() { 633 void ThemeService::OnInfobarDestroyed() {
630 number_of_infobars_--; 634 number_of_infobars_--;
631 635
632 if (number_of_infobars_ == 0) 636 if (number_of_infobars_ == 0)
633 RemoveUnusedThemes(false); 637 RemoveUnusedThemes(false);
634 } 638 }
635 639
636 ThemeSyncableService* ThemeService::GetThemeSyncableService() const { 640 ThemeSyncableService* ThemeService::GetThemeSyncableService() const {
637 return theme_syncable_service_.get(); 641 return theme_syncable_service_.get();
638 } 642 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698