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/chromeos/system/input_device_settings.h" | 5 #include "chrome/browser/chromeos/system/input_device_settings.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 15 matching lines...) Expand all Loading... | |
26 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
27 | 27 |
28 namespace chromeos { | 28 namespace chromeos { |
29 namespace system { | 29 namespace system { |
30 | 30 |
31 namespace { | 31 namespace { |
32 | 32 |
33 InputDeviceSettings* g_instance_; | 33 InputDeviceSettings* g_instance_; |
34 InputDeviceSettings* g_test_instance_; | 34 InputDeviceSettings* g_test_instance_; |
35 | 35 |
36 const char kTpControl[] = "/opt/google/touchpad/tpcontrol"; | 36 const char kTouchpad[] = "touchpad"; |
achuithb
2014/03/27 00:18:49
kDeviceTypeTouchpad
denniskempin (chromium)
2014/03/27 17:36:58
Done.
| |
37 const char kMouseControl[] = "/opt/google/mouse/mousecontrol"; | 37 const char kMouse[] = "mouse"; |
achuithb
2014/03/27 00:18:49
kDeviceTypeMouse
denniskempin (chromium)
2014/03/27 17:36:58
Done.
| |
38 const char kInputControl[] = "/opt/google/input/inputcontrol"; | |
38 | 39 |
39 const char kRemoraRequisition[] = "remora"; | 40 const char kRemoraRequisition[] = "remora"; |
40 | 41 |
41 typedef base::RefCountedData<bool> RefCountedBool; | 42 typedef base::RefCountedData<bool> RefCountedBool; |
42 | 43 |
43 bool ScriptExists(const std::string& script) { | 44 bool ScriptExists(const std::string& script) { |
44 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | 45 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
45 return base::PathExists(base::FilePath(script)); | 46 return base::PathExists(base::FilePath(script)); |
46 } | 47 } |
47 | 48 |
(...skipping 26 matching lines...) Expand all Loading... | |
74 // Control scripts can take long enough to cause SIGART during shutdown | 75 // Control scripts can take long enough to cause SIGART during shutdown |
75 // (http://crbug.com/261426). Run the blocking pool task with | 76 // (http://crbug.com/261426). Run the blocking pool task with |
76 // CONTINUE_ON_SHUTDOWN so it won't be joined when Chrome shuts down. | 77 // CONTINUE_ON_SHUTDOWN so it won't be joined when Chrome shuts down. |
77 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool(); | 78 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool(); |
78 scoped_refptr<base::TaskRunner> runner = | 79 scoped_refptr<base::TaskRunner> runner = |
79 pool->GetTaskRunnerWithShutdownBehavior( | 80 pool->GetTaskRunnerWithShutdownBehavior( |
80 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); | 81 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); |
81 runner->PostTask(FROM_HERE, base::Bind(&ExecuteScriptOnFileThread, argv)); | 82 runner->PostTask(FROM_HERE, base::Bind(&ExecuteScriptOnFileThread, argv)); |
82 } | 83 } |
83 | 84 |
84 void AddSensitivityArguments(int value, std::vector<std::string>* argv) { | 85 void AddSensitivityArguments(const char* type, int value, |
achuithb
2014/03/27 00:18:49
type is too general - let's call this device_type.
denniskempin (chromium)
2014/03/27 17:36:58
Done.
| |
86 std::vector<std::string>* argv) { | |
85 DCHECK(value >= kMinPointerSensitivity && value <= kMaxPointerSensitivity); | 87 DCHECK(value >= kMinPointerSensitivity && value <= kMaxPointerSensitivity); |
86 argv->push_back("sensitivity"); | 88 argv->push_back(base::StringPrintf("--%s_sensitivity=%d", type, value)); |
87 argv->push_back(base::StringPrintf("%d", value)); | |
88 } | 89 } |
89 | 90 |
90 void AddTPControlArguments(const char* control, | 91 void AddTPControlArguments(const char* control, |
91 bool enabled, | 92 bool enabled, |
92 std::vector<std::string>* argv) { | 93 std::vector<std::string>* argv) { |
93 argv->push_back(control); | 94 argv->push_back(base::StringPrintf("--%s=%d", control, enabled ? 1 : 0)); |
94 argv->push_back(enabled ? "on" : "off"); | |
95 } | 95 } |
96 | 96 |
97 void DeviceExistsBlockingPool(const char* script, | 97 void DeviceExistsBlockingPool(const char* type, |
achuithb
2014/03/27 00:18:49
device_type
denniskempin (chromium)
2014/03/27 17:36:58
Done.
| |
98 scoped_refptr<RefCountedBool> exists) { | 98 scoped_refptr<RefCountedBool> exists) { |
99 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | 99 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
100 exists->data = false; | 100 exists->data = false; |
101 if (!ScriptExists(script)) | 101 if (!ScriptExists(kInputControl)) |
102 return; | 102 return; |
103 | 103 |
104 std::vector<std::string> argv; | 104 std::vector<std::string> argv; |
105 argv.push_back(script); | 105 argv.push_back(kInputControl); |
106 argv.push_back("status"); | 106 argv.push_back(base::StringPrintf("--type=%s", type)); |
107 argv.push_back("--list"); | |
107 std::string output; | 108 std::string output; |
108 // Output is empty if the device is not found. | 109 // Output is empty if the device is not found. |
109 exists->data = base::GetAppOutput(CommandLine(argv), &output) && | 110 exists->data = base::GetAppOutput(CommandLine(argv), &output) && |
110 !output.empty(); | 111 !output.empty(); |
111 DVLOG(1) << "DeviceExistsBlockingPool:" << script << "=" << exists->data; | 112 DVLOG(1) << "DeviceExistsBlockingPool:" << type << "=" << exists->data; |
112 } | 113 } |
113 | 114 |
114 void RunCallbackUIThread( | 115 void RunCallbackUIThread( |
115 scoped_refptr<RefCountedBool> exists, | 116 scoped_refptr<RefCountedBool> exists, |
116 const InputDeviceSettings::DeviceExistsCallback& callback) { | 117 const InputDeviceSettings::DeviceExistsCallback& callback) { |
117 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 118 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
118 DVLOG(1) << "RunCallbackUIThread " << exists->data; | 119 DVLOG(1) << "RunCallbackUIThread " << exists->data; |
119 callback.Run(exists->data); | 120 callback.Run(exists->data); |
120 } | 121 } |
121 | 122 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
161 TouchpadSettings current_touchpad_settings_; | 162 TouchpadSettings current_touchpad_settings_; |
162 MouseSettings current_mouse_settings_; | 163 MouseSettings current_mouse_settings_; |
163 | 164 |
164 DISALLOW_COPY_AND_ASSIGN(InputDeviceSettingsImpl); | 165 DISALLOW_COPY_AND_ASSIGN(InputDeviceSettingsImpl); |
165 }; | 166 }; |
166 | 167 |
167 InputDeviceSettingsImpl::InputDeviceSettingsImpl() {} | 168 InputDeviceSettingsImpl::InputDeviceSettingsImpl() {} |
168 | 169 |
169 void InputDeviceSettingsImpl::TouchpadExists( | 170 void InputDeviceSettingsImpl::TouchpadExists( |
170 const DeviceExistsCallback& callback) { | 171 const DeviceExistsCallback& callback) { |
171 DeviceExists(kTpControl, callback); | 172 DeviceExists(kTouchpad, callback); |
172 } | 173 } |
173 | 174 |
174 void InputDeviceSettingsImpl::UpdateTouchpadSettings( | 175 void InputDeviceSettingsImpl::UpdateTouchpadSettings( |
175 const TouchpadSettings& settings) { | 176 const TouchpadSettings& settings) { |
176 std::vector<std::string> argv; | 177 std::vector<std::string> argv; |
177 if (current_touchpad_settings_.Update(settings, &argv)) | 178 if (current_touchpad_settings_.Update(settings, &argv)) |
178 ExecuteScript(argv); | 179 ExecuteScript(argv); |
179 } | 180 } |
180 | 181 |
181 void InputDeviceSettingsImpl::SetTouchpadSensitivity(int value) { | 182 void InputDeviceSettingsImpl::SetTouchpadSensitivity(int value) { |
(...skipping 17 matching lines...) Expand all Loading... | |
199 | 200 |
200 void InputDeviceSettingsImpl::SetTapDragging(bool enabled) { | 201 void InputDeviceSettingsImpl::SetTapDragging(bool enabled) { |
201 TouchpadSettings settings; | 202 TouchpadSettings settings; |
202 settings.SetTapDragging(enabled); | 203 settings.SetTapDragging(enabled); |
203 UpdateTouchpadSettings(settings); | 204 UpdateTouchpadSettings(settings); |
204 } | 205 } |
205 | 206 |
206 void InputDeviceSettingsImpl::MouseExists( | 207 void InputDeviceSettingsImpl::MouseExists( |
207 const DeviceExistsCallback& callback) { | 208 const DeviceExistsCallback& callback) { |
208 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 209 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
209 DeviceExists(kMouseControl, callback); | 210 DeviceExists(kMouse, callback); |
210 } | 211 } |
211 | 212 |
212 void InputDeviceSettingsImpl::UpdateMouseSettings(const MouseSettings& update) { | 213 void InputDeviceSettingsImpl::UpdateMouseSettings(const MouseSettings& update) { |
213 std::vector<std::string> argv; | 214 std::vector<std::string> argv; |
214 if (current_mouse_settings_.Update(update, &argv)) | 215 if (current_mouse_settings_.Update(update, &argv)) |
215 ExecuteScript(argv); | 216 ExecuteScript(argv); |
216 } | 217 } |
217 | 218 |
218 void InputDeviceSettingsImpl::SetMouseSensitivity(int value) { | 219 void InputDeviceSettingsImpl::SetMouseSensitivity(int value) { |
219 MouseSettings settings; | 220 MouseSettings settings; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
306 tap_dragging_.Set(enabled); | 307 tap_dragging_.Set(enabled); |
307 } | 308 } |
308 | 309 |
309 bool TouchpadSettings::GetTapDragging() const { | 310 bool TouchpadSettings::GetTapDragging() const { |
310 return tap_dragging_.value(); | 311 return tap_dragging_.value(); |
311 } | 312 } |
312 | 313 |
313 bool TouchpadSettings::Update(const TouchpadSettings& settings, | 314 bool TouchpadSettings::Update(const TouchpadSettings& settings, |
314 std::vector<std::string>* argv) { | 315 std::vector<std::string>* argv) { |
315 if (argv) | 316 if (argv) |
316 argv->push_back(kTpControl); | 317 argv->push_back(kInputControl); |
317 bool updated = false; | 318 bool updated = false; |
318 if (sensitivity_.Update(settings.sensitivity_)) { | 319 if (sensitivity_.Update(settings.sensitivity_)) { |
319 updated = true; | 320 updated = true; |
320 if (argv) | 321 if (argv) |
321 AddSensitivityArguments(sensitivity_.value(), argv); | 322 AddSensitivityArguments(kTouchpad, sensitivity_.value(), argv); |
322 } | 323 } |
323 if (tap_to_click_.Update(settings.tap_to_click_)) { | 324 if (tap_to_click_.Update(settings.tap_to_click_)) { |
324 updated = true; | 325 updated = true; |
325 if (argv) | 326 if (argv) |
326 AddTPControlArguments("taptoclick", tap_to_click_.value(), argv); | 327 AddTPControlArguments("tapclick", tap_to_click_.value(), argv); |
327 } | 328 } |
328 if (three_finger_click_.Update(settings.three_finger_click_)) { | 329 if (three_finger_click_.Update(settings.three_finger_click_)) { |
329 updated = true; | 330 updated = true; |
330 if (argv) | 331 if (argv) |
331 AddTPControlArguments("t5r2_three_finger_click", | 332 AddTPControlArguments("t5r2_three_finger_click", |
332 three_finger_click_.value(), | 333 three_finger_click_.value(), |
333 argv); | 334 argv); |
334 } | 335 } |
335 if (tap_dragging_.Update(settings.tap_dragging_)) { | 336 if (tap_dragging_.Update(settings.tap_dragging_)) { |
336 updated = true; | 337 updated = true; |
337 if (argv) | 338 if (argv) |
338 AddTPControlArguments("tap_dragging", tap_dragging_.value(), argv); | 339 AddTPControlArguments("tapdrag", tap_dragging_.value(), argv); |
339 } | 340 } |
340 return updated; | 341 return updated; |
341 } | 342 } |
342 | 343 |
343 MouseSettings::MouseSettings() {} | 344 MouseSettings::MouseSettings() {} |
344 | 345 |
345 MouseSettings& MouseSettings::operator=(const MouseSettings& other) { | 346 MouseSettings& MouseSettings::operator=(const MouseSettings& other) { |
346 if (&other != this) { | 347 if (&other != this) { |
347 sensitivity_ = other.sensitivity_; | 348 sensitivity_ = other.sensitivity_; |
348 primary_button_right_ = other.primary_button_right_; | 349 primary_button_right_ = other.primary_button_right_; |
(...skipping 13 matching lines...) Expand all Loading... | |
362 primary_button_right_.Set(right); | 363 primary_button_right_.Set(right); |
363 } | 364 } |
364 | 365 |
365 bool MouseSettings::GetPrimaryButtonRight() const { | 366 bool MouseSettings::GetPrimaryButtonRight() const { |
366 return primary_button_right_.value(); | 367 return primary_button_right_.value(); |
367 } | 368 } |
368 | 369 |
369 bool MouseSettings::Update(const MouseSettings& settings, | 370 bool MouseSettings::Update(const MouseSettings& settings, |
370 std::vector<std::string>* argv) { | 371 std::vector<std::string>* argv) { |
371 if (argv) | 372 if (argv) |
372 argv->push_back(kMouseControl); | 373 argv->push_back(kInputControl); |
373 bool updated = false; | 374 bool updated = false; |
374 if (sensitivity_.Update(settings.sensitivity_)) { | 375 if (sensitivity_.Update(settings.sensitivity_)) { |
375 updated = true; | 376 updated = true; |
376 if (argv) | 377 if (argv) |
377 AddSensitivityArguments(sensitivity_.value(), argv); | 378 AddSensitivityArguments(kMouse, sensitivity_.value(), argv); |
378 } | 379 } |
379 if (primary_button_right_.Update(settings.primary_button_right_)) { | 380 if (primary_button_right_.Update(settings.primary_button_right_)) { |
380 updated = true; | 381 updated = true; |
381 if (argv) { | 382 if (argv) { |
382 argv->push_back("swap_left_right"); | 383 AddTPControlArguments("mouse_swap_lr", primary_button_right_.value(), |
383 argv->push_back(settings.GetPrimaryButtonRight() ? "1" : "0"); | 384 argv); |
384 } | 385 } |
385 } | 386 } |
386 return updated; | 387 return updated; |
387 } | 388 } |
388 | 389 |
389 // static | 390 // static |
390 InputDeviceSettings* InputDeviceSettings::Get() { | 391 InputDeviceSettings* InputDeviceSettings::Get() { |
391 if (g_test_instance_) | 392 if (g_test_instance_) |
392 return g_test_instance_; | 393 return g_test_instance_; |
393 if (!g_instance_) | 394 if (!g_instance_) |
394 g_instance_ = new InputDeviceSettingsImpl; | 395 g_instance_ = new InputDeviceSettingsImpl; |
395 return g_instance_; | 396 return g_instance_; |
396 } | 397 } |
397 | 398 |
398 // static | 399 // static |
399 void InputDeviceSettings::SetSettingsForTesting( | 400 void InputDeviceSettings::SetSettingsForTesting( |
400 InputDeviceSettings* test_settings) { | 401 InputDeviceSettings* test_settings) { |
401 if (g_test_instance_ == test_settings) | 402 if (g_test_instance_ == test_settings) |
402 return; | 403 return; |
403 delete g_test_instance_; | 404 delete g_test_instance_; |
404 g_test_instance_ = test_settings; | 405 g_test_instance_ = test_settings; |
405 } | 406 } |
406 | 407 |
407 } // namespace system | 408 } // namespace system |
408 } // namespace chromeos | 409 } // namespace chromeos |
OLD | NEW |