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

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

Issue 2893693002: Remove NOTIFICATION_EXTENSION_ENABLED. (Closed)
Patch Set: add code for component reload Created 3 years, 6 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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 #include "extensions/common/extension_set.h" 42 #include "extensions/common/extension_set.h"
43 #include "extensions/features/features.h" 43 #include "extensions/features/features.h"
44 #include "ui/base/layout.h" 44 #include "ui/base/layout.h"
45 #include "ui/base/resource/resource_bundle.h" 45 #include "ui/base/resource/resource_bundle.h"
46 #include "ui/gfx/color_palette.h" 46 #include "ui/gfx/color_palette.h"
47 #include "ui/gfx/image/image_skia.h" 47 #include "ui/gfx/image/image_skia.h"
48 #include "ui/native_theme/common_theme.h" 48 #include "ui/native_theme/common_theme.h"
49 #include "ui/native_theme/native_theme.h" 49 #include "ui/native_theme/native_theme.h"
50 50
51 #if BUILDFLAG(ENABLE_EXTENSIONS) 51 #if BUILDFLAG(ENABLE_EXTENSIONS)
52 #include "base/scoped_observer.h"
52 #include "extensions/browser/extension_registry_observer.h" 53 #include "extensions/browser/extension_registry_observer.h"
53 #endif 54 #endif
54 55
55 #if BUILDFLAG(ENABLE_SUPERVISED_USERS) 56 #if BUILDFLAG(ENABLE_SUPERVISED_USERS)
56 #include "chrome/browser/supervised_user/supervised_user_theme.h" 57 #include "chrome/browser/supervised_user/supervised_user_theme.h"
57 #endif 58 #endif
58 59
59 using base::UserMetricsAction; 60 using base::UserMetricsAction;
60 using content::BrowserThread; 61 using content::BrowserThread;
61 using extensions::Extension; 62 using extensions::Extension;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 return theme_service_.GetRawData(id, scale_factor); 154 return theme_service_.GetRawData(id, scale_factor);
154 } 155 }
155 156
156 157
157 // ThemeService::ThemeObserver ------------------------------------------------ 158 // ThemeService::ThemeObserver ------------------------------------------------
158 159
159 #if BUILDFLAG(ENABLE_EXTENSIONS) 160 #if BUILDFLAG(ENABLE_EXTENSIONS)
160 class ThemeService::ThemeObserver 161 class ThemeService::ThemeObserver
161 : public extensions::ExtensionRegistryObserver { 162 : public extensions::ExtensionRegistryObserver {
162 public: 163 public:
163 explicit ThemeObserver(ThemeService* service) : theme_service_(service) { 164 explicit ThemeObserver(ThemeService* service)
164 extensions::ExtensionRegistry::Get(theme_service_->profile_) 165 : theme_service_(service), extension_registry_observer_(this) {
165 ->AddObserver(this); 166 extension_registry_observer_.Add(
167 extensions::ExtensionRegistry::Get(theme_service_->profile_));
166 } 168 }
167 169
168 ~ThemeObserver() override { 170 ~ThemeObserver() override {
169 extensions::ExtensionRegistry::Get(theme_service_->profile_)
170 ->RemoveObserver(this);
171 } 171 }
172 172
173 private: 173 private:
174 // extensions::ExtensionRegistryObserver:
174 void OnExtensionWillBeInstalled(content::BrowserContext* browser_context, 175 void OnExtensionWillBeInstalled(content::BrowserContext* browser_context,
175 const extensions::Extension* extension, 176 const extensions::Extension* extension,
176 bool is_update, 177 bool is_update,
177 const std::string& old_name) override { 178 const std::string& old_name) override {
178 if (extension->is_theme()) { 179 if (extension->is_theme()) {
179 // The theme may be initially disabled. Wait till it is loaded (if ever). 180 // Remember ID of the newly installed theme.
180 theme_service_->installed_pending_load_id_ = extension->id(); 181 theme_service_->installed_pending_load_id_ = extension->id();
181 } 182 }
182 } 183 }
183 184
184 void OnExtensionLoaded(content::BrowserContext* browser_context, 185 void OnExtensionLoaded(content::BrowserContext* browser_context,
185 const extensions::Extension* extension) override { 186 const extensions::Extension* extension) override {
186 if (extension->is_theme() && 187 if (!extension->is_theme())
188 return;
189
190 bool is_new_version =
187 theme_service_->installed_pending_load_id_ != kDefaultThemeID && 191 theme_service_->installed_pending_load_id_ != kDefaultThemeID &&
188 theme_service_->installed_pending_load_id_ == extension->id()) { 192 theme_service_->installed_pending_load_id_ == extension->id();
189 theme_service_->SetTheme(extension);
190 }
191 theme_service_->installed_pending_load_id_ = kDefaultThemeID; 193 theme_service_->installed_pending_load_id_ = kDefaultThemeID;
194
195 // Do not load already loaded theme.
196 if (!is_new_version && extension->id() == theme_service_->GetThemeID())
197 return;
198
199 // Set the new theme during extension load:
200 // This includes: a) installing a new theme, b) enabling a disabled theme.
201 // We shouldn't get here for the update of a disabled theme.
202 theme_service_->SetTheme(extension);
192 } 203 }
193 204
194 void OnExtensionUnloaded( 205 void OnExtensionUnloaded(
195 content::BrowserContext* browser_context, 206 content::BrowserContext* browser_context,
196 const extensions::Extension* extension, 207 const extensions::Extension* extension,
197 extensions::UnloadedExtensionReason reason) override { 208 extensions::UnloadedExtensionReason reason) override {
198 if (reason != extensions::UnloadedExtensionReason::UPDATE && 209 if (reason != extensions::UnloadedExtensionReason::UPDATE &&
199 reason != extensions::UnloadedExtensionReason::LOCK_ALL && 210 reason != extensions::UnloadedExtensionReason::LOCK_ALL &&
200 extension->is_theme() && 211 extension->is_theme() &&
201 extension->id() == theme_service_->GetThemeID()) { 212 extension->id() == theme_service_->GetThemeID()) {
202 theme_service_->UseDefaultTheme(); 213 theme_service_->UseDefaultTheme();
203 } 214 }
204 } 215 }
205 216
206 ThemeService* theme_service_; 217 ThemeService* theme_service_;
218
219 ScopedObserver<extensions::ExtensionRegistry,
220 extensions::ExtensionRegistryObserver>
221 extension_registry_observer_;
222
223 DISALLOW_COPY_AND_ASSIGN(ThemeObserver);
207 }; 224 };
208 #endif // BUILDFLAG(ENABLE_EXTENSIONS) 225 #endif // BUILDFLAG(ENABLE_EXTENSIONS)
209 226
210 227
211 // ThemeService --------------------------------------------------------------- 228 // ThemeService ---------------------------------------------------------------
212 229
213 // The default theme if we haven't installed a theme yet or if we've clicked 230 // The default theme if we haven't installed a theme yet or if we've clicked
214 // the "Use Classic" button. 231 // the "Use Classic" button.
215 const char ThemeService::kDefaultThemeID[] = ""; 232 const char ThemeService::kDefaultThemeID[] = "";
216 233
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 const content::NotificationSource& source, 269 const content::NotificationSource& source,
253 const content::NotificationDetails& details) { 270 const content::NotificationDetails& details) {
254 using content::Details; 271 using content::Details;
255 switch (type) { 272 switch (type) {
256 case extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED: 273 case extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED:
257 registrar_.Remove(this, 274 registrar_.Remove(this,
258 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED, 275 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED,
259 content::Source<Profile>(profile_)); 276 content::Source<Profile>(profile_));
260 OnExtensionServiceReady(); 277 OnExtensionServiceReady();
261 break; 278 break;
262 case extensions::NOTIFICATION_EXTENSION_ENABLED: {
263 const Extension* extension = Details<const Extension>(details).ptr();
264 if (extension->is_theme())
265 SetTheme(extension);
266 break;
267 }
268 default: 279 default:
269 NOTREACHED(); 280 NOTREACHED();
270 } 281 }
271 } 282 }
272 283
273 void ThemeService::SetTheme(const Extension* extension) { 284 void ThemeService::SetTheme(const Extension* extension) {
274 DCHECK(extension->is_theme()); 285 DCHECK(extension->is_theme());
275 ExtensionService* service = 286 ExtensionService* service =
276 extensions::ExtensionSystem::Get(profile_)->extension_service(); 287 extensions::ExtensionSystem::Get(profile_)->extension_service();
277 if (!service->IsExtensionEnabled(extension->id())) { 288 if (!service->IsExtensionEnabled(extension->id())) {
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 // be recreated from the extension. 796 // be recreated from the extension.
786 MigrateTheme(); 797 MigrateTheme();
787 set_ready(); 798 set_ready();
788 799
789 // Send notification in case anyone requested data and cached it when the 800 // Send notification in case anyone requested data and cached it when the
790 // theme service was not ready yet. 801 // theme service was not ready yet.
791 NotifyThemeChanged(); 802 NotifyThemeChanged();
792 } 803 }
793 804
794 #if BUILDFLAG(ENABLE_EXTENSIONS) 805 #if BUILDFLAG(ENABLE_EXTENSIONS)
795 theme_observer_.reset(new ThemeObserver(this)); 806 theme_observer_ = base::MakeUnique<ThemeObserver>(this);
796 #endif 807 #endif
797 808
798 registrar_.Add(this,
799 extensions::NOTIFICATION_EXTENSION_ENABLED,
800 content::Source<Profile>(profile_));
801
802 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 809 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
803 FROM_HERE, base::Bind(&ThemeService::RemoveUnusedThemes, 810 FROM_HERE, base::Bind(&ThemeService::RemoveUnusedThemes,
804 weak_ptr_factory_.GetWeakPtr(), false), 811 weak_ptr_factory_.GetWeakPtr(), false),
805 base::TimeDelta::FromSeconds(kRemoveUnusedThemesStartupDelay)); 812 base::TimeDelta::FromSeconds(kRemoveUnusedThemesStartupDelay));
806 } 813 }
807 814
808 void ThemeService::MigrateTheme() { 815 void ThemeService::MigrateTheme() {
809 // TODO(erg): We need to pop up a dialog informing the user that their 816 // TODO(erg): We need to pop up a dialog informing the user that their
810 // theme is being migrated. 817 // theme is being migrated.
811 ExtensionService* service = 818 ExtensionService* service =
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 876
870 #if BUILDFLAG(ENABLE_SUPERVISED_USERS) 877 #if BUILDFLAG(ENABLE_SUPERVISED_USERS)
871 bool ThemeService::IsSupervisedUser() const { 878 bool ThemeService::IsSupervisedUser() const {
872 return profile_->IsSupervised(); 879 return profile_->IsSupervised();
873 } 880 }
874 881
875 void ThemeService::SetSupervisedUserTheme() { 882 void ThemeService::SetSupervisedUserTheme() {
876 SetCustomDefaultTheme(new SupervisedUserTheme); 883 SetCustomDefaultTheme(new SupervisedUserTheme);
877 } 884 }
878 #endif 885 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698