Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 26 matching lines...) Expand all Loading... | |
| 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"); | 46 base::StringValue event("reset-theme-enabled-changed"); |
| 47 base::FundamentalValue enabled(QueryResetThemeEnabledState()); | 47 base::FundamentalValue enabled(ResetThemeEnabled()); |
| 48 web_ui()->CallJavascriptFunction( | 48 web_ui()->CallJavascriptFunction( |
| 49 "cr.webUIListenerCallback", event, enabled); | 49 "cr.webUIListenerCallback", event, enabled); |
| 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 Profile* profile = Profile::FromWebUI(web_ui()); |
|
dpapad
2016/03/30 17:15:26
Nit(optional): Unnecessary local var, since profil
Dan Beam
2016/03/30 23:22:37
Done.
| |
| 59 ThemeServiceFactory::GetForProfile(profile)->UseDefaultTheme(); | 59 ThemeServiceFactory::GetForProfile(profile)->UseDefaultTheme(); |
| 60 } | 60 } |
| 61 | 61 |
| 62 base::FundamentalValue AppearanceHandler::QueryResetThemeEnabledState() { | 62 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. | 63 // TODO(jhawkins): Handle native/system theme button. |
| 67 | 64 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 } | 65 } |
| 72 | 66 |
| 73 void AppearanceHandler::GetResetThemeEnabled(const base::ListValue* args) { | 67 void AppearanceHandler::GetResetThemeEnabled(const base::ListValue* args) { |
| 74 CHECK_EQ(1U, args->GetSize()); | 68 CHECK_EQ(1U, args->GetSize()); |
| 75 const base::Value* callback_id; | 69 const base::Value* callback_id; |
| 76 CHECK(args->Get(0, &callback_id)); | 70 CHECK(args->Get(0, &callback_id)); |
| 77 | 71 |
| 78 base::FundamentalValue enabled(QueryResetThemeEnabledState()); | 72 base::FundamentalValue enabled(ResetThemeEnabled()); |
| 79 ResolveJavascriptCallback(*callback_id, enabled); | 73 ResolveJavascriptCallback(*callback_id, enabled); |
|
dpapad
2016/03/30 17:15:26
Nit(optional): Maybe Inline local var.
ResolveJav
Dan Beam
2016/03/30 23:22:37
Done.
| |
| 80 } | 74 } |
| 81 | 75 |
| 82 } // namespace settings | 76 } // namespace settings |
| OLD | NEW |