OLD | NEW |
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 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
13 #include "base/location.h" | 13 #include "base/location.h" |
14 #include "base/memory/ref_counted_memory.h" | 14 #include "base/memory/ref_counted_memory.h" |
| 15 #include "base/metrics/user_metrics.h" |
15 #include "base/sequenced_task_runner.h" | 16 #include "base/sequenced_task_runner.h" |
16 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
17 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
18 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
19 #include "base/threading/thread_task_runner_handle.h" | 20 #include "base/threading/thread_task_runner_handle.h" |
20 #include "build/build_config.h" | 21 #include "build/build_config.h" |
21 #include "chrome/browser/chrome_notification_types.h" | 22 #include "chrome/browser/chrome_notification_types.h" |
22 #include "chrome/browser/extensions/extension_service.h" | 23 #include "chrome/browser/extensions/extension_service.h" |
23 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/themes/browser_theme_pack.h" | 25 #include "chrome/browser/themes/browser_theme_pack.h" |
25 #include "chrome/browser/themes/custom_theme_supplier.h" | 26 #include "chrome/browser/themes/custom_theme_supplier.h" |
26 #include "chrome/browser/themes/theme_properties.h" | 27 #include "chrome/browser/themes/theme_properties.h" |
27 #include "chrome/browser/themes/theme_service_factory.h" | 28 #include "chrome/browser/themes/theme_service_factory.h" |
28 #include "chrome/browser/themes/theme_syncable_service.h" | 29 #include "chrome/browser/themes/theme_syncable_service.h" |
29 #include "chrome/common/chrome_constants.h" | 30 #include "chrome/common/chrome_constants.h" |
30 #include "chrome/common/features.h" | 31 #include "chrome/common/features.h" |
31 #include "chrome/common/pref_names.h" | 32 #include "chrome/common/pref_names.h" |
32 #include "chrome/grit/theme_resources.h" | 33 #include "chrome/grit/theme_resources.h" |
33 #include "components/grit/components_scaled_resources.h" | 34 #include "components/grit/components_scaled_resources.h" |
34 #include "components/prefs/pref_service.h" | 35 #include "components/prefs/pref_service.h" |
35 #include "content/public/browser/notification_service.h" | 36 #include "content/public/browser/notification_service.h" |
36 #include "content/public/browser/user_metrics.h" | |
37 #include "extensions/browser/extension_prefs.h" | 37 #include "extensions/browser/extension_prefs.h" |
38 #include "extensions/browser/extension_registry.h" | 38 #include "extensions/browser/extension_registry.h" |
39 #include "extensions/browser/extension_system.h" | 39 #include "extensions/browser/extension_system.h" |
40 #include "extensions/browser/uninstall_reason.h" | 40 #include "extensions/browser/uninstall_reason.h" |
41 #include "extensions/common/extension.h" | 41 #include "extensions/common/extension.h" |
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" |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 | 284 |
285 std::string previous_theme_id = GetThemeID(); | 285 std::string previous_theme_id = GetThemeID(); |
286 | 286 |
287 // Clear our image cache. | 287 // Clear our image cache. |
288 FreePlatformCaches(); | 288 FreePlatformCaches(); |
289 | 289 |
290 BuildFromExtension(extension); | 290 BuildFromExtension(extension); |
291 SaveThemeID(extension->id()); | 291 SaveThemeID(extension->id()); |
292 | 292 |
293 NotifyThemeChanged(); | 293 NotifyThemeChanged(); |
294 content::RecordAction(UserMetricsAction("Themes_Installed")); | 294 base::RecordAction(UserMetricsAction("Themes_Installed")); |
295 | 295 |
296 if (previous_theme_id != kDefaultThemeID && | 296 if (previous_theme_id != kDefaultThemeID && |
297 previous_theme_id != extension->id() && | 297 previous_theme_id != extension->id() && |
298 service->GetInstalledExtension(previous_theme_id)) { | 298 service->GetInstalledExtension(previous_theme_id)) { |
299 // Do not disable the previous theme if it is already uninstalled. Sending | 299 // Do not disable the previous theme if it is already uninstalled. Sending |
300 // NOTIFICATION_BROWSER_THEME_CHANGED causes the previous theme to be | 300 // NOTIFICATION_BROWSER_THEME_CHANGED causes the previous theme to be |
301 // uninstalled when the notification causes the remaining infobar to close | 301 // uninstalled when the notification causes the remaining infobar to close |
302 // and does not open any new infobars. See crbug.com/468280. | 302 // and does not open any new infobars. See crbug.com/468280. |
303 | 303 |
304 // Disable the old theme. | 304 // Disable the old theme. |
305 service->DisableExtension(previous_theme_id, | 305 service->DisableExtension(previous_theme_id, |
306 extensions::Extension::DISABLE_USER_ACTION); | 306 extensions::Extension::DISABLE_USER_ACTION); |
307 } | 307 } |
308 } | 308 } |
309 | 309 |
310 void ThemeService::UseDefaultTheme() { | 310 void ThemeService::UseDefaultTheme() { |
311 if (ready_) | 311 if (ready_) |
312 content::RecordAction(UserMetricsAction("Themes_Reset")); | 312 base::RecordAction(UserMetricsAction("Themes_Reset")); |
313 #if BUILDFLAG(ENABLE_SUPERVISED_USERS) | 313 #if BUILDFLAG(ENABLE_SUPERVISED_USERS) |
314 if (IsSupervisedUser()) { | 314 if (IsSupervisedUser()) { |
315 SetSupervisedUserTheme(); | 315 SetSupervisedUserTheme(); |
316 return; | 316 return; |
317 } | 317 } |
318 #endif | 318 #endif |
319 ClearAllThemeData(); | 319 ClearAllThemeData(); |
320 NotifyThemeChanged(); | 320 NotifyThemeChanged(); |
321 } | 321 } |
322 | 322 |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 // If we don't have a file pack, we're updating from an old version. | 579 // If we don't have a file pack, we're updating from an old version. |
580 base::FilePath path = prefs->GetFilePath(prefs::kCurrentThemePackFilename); | 580 base::FilePath path = prefs->GetFilePath(prefs::kCurrentThemePackFilename); |
581 if (path != base::FilePath()) { | 581 if (path != base::FilePath()) { |
582 path = path.Append(chrome::kThemePackFilename); | 582 path = path.Append(chrome::kThemePackFilename); |
583 SwapThemeSupplier(BrowserThemePack::BuildFromDataPack(path, current_id)); | 583 SwapThemeSupplier(BrowserThemePack::BuildFromDataPack(path, current_id)); |
584 if (theme_supplier_) | 584 if (theme_supplier_) |
585 loaded_pack = true; | 585 loaded_pack = true; |
586 } | 586 } |
587 | 587 |
588 if (loaded_pack) { | 588 if (loaded_pack) { |
589 content::RecordAction(UserMetricsAction("Themes.Loaded")); | 589 base::RecordAction(UserMetricsAction("Themes.Loaded")); |
590 set_ready(); | 590 set_ready(); |
591 } | 591 } |
592 // Else: wait for the extension service to be ready so that the theme pack | 592 // Else: wait for the extension service to be ready so that the theme pack |
593 // can be recreated from the extension. | 593 // can be recreated from the extension. |
594 } | 594 } |
595 | 595 |
596 void ThemeService::NotifyThemeChanged() { | 596 void ThemeService::NotifyThemeChanged() { |
597 if (!ready_) | 597 if (!ready_) |
598 return; | 598 return; |
599 | 599 |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
808 void ThemeService::MigrateTheme() { | 808 void ThemeService::MigrateTheme() { |
809 // TODO(erg): We need to pop up a dialog informing the user that their | 809 // TODO(erg): We need to pop up a dialog informing the user that their |
810 // theme is being migrated. | 810 // theme is being migrated. |
811 ExtensionService* service = | 811 ExtensionService* service = |
812 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 812 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
813 const Extension* extension = | 813 const Extension* extension = |
814 service ? service->GetExtensionById(GetThemeID(), false) : nullptr; | 814 service ? service->GetExtensionById(GetThemeID(), false) : nullptr; |
815 if (extension) { | 815 if (extension) { |
816 DLOG(ERROR) << "Migrating theme"; | 816 DLOG(ERROR) << "Migrating theme"; |
817 BuildFromExtension(extension); | 817 BuildFromExtension(extension); |
818 content::RecordAction(UserMetricsAction("Themes.Migrated")); | 818 base::RecordAction(UserMetricsAction("Themes.Migrated")); |
819 } else { | 819 } else { |
820 DLOG(ERROR) << "Theme is mysteriously gone."; | 820 DLOG(ERROR) << "Theme is mysteriously gone."; |
821 ClearAllThemeData(); | 821 ClearAllThemeData(); |
822 content::RecordAction(UserMetricsAction("Themes.Gone")); | 822 base::RecordAction(UserMetricsAction("Themes.Gone")); |
823 } | 823 } |
824 } | 824 } |
825 | 825 |
826 void ThemeService::SwapThemeSupplier( | 826 void ThemeService::SwapThemeSupplier( |
827 scoped_refptr<CustomThemeSupplier> theme_supplier) { | 827 scoped_refptr<CustomThemeSupplier> theme_supplier) { |
828 if (theme_supplier_) | 828 if (theme_supplier_) |
829 theme_supplier_->StopUsingTheme(); | 829 theme_supplier_->StopUsingTheme(); |
830 theme_supplier_ = theme_supplier; | 830 theme_supplier_ = theme_supplier; |
831 if (theme_supplier_) | 831 if (theme_supplier_) |
832 theme_supplier_->StartUsingTheme(); | 832 theme_supplier_->StartUsingTheme(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 | 869 |
870 #if BUILDFLAG(ENABLE_SUPERVISED_USERS) | 870 #if BUILDFLAG(ENABLE_SUPERVISED_USERS) |
871 bool ThemeService::IsSupervisedUser() const { | 871 bool ThemeService::IsSupervisedUser() const { |
872 return profile_->IsSupervised(); | 872 return profile_->IsSupervised(); |
873 } | 873 } |
874 | 874 |
875 void ThemeService::SetSupervisedUserTheme() { | 875 void ThemeService::SetSupervisedUserTheme() { |
876 SetCustomDefaultTheme(new SupervisedUserTheme); | 876 SetCustomDefaultTheme(new SupervisedUserTheme); |
877 } | 877 } |
878 #endif | 878 #endif |
OLD | NEW |