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

Side by Side Diff: chrome/browser/ui/webui/options2/chromeos/system_options_handler2.cc

Issue 8965070: Change system settings based on when mouse/touchpad is connected/disconnected. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: rebase Created 9 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/options2/chromeos/system_options_handler2.h" 5 #include "chrome/browser/ui/webui/options2/chromeos/system_options_handler2.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/json/json_value_serializer.h" 13 #include "base/json/json_value_serializer.h"
14 #include "base/string_number_conversions.h" 14 #include "base/string_number_conversions.h"
15 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "content/browser/tab_contents/tab_contents.h" 17 #include "content/browser/tab_contents/tab_contents.h"
18 #include "chrome/browser/browser_process.h" 18 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/chromeos/accessibility/accessibility_util.h" 19 #include "chrome/browser/chromeos/accessibility/accessibility_util.h"
20 #include "chrome/browser/chromeos/cros_settings.h" 20 #include "chrome/browser/chromeos/cros_settings.h"
21 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" 21 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h"
22 #include "chrome/browser/chromeos/dbus/power_manager_client.h" 22 #include "chrome/browser/chromeos/dbus/power_manager_client.h"
23 #include "chrome/browser/chromeos/language_preferences.h" 23 #include "chrome/browser/chromeos/language_preferences.h"
24 #include "chrome/browser/chromeos/system/input_device_settings.h" 24 #include "chrome/browser/chromeos/system/input_device_settings.h"
25 #include "chrome/browser/chromeos/xinput_hierarchy_changed_event_listener.h"
25 #include "chrome/browser/extensions/extension_service.h" 26 #include "chrome/browser/extensions/extension_service.h"
26 #include "chrome/browser/prefs/pref_service.h" 27 #include "chrome/browser/prefs/pref_service.h"
27 #include "chrome/browser/profiles/profile.h" 28 #include "chrome/browser/profiles/profile.h"
28 #include "chrome/browser/ui/webui/options2/chromeos/system_settings_provider2.h" 29 #include "chrome/browser/ui/webui/options2/chromeos/system_settings_provider2.h"
29 #include "chrome/common/chrome_switches.h" 30 #include "chrome/common/chrome_switches.h"
30 #include "chrome/common/pref_names.h" 31 #include "chrome/common/pref_names.h"
31 #include "chrome/common/extensions/extension.h" 32 #include "chrome/common/extensions/extension.h"
32 #include "grit/browser_resources.h" 33 #include "grit/browser_resources.h"
33 #include "grit/chromium_strings.h" 34 #include "grit/chromium_strings.h"
34 #include "grit/generated_resources.h" 35 #include "grit/generated_resources.h"
35 #include "grit/locale_settings.h" 36 #include "grit/locale_settings.h"
36 #include "grit/theme_resources.h" 37 #include "grit/theme_resources.h"
37 #include "ui/base/l10n/l10n_util.h" 38 #include "ui/base/l10n/l10n_util.h"
38 #include "ui/base/resource/resource_bundle.h" 39 #include "ui/base/resource/resource_bundle.h"
39 40
40 using content::BrowserThread; 41 using content::BrowserThread;
41 42
42 namespace { 43 namespace {
43 44
44 void TouchpadExistsFileThread(bool* exists) { 45 void TouchpadExistsFileThread(bool* exists) {
45 *exists = chromeos::system::touchpad_settings::TouchpadExists(); 46 *exists = chromeos::system::touchpad_settings::TouchpadExists();
46 } 47 }
47 48
49 void MouseExistsFileThread(bool* exists) {
50 *exists = chromeos::system::mouse_settings::MouseExists();
51 }
52
48 } // namespace 53 } // namespace
49 54
50 namespace options2 { 55 namespace options2 {
51 56
52 SystemOptionsHandler::SystemOptionsHandler() { 57 SystemOptionsHandler::SystemOptionsHandler() {
53 } 58 }
54 59
55 SystemOptionsHandler::~SystemOptionsHandler() { 60 SystemOptionsHandler::~SystemOptionsHandler() {
61 chromeos::XInputHierarchyChangedEventListener::GetInstance()
62 ->RemoveObserver(this);
56 } 63 }
57 64
58 void SystemOptionsHandler::GetLocalizedValues( 65 void SystemOptionsHandler::GetLocalizedValues(
59 DictionaryValue* localized_strings) { 66 DictionaryValue* localized_strings) {
60 DCHECK(localized_strings); 67 DCHECK(localized_strings);
61 68
62 RegisterTitle(localized_strings, "systemPage", IDS_OPTIONS_SYSTEM_TAB_LABEL); 69 RegisterTitle(localized_strings, "systemPage", IDS_OPTIONS_SYSTEM_TAB_LABEL);
63 localized_strings->SetString("datetimeTitle", 70 localized_strings->SetString("datetimeTitle",
64 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_SECTION_TITLE_DATETIME)); 71 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_SECTION_TITLE_DATETIME));
65 localized_strings->SetString("timezone", 72 localized_strings->SetString("timezone",
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 } 129 }
123 130
124 void SystemOptionsHandler::Initialize() { 131 void SystemOptionsHandler::Initialize() {
125 DCHECK(web_ui_); 132 DCHECK(web_ui_);
126 PrefService* pref_service = g_browser_process->local_state(); 133 PrefService* pref_service = g_browser_process->local_state();
127 bool acc_enabled = pref_service->GetBoolean(prefs::kSpokenFeedbackEnabled); 134 bool acc_enabled = pref_service->GetBoolean(prefs::kSpokenFeedbackEnabled);
128 base::FundamentalValue checked(acc_enabled); 135 base::FundamentalValue checked(acc_enabled);
129 web_ui_->CallJavascriptFunction( 136 web_ui_->CallJavascriptFunction(
130 "options.SystemOptions.SetAccessibilityCheckboxState", checked); 137 "options.SystemOptions.SetAccessibilityCheckboxState", checked);
131 138
139 chromeos::XInputHierarchyChangedEventListener::GetInstance()
140 ->AddObserver(this);
141 DeviceHierarchyChanged();
142 }
143
144 void SystemOptionsHandler::CheckTouchpadExists() {
132 bool* exists = new bool; 145 bool* exists = new bool;
133 BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE, 146 BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE,
134 base::Bind(&TouchpadExistsFileThread, exists), 147 base::Bind(&TouchpadExistsFileThread, exists),
135 base::Bind(&SystemOptionsHandler::TouchpadExists, AsWeakPtr(), exists)); 148 base::Bind(&SystemOptionsHandler::TouchpadExists, AsWeakPtr(), exists));
136 } 149 }
137 150
151 void SystemOptionsHandler::CheckMouseExists() {
152 bool* exists = new bool;
153 BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE,
154 base::Bind(&MouseExistsFileThread, exists),
155 base::Bind(&SystemOptionsHandler::MouseExists, AsWeakPtr(), exists));
156 }
157
138 void SystemOptionsHandler::TouchpadExists(bool* exists) { 158 void SystemOptionsHandler::TouchpadExists(bool* exists) {
139 if (*exists) 159 base::FundamentalValue val(*exists);
140 web_ui_->CallJavascriptFunction( 160 web_ui_->CallJavascriptFunction("options.SystemOptions.showTouchpadControls",
141 "options.SystemOptions.showTouchpadControls"); 161 val);
162 delete exists;
163 }
164
165 void SystemOptionsHandler::MouseExists(bool* exists) {
166 base::FundamentalValue val(*exists);
167 web_ui_->CallJavascriptFunction("options.SystemOptions.showMouseControls",
168 val);
142 delete exists; 169 delete exists;
143 } 170 }
144 171
145 void SystemOptionsHandler::RegisterMessages() { 172 void SystemOptionsHandler::RegisterMessages() {
146 DCHECK(web_ui_); 173 DCHECK(web_ui_);
147 web_ui_->RegisterMessageCallback("accessibilityChange", 174 web_ui_->RegisterMessageCallback("accessibilityChange",
148 base::Bind(&SystemOptionsHandler::AccessibilityChangeCallback, 175 base::Bind(&SystemOptionsHandler::AccessibilityChangeCallback,
149 base::Unretained(this))); 176 base::Unretained(this)));
150 177
151 web_ui_->RegisterMessageCallback("decreaseScreenBrightness", 178 web_ui_->RegisterMessageCallback("decreaseScreenBrightness",
152 base::Bind(&SystemOptionsHandler::DecreaseScreenBrightnessCallback, 179 base::Bind(&SystemOptionsHandler::DecreaseScreenBrightnessCallback,
153 base::Unretained(this))); 180 base::Unretained(this)));
154 web_ui_->RegisterMessageCallback("increaseScreenBrightness", 181 web_ui_->RegisterMessageCallback("increaseScreenBrightness",
155 base::Bind(&SystemOptionsHandler::IncreaseScreenBrightnessCallback, 182 base::Bind(&SystemOptionsHandler::IncreaseScreenBrightnessCallback,
156 base::Unretained(this))); 183 base::Unretained(this)));
157 } 184 }
158 185
186 void SystemOptionsHandler::DeviceHierarchyChanged() {
187 CheckMouseExists();
188 CheckTouchpadExists();
189 }
190
159 void SystemOptionsHandler::AccessibilityChangeCallback(const ListValue* args) { 191 void SystemOptionsHandler::AccessibilityChangeCallback(const ListValue* args) {
160 std::string checked_str; 192 std::string checked_str;
161 args->GetString(0, &checked_str); 193 args->GetString(0, &checked_str);
162 bool accessibility_enabled = (checked_str == "true"); 194 bool accessibility_enabled = (checked_str == "true");
163 195
164 chromeos::accessibility::EnableAccessibility(accessibility_enabled, NULL); 196 chromeos::accessibility::EnableAccessibility(accessibility_enabled, NULL);
165 } 197 }
166 198
167 void SystemOptionsHandler::DecreaseScreenBrightnessCallback( 199 void SystemOptionsHandler::DecreaseScreenBrightnessCallback(
168 const ListValue* args) { 200 const ListValue* args) {
169 // Do not allow the options button to turn off the backlight, as that 201 // Do not allow the options button to turn off the backlight, as that
170 // can make it very difficult to see the increase brightness button. 202 // can make it very difficult to see the increase brightness button.
171 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> 203 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->
172 DecreaseScreenBrightness(false); 204 DecreaseScreenBrightness(false);
173 } 205 }
174 206
175 void SystemOptionsHandler::IncreaseScreenBrightnessCallback( 207 void SystemOptionsHandler::IncreaseScreenBrightnessCallback(
176 const ListValue* args) { 208 const ListValue* args) {
177 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> 209 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->
178 IncreaseScreenBrightness(); 210 IncreaseScreenBrightness();
179 } 211 }
180 212
181 } // namespace options2 213 } // namespace options2
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options2/chromeos/system_options_handler2.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698