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

Side by Side Diff: chrome/browser/ui/webui/settings/appearance_handler.cc

Issue 1839293002: MD Settings: simplify logic for whether themes can be reset (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: simpler Created 4 years, 8 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
« no previous file with comments | « chrome/browser/ui/webui/settings/appearance_handler.h ('k') | no next file » | 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) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 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/ui/webui/settings/appearance_handler.h" 5 #include "chrome/browser/ui/webui/settings/appearance_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/chrome_notification_types.h" 10 #include "chrome/browser/chrome_notification_types.h"
(...skipping 25 matching lines...) Expand all
36 base::Bind(&AppearanceHandler::GetResetThemeEnabled, 36 base::Bind(&AppearanceHandler::GetResetThemeEnabled,
37 base::Unretained(this))); 37 base::Unretained(this)));
38 } 38 }
39 39
40 void AppearanceHandler::Observe( 40 void AppearanceHandler::Observe(
41 int type, 41 int type,
42 const content::NotificationSource& source, 42 const content::NotificationSource& source,
43 const content::NotificationDetails& details) { 43 const content::NotificationDetails& details) {
44 switch (type) { 44 switch (type) {
45 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: { 45 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: {
46 base::StringValue event("reset-theme-enabled-changed");
47 base::FundamentalValue enabled(QueryResetThemeEnabledState());
48 web_ui()->CallJavascriptFunction( 46 web_ui()->CallJavascriptFunction(
49 "cr.webUIListenerCallback", event, enabled); 47 "cr.webUIListenerCallback",
48 base::StringValue("reset-theme-enabled-changed"),
49 base::FundamentalValue(ResetThemeEnabled()));
50 break; 50 break;
51 } 51 }
52 default: 52 default:
53 NOTREACHED(); 53 NOTREACHED();
54 } 54 }
55 } 55 }
56 56
57 void AppearanceHandler::ResetTheme(const base::ListValue* /* args */) { 57 void AppearanceHandler::ResetTheme(const base::ListValue* /* args */) {
58 Profile* profile = Profile::FromWebUI(web_ui()); 58 ThemeServiceFactory::GetForProfile(profile_)->UseDefaultTheme();
59 ThemeServiceFactory::GetForProfile(profile)->UseDefaultTheme();
60 } 59 }
61 60
62 base::FundamentalValue AppearanceHandler::QueryResetThemeEnabledState() { 61 bool AppearanceHandler::ResetThemeEnabled() const {
63 ThemeService* theme_service = ThemeServiceFactory::GetForProfile(profile_);
64 bool is_system_theme = false;
65
66 // TODO(jhawkins): Handle native/system theme button. 62 // TODO(jhawkins): Handle native/system theme button.
67 63 return !ThemeServiceFactory::GetForProfile(profile_)->UsingDefaultTheme();
68 bool is_classic_theme = !is_system_theme &&
69 theme_service->UsingDefaultTheme();
70 return base::FundamentalValue(!is_classic_theme);
71 } 64 }
72 65
73 void AppearanceHandler::GetResetThemeEnabled(const base::ListValue* args) { 66 void AppearanceHandler::GetResetThemeEnabled(const base::ListValue* args) {
74 CHECK_EQ(1U, args->GetSize()); 67 CHECK_EQ(1U, args->GetSize());
75 const base::Value* callback_id; 68 const base::Value* callback_id;
76 CHECK(args->Get(0, &callback_id)); 69 CHECK(args->Get(0, &callback_id));
77 70
78 base::FundamentalValue enabled(QueryResetThemeEnabledState()); 71 ResolveJavascriptCallback(*callback_id,
79 ResolveJavascriptCallback(*callback_id, enabled); 72 base::FundamentalValue(ResetThemeEnabled()));
80 } 73 }
81 74
82 } // namespace settings 75 } // namespace settings
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/settings/appearance_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698