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

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

Issue 2468723003: Move session service and supervised users to buildflags. (Closed)
Patch Set: Created 4 years, 1 month 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
« no previous file with comments | « chrome/browser/themes/theme_service.h ('k') | chrome/browser/themes/theme_service_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/memory/ref_counted_memory.h" 13 #include "base/memory/ref_counted_memory.h"
14 #include "base/sequenced_task_runner.h" 14 #include "base/sequenced_task_runner.h"
15 #include "base/single_thread_task_runner.h" 15 #include "base/single_thread_task_runner.h"
16 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
17 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
18 #include "base/threading/thread_task_runner_handle.h" 18 #include "base/threading/thread_task_runner_handle.h"
19 #include "build/build_config.h" 19 #include "build/build_config.h"
20 #include "chrome/browser/chrome_notification_types.h" 20 #include "chrome/browser/chrome_notification_types.h"
21 #include "chrome/browser/extensions/extension_service.h" 21 #include "chrome/browser/extensions/extension_service.h"
22 #include "chrome/browser/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/browser/themes/browser_theme_pack.h" 23 #include "chrome/browser/themes/browser_theme_pack.h"
24 #include "chrome/browser/themes/custom_theme_supplier.h" 24 #include "chrome/browser/themes/custom_theme_supplier.h"
25 #include "chrome/browser/themes/theme_properties.h" 25 #include "chrome/browser/themes/theme_properties.h"
26 #include "chrome/browser/themes/theme_service_factory.h" 26 #include "chrome/browser/themes/theme_service_factory.h"
27 #include "chrome/browser/themes/theme_syncable_service.h" 27 #include "chrome/browser/themes/theme_syncable_service.h"
28 #include "chrome/common/chrome_constants.h" 28 #include "chrome/common/chrome_constants.h"
29 #include "chrome/common/features.h"
29 #include "chrome/common/pref_names.h" 30 #include "chrome/common/pref_names.h"
30 #include "chrome/grit/theme_resources.h" 31 #include "chrome/grit/theme_resources.h"
31 #include "components/grit/components_scaled_resources.h" 32 #include "components/grit/components_scaled_resources.h"
32 #include "components/prefs/pref_service.h" 33 #include "components/prefs/pref_service.h"
33 #include "content/public/browser/notification_service.h" 34 #include "content/public/browser/notification_service.h"
34 #include "content/public/browser/user_metrics.h" 35 #include "content/public/browser/user_metrics.h"
35 #include "extensions/browser/extension_prefs.h" 36 #include "extensions/browser/extension_prefs.h"
36 #include "extensions/browser/extension_registry.h" 37 #include "extensions/browser/extension_registry.h"
37 #include "extensions/browser/extension_system.h" 38 #include "extensions/browser/extension_system.h"
38 #include "extensions/browser/uninstall_reason.h" 39 #include "extensions/browser/uninstall_reason.h"
39 #include "extensions/common/extension.h" 40 #include "extensions/common/extension.h"
40 #include "extensions/common/extension_set.h" 41 #include "extensions/common/extension_set.h"
41 #include "ui/base/layout.h" 42 #include "ui/base/layout.h"
42 #include "ui/base/material_design/material_design_controller.h" 43 #include "ui/base/material_design/material_design_controller.h"
43 #include "ui/base/resource/resource_bundle.h" 44 #include "ui/base/resource/resource_bundle.h"
44 #include "ui/gfx/color_palette.h" 45 #include "ui/gfx/color_palette.h"
45 #include "ui/gfx/image/image_skia.h" 46 #include "ui/gfx/image/image_skia.h"
46 #include "ui/native_theme/common_theme.h" 47 #include "ui/native_theme/common_theme.h"
47 #include "ui/native_theme/native_theme.h" 48 #include "ui/native_theme/native_theme.h"
48 49
49 #if defined(ENABLE_EXTENSIONS) 50 #if defined(ENABLE_EXTENSIONS)
50 #include "extensions/browser/extension_registry_observer.h" 51 #include "extensions/browser/extension_registry_observer.h"
51 #endif 52 #endif
52 53
53 #if defined(ENABLE_SUPERVISED_USERS) 54 #if BUILDFLAG(ENABLE_SUPERVISED_USERS)
54 #include "chrome/browser/supervised_user/supervised_user_theme.h" 55 #include "chrome/browser/supervised_user/supervised_user_theme.h"
55 #endif 56 #endif
56 57
57 using base::UserMetricsAction; 58 using base::UserMetricsAction;
58 using content::BrowserThread; 59 using content::BrowserThread;
59 using extensions::Extension; 60 using extensions::Extension;
60 using extensions::UnloadedExtensionInfo; 61 using extensions::UnloadedExtensionInfo;
61 using ui::ResourceBundle; 62 using ui::ResourceBundle;
62 63
63 64
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 295
295 // Disable the old theme. 296 // Disable the old theme.
296 service->DisableExtension(previous_theme_id, 297 service->DisableExtension(previous_theme_id,
297 extensions::Extension::DISABLE_USER_ACTION); 298 extensions::Extension::DISABLE_USER_ACTION);
298 } 299 }
299 } 300 }
300 301
301 void ThemeService::UseDefaultTheme() { 302 void ThemeService::UseDefaultTheme() {
302 if (ready_) 303 if (ready_)
303 content::RecordAction(UserMetricsAction("Themes_Reset")); 304 content::RecordAction(UserMetricsAction("Themes_Reset"));
304 #if defined(ENABLE_SUPERVISED_USERS) 305 #if BUILDFLAG(ENABLE_SUPERVISED_USERS)
305 if (IsSupervisedUser()) { 306 if (IsSupervisedUser()) {
306 SetSupervisedUserTheme(); 307 SetSupervisedUserTheme();
307 return; 308 return;
308 } 309 }
309 #endif 310 #endif
310 ClearAllThemeData(); 311 ClearAllThemeData();
311 NotifyThemeChanged(); 312 NotifyThemeChanged();
312 } 313 }
313 314
314 void ThemeService::UseSystemTheme() { 315 void ThemeService::UseSystemTheme() {
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 case ThemeProperties::COLOR_TAB_THROBBER_SPINNING: 492 case ThemeProperties::COLOR_TAB_THROBBER_SPINNING:
492 case ThemeProperties::COLOR_TAB_THROBBER_WAITING: { 493 case ThemeProperties::COLOR_TAB_THROBBER_WAITING: {
493 SkColor base_color = 494 SkColor base_color =
494 ui::GetAuraColor(id == ThemeProperties::COLOR_TAB_THROBBER_SPINNING 495 ui::GetAuraColor(id == ThemeProperties::COLOR_TAB_THROBBER_SPINNING
495 ? ui::NativeTheme::kColorId_ThrobberSpinningColor 496 ? ui::NativeTheme::kColorId_ThrobberSpinningColor
496 : ui::NativeTheme::kColorId_ThrobberWaitingColor, 497 : ui::NativeTheme::kColorId_ThrobberWaitingColor,
497 nullptr); 498 nullptr);
498 color_utils::HSL hsl = GetTint(ThemeProperties::TINT_BUTTONS, incognito); 499 color_utils::HSL hsl = GetTint(ThemeProperties::TINT_BUTTONS, incognito);
499 return color_utils::HSLShift(base_color, hsl); 500 return color_utils::HSLShift(base_color, hsl);
500 } 501 }
501 #if defined(ENABLE_SUPERVISED_USERS) 502 #if BUILDFLAG(ENABLE_SUPERVISED_USERS)
502 case ThemeProperties::COLOR_SUPERVISED_USER_LABEL: 503 case ThemeProperties::COLOR_SUPERVISED_USER_LABEL:
503 return color_utils::GetReadableColor( 504 return color_utils::GetReadableColor(
504 SK_ColorWHITE, GetColor(kLabelBackground, incognito)); 505 SK_ColorWHITE, GetColor(kLabelBackground, incognito));
505 case ThemeProperties::COLOR_SUPERVISED_USER_LABEL_BACKGROUND: 506 case ThemeProperties::COLOR_SUPERVISED_USER_LABEL_BACKGROUND:
506 return color_utils::BlendTowardOppositeLuma( 507 return color_utils::BlendTowardOppositeLuma(
507 GetColor(ThemeProperties::COLOR_FRAME, incognito), 0x80); 508 GetColor(ThemeProperties::COLOR_FRAME, incognito), 0x80);
508 case ThemeProperties::COLOR_SUPERVISED_USER_LABEL_BORDER: 509 case ThemeProperties::COLOR_SUPERVISED_USER_LABEL_BORDER:
509 return color_utils::AlphaBlend(GetColor(kLabelBackground, incognito), 510 return color_utils::AlphaBlend(GetColor(kLabelBackground, incognito),
510 SK_ColorBLACK, 230); 511 SK_ColorBLACK, 230);
511 #endif 512 #endif
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 base::ThreadTaskRunnerHandle::Get()->PostTask( 549 base::ThreadTaskRunnerHandle::Get()->PostTask(
549 FROM_HERE, base::Bind(&ThemeService::RemoveUnusedThemes, 550 FROM_HERE, base::Bind(&ThemeService::RemoveUnusedThemes,
550 weak_ptr_factory_.GetWeakPtr(), true)); 551 weak_ptr_factory_.GetWeakPtr(), true));
551 } 552 }
552 553
553 void ThemeService::LoadThemePrefs() { 554 void ThemeService::LoadThemePrefs() {
554 PrefService* prefs = profile_->GetPrefs(); 555 PrefService* prefs = profile_->GetPrefs();
555 556
556 std::string current_id = GetThemeID(); 557 std::string current_id = GetThemeID();
557 if (current_id == kDefaultThemeID) { 558 if (current_id == kDefaultThemeID) {
558 #if defined(ENABLE_SUPERVISED_USERS) 559 #if BUILDFLAG(ENABLE_SUPERVISED_USERS)
559 // Supervised users have a different default theme. 560 // Supervised users have a different default theme.
560 if (IsSupervisedUser()) { 561 if (IsSupervisedUser()) {
561 SetSupervisedUserTheme(); 562 SetSupervisedUserTheme();
562 set_ready(); 563 set_ready();
563 return; 564 return;
564 } 565 }
565 #endif 566 #endif
566 if (ShouldInitWithSystemTheme()) 567 if (ShouldInitWithSystemTheme())
567 UseSystemTheme(); 568 UseSystemTheme();
568 else 569 else
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 service->GetFileTaskRunner()->PostTask( 865 service->GetFileTaskRunner()->PostTask(
865 FROM_HERE, 866 FROM_HERE,
866 base::Bind(&WritePackToDiskCallback, base::RetainedRef(pack), pack_path)); 867 base::Bind(&WritePackToDiskCallback, base::RetainedRef(pack), pack_path));
867 868
868 // Save only the extension path. The packed file which matches the 869 // Save only the extension path. The packed file which matches the
869 // MaterialDesignController::Mode will be loaded via LoadThemePrefs(). 870 // MaterialDesignController::Mode will be loaded via LoadThemePrefs().
870 SavePackName(extension->path()); 871 SavePackName(extension->path());
871 SwapThemeSupplier(pack); 872 SwapThemeSupplier(pack);
872 } 873 }
873 874
874 #if defined(ENABLE_SUPERVISED_USERS) 875 #if BUILDFLAG(ENABLE_SUPERVISED_USERS)
875 bool ThemeService::IsSupervisedUser() const { 876 bool ThemeService::IsSupervisedUser() const {
876 return profile_->IsSupervised(); 877 return profile_->IsSupervised();
877 } 878 }
878 879
879 void ThemeService::SetSupervisedUserTheme() { 880 void ThemeService::SetSupervisedUserTheme() {
880 SetCustomDefaultTheme(new SupervisedUserTheme); 881 SetCustomDefaultTheme(new SupervisedUserTheme);
881 } 882 }
882 #endif 883 #endif
OLDNEW
« no previous file with comments | « chrome/browser/themes/theme_service.h ('k') | chrome/browser/themes/theme_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698