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

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

Issue 2893693002: Remove NOTIFICATION_EXTENSION_ENABLED. (Closed)
Patch Set: address comments + fix theme update path for skipping already set theme 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 // If this theme is a new version, we will use it.
191 bool is_new_version =
187 theme_service_->installed_pending_load_id_ != kDefaultThemeID && 192 theme_service_->installed_pending_load_id_ != kDefaultThemeID &&
188 theme_service_->installed_pending_load_id_ == extension->id()) { 193 theme_service_->installed_pending_load_id_ == extension->id();
189 theme_service_->SetTheme(extension);
190 }
191 theme_service_->installed_pending_load_id_ = kDefaultThemeID; 194 theme_service_->installed_pending_load_id_ = kDefaultThemeID;
195
196 // Do not load existing theme.
pkotwicz 2017/05/31 21:54:06 Perhaps clarify in the comment that SetTheme() sho
lazyboy 2017/05/31 23:31:56 I've removed the comment on line 190, added commen
197 if (!is_new_version && extension->id() == theme_service_->GetThemeID())
198 return;
199
200 // Set the new theme during extension load.
201 // Even if the theme was an update of a disabled extension, it shouldn't be
202 // loaded.
203 theme_service_->SetTheme(extension);
192 } 204 }
193 205
194 void OnExtensionUnloaded( 206 void OnExtensionUnloaded(
195 content::BrowserContext* browser_context, 207 content::BrowserContext* browser_context,
196 const extensions::Extension* extension, 208 const extensions::Extension* extension,
197 extensions::UnloadedExtensionReason reason) override { 209 extensions::UnloadedExtensionReason reason) override {
198 if (reason != extensions::UnloadedExtensionReason::UPDATE && 210 if (reason != extensions::UnloadedExtensionReason::UPDATE &&
199 reason != extensions::UnloadedExtensionReason::LOCK_ALL && 211 reason != extensions::UnloadedExtensionReason::LOCK_ALL &&
200 extension->is_theme() && 212 extension->is_theme() &&
201 extension->id() == theme_service_->GetThemeID()) { 213 extension->id() == theme_service_->GetThemeID()) {
202 theme_service_->UseDefaultTheme(); 214 theme_service_->UseDefaultTheme();
203 } 215 }
204 } 216 }
205 217
206 ThemeService* theme_service_; 218 ThemeService* theme_service_;
219
220 ScopedObserver<extensions::ExtensionRegistry,
221 extensions::ExtensionRegistryObserver>
222 extension_registry_observer_;
223
224 DISALLOW_COPY_AND_ASSIGN(ThemeObserver);
207 }; 225 };
208 #endif // BUILDFLAG(ENABLE_EXTENSIONS) 226 #endif // BUILDFLAG(ENABLE_EXTENSIONS)
209 227
210 228
211 // ThemeService --------------------------------------------------------------- 229 // ThemeService ---------------------------------------------------------------
212 230
213 // The default theme if we haven't installed a theme yet or if we've clicked 231 // The default theme if we haven't installed a theme yet or if we've clicked
214 // the "Use Classic" button. 232 // the "Use Classic" button.
215 const char ThemeService::kDefaultThemeID[] = ""; 233 const char ThemeService::kDefaultThemeID[] = "";
216 234
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 const content::NotificationSource& source, 270 const content::NotificationSource& source,
253 const content::NotificationDetails& details) { 271 const content::NotificationDetails& details) {
254 using content::Details; 272 using content::Details;
255 switch (type) { 273 switch (type) {
256 case extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED: 274 case extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED:
257 registrar_.Remove(this, 275 registrar_.Remove(this,
258 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED, 276 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED,
259 content::Source<Profile>(profile_)); 277 content::Source<Profile>(profile_));
260 OnExtensionServiceReady(); 278 OnExtensionServiceReady();
261 break; 279 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: 280 default:
269 NOTREACHED(); 281 NOTREACHED();
270 } 282 }
271 } 283 }
272 284
273 void ThemeService::SetTheme(const Extension* extension) { 285 void ThemeService::SetTheme(const Extension* extension) {
274 DCHECK(extension->is_theme()); 286 DCHECK(extension->is_theme());
275 ExtensionService* service = 287 ExtensionService* service =
276 extensions::ExtensionSystem::Get(profile_)->extension_service(); 288 extensions::ExtensionSystem::Get(profile_)->extension_service();
277 if (!service->IsExtensionEnabled(extension->id())) { 289 if (!service->IsExtensionEnabled(extension->id())) {
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 // be recreated from the extension. 797 // be recreated from the extension.
786 MigrateTheme(); 798 MigrateTheme();
787 set_ready(); 799 set_ready();
788 800
789 // Send notification in case anyone requested data and cached it when the 801 // Send notification in case anyone requested data and cached it when the
790 // theme service was not ready yet. 802 // theme service was not ready yet.
791 NotifyThemeChanged(); 803 NotifyThemeChanged();
792 } 804 }
793 805
794 #if BUILDFLAG(ENABLE_EXTENSIONS) 806 #if BUILDFLAG(ENABLE_EXTENSIONS)
795 theme_observer_.reset(new ThemeObserver(this)); 807 theme_observer_ = base::MakeUnique<ThemeObserver>(this);
796 #endif 808 #endif
797 809
798 registrar_.Add(this,
799 extensions::NOTIFICATION_EXTENSION_ENABLED,
800 content::Source<Profile>(profile_));
801
802 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 810 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
803 FROM_HERE, base::Bind(&ThemeService::RemoveUnusedThemes, 811 FROM_HERE, base::Bind(&ThemeService::RemoveUnusedThemes,
804 weak_ptr_factory_.GetWeakPtr(), false), 812 weak_ptr_factory_.GetWeakPtr(), false),
805 base::TimeDelta::FromSeconds(kRemoveUnusedThemesStartupDelay)); 813 base::TimeDelta::FromSeconds(kRemoveUnusedThemesStartupDelay));
806 } 814 }
807 815
808 void ThemeService::MigrateTheme() { 816 void ThemeService::MigrateTheme() {
809 // TODO(erg): We need to pop up a dialog informing the user that their 817 // TODO(erg): We need to pop up a dialog informing the user that their
810 // theme is being migrated. 818 // theme is being migrated.
811 ExtensionService* service = 819 ExtensionService* service =
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 877
870 #if BUILDFLAG(ENABLE_SUPERVISED_USERS) 878 #if BUILDFLAG(ENABLE_SUPERVISED_USERS)
871 bool ThemeService::IsSupervisedUser() const { 879 bool ThemeService::IsSupervisedUser() const {
872 return profile_->IsSupervised(); 880 return profile_->IsSupervised();
873 } 881 }
874 882
875 void ThemeService::SetSupervisedUserTheme() { 883 void ThemeService::SetSupervisedUserTheme() {
876 SetCustomDefaultTheme(new SupervisedUserTheme); 884 SetCustomDefaultTheme(new SupervisedUserTheme);
877 } 885 }
878 #endif 886 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698