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 kDeviceTypeTouchpad[] = "touchpad"; |
37 const char kMouseControl[] = "/opt/google/mouse/mousecontrol"; | 37 const char kDeviceTypeMouse[] = "mouse"; |
| 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* device_type, int value, |
| 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", |
87 argv->push_back(base::StringPrintf("%d", value)); | 89 device_type, value)); |
88 } | 90 } |
89 | 91 |
90 void AddTPControlArguments(const char* control, | 92 void AddTPControlArguments(const char* control, |
91 bool enabled, | 93 bool enabled, |
92 std::vector<std::string>* argv) { | 94 std::vector<std::string>* argv) { |
93 argv->push_back(control); | 95 argv->push_back(base::StringPrintf("--%s=%d", control, enabled ? 1 : 0)); |
94 argv->push_back(enabled ? "on" : "off"); | |
95 } | 96 } |
96 | 97 |
97 void DeviceExistsBlockingPool(const char* script, | 98 void DeviceExistsBlockingPool(const char* device_type, |
98 scoped_refptr<RefCountedBool> exists) { | 99 scoped_refptr<RefCountedBool> exists) { |
99 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | 100 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
100 exists->data = false; | 101 exists->data = false; |
101 if (!ScriptExists(script)) | 102 if (!ScriptExists(kInputControl)) |
102 return; | 103 return; |
103 | 104 |
104 std::vector<std::string> argv; | 105 std::vector<std::string> argv; |
105 argv.push_back(script); | 106 argv.push_back(kInputControl); |
106 argv.push_back("status"); | 107 argv.push_back(base::StringPrintf("--type=%s", device_type)); |
| 108 argv.push_back("--list"); |
107 std::string output; | 109 std::string output; |
108 // Output is empty if the device is not found. | 110 // Output is empty if the device is not found. |
109 exists->data = base::GetAppOutput(CommandLine(argv), &output) && | 111 exists->data = base::GetAppOutput(CommandLine(argv), &output) && |
110 !output.empty(); | 112 !output.empty(); |
111 DVLOG(1) << "DeviceExistsBlockingPool:" << script << "=" << exists->data; | 113 DVLOG(1) << "DeviceExistsBlockingPool:" << device_type << "=" << exists->data; |
112 } | 114 } |
113 | 115 |
114 void RunCallbackUIThread( | 116 void RunCallbackUIThread( |
115 scoped_refptr<RefCountedBool> exists, | 117 scoped_refptr<RefCountedBool> exists, |
116 const InputDeviceSettings::DeviceExistsCallback& callback) { | 118 const InputDeviceSettings::DeviceExistsCallback& callback) { |
117 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 119 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
118 DVLOG(1) << "RunCallbackUIThread " << exists->data; | 120 DVLOG(1) << "RunCallbackUIThread " << exists->data; |
119 callback.Run(exists->data); | 121 callback.Run(exists->data); |
120 } | 122 } |
121 | 123 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 TouchpadSettings current_touchpad_settings_; | 163 TouchpadSettings current_touchpad_settings_; |
162 MouseSettings current_mouse_settings_; | 164 MouseSettings current_mouse_settings_; |
163 | 165 |
164 DISALLOW_COPY_AND_ASSIGN(InputDeviceSettingsImpl); | 166 DISALLOW_COPY_AND_ASSIGN(InputDeviceSettingsImpl); |
165 }; | 167 }; |
166 | 168 |
167 InputDeviceSettingsImpl::InputDeviceSettingsImpl() {} | 169 InputDeviceSettingsImpl::InputDeviceSettingsImpl() {} |
168 | 170 |
169 void InputDeviceSettingsImpl::TouchpadExists( | 171 void InputDeviceSettingsImpl::TouchpadExists( |
170 const DeviceExistsCallback& callback) { | 172 const DeviceExistsCallback& callback) { |
171 DeviceExists(kTpControl, callback); | 173 DeviceExists(kDeviceTypeTouchpad, callback); |
172 } | 174 } |
173 | 175 |
174 void InputDeviceSettingsImpl::UpdateTouchpadSettings( | 176 void InputDeviceSettingsImpl::UpdateTouchpadSettings( |
175 const TouchpadSettings& settings) { | 177 const TouchpadSettings& settings) { |
176 std::vector<std::string> argv; | 178 std::vector<std::string> argv; |
177 if (current_touchpad_settings_.Update(settings, &argv)) | 179 if (current_touchpad_settings_.Update(settings, &argv)) |
178 ExecuteScript(argv); | 180 ExecuteScript(argv); |
179 } | 181 } |
180 | 182 |
181 void InputDeviceSettingsImpl::SetTouchpadSensitivity(int value) { | 183 void InputDeviceSettingsImpl::SetTouchpadSensitivity(int value) { |
(...skipping 17 matching lines...) Expand all Loading... |
199 | 201 |
200 void InputDeviceSettingsImpl::SetTapDragging(bool enabled) { | 202 void InputDeviceSettingsImpl::SetTapDragging(bool enabled) { |
201 TouchpadSettings settings; | 203 TouchpadSettings settings; |
202 settings.SetTapDragging(enabled); | 204 settings.SetTapDragging(enabled); |
203 UpdateTouchpadSettings(settings); | 205 UpdateTouchpadSettings(settings); |
204 } | 206 } |
205 | 207 |
206 void InputDeviceSettingsImpl::MouseExists( | 208 void InputDeviceSettingsImpl::MouseExists( |
207 const DeviceExistsCallback& callback) { | 209 const DeviceExistsCallback& callback) { |
208 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 210 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
209 DeviceExists(kMouseControl, callback); | 211 DeviceExists(kDeviceTypeMouse, callback); |
210 } | 212 } |
211 | 213 |
212 void InputDeviceSettingsImpl::UpdateMouseSettings(const MouseSettings& update) { | 214 void InputDeviceSettingsImpl::UpdateMouseSettings(const MouseSettings& update) { |
213 std::vector<std::string> argv; | 215 std::vector<std::string> argv; |
214 if (current_mouse_settings_.Update(update, &argv)) | 216 if (current_mouse_settings_.Update(update, &argv)) |
215 ExecuteScript(argv); | 217 ExecuteScript(argv); |
216 } | 218 } |
217 | 219 |
218 void InputDeviceSettingsImpl::SetMouseSensitivity(int value) { | 220 void InputDeviceSettingsImpl::SetMouseSensitivity(int value) { |
219 MouseSettings settings; | 221 MouseSettings settings; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 tap_dragging_.Set(enabled); | 308 tap_dragging_.Set(enabled); |
307 } | 309 } |
308 | 310 |
309 bool TouchpadSettings::GetTapDragging() const { | 311 bool TouchpadSettings::GetTapDragging() const { |
310 return tap_dragging_.value(); | 312 return tap_dragging_.value(); |
311 } | 313 } |
312 | 314 |
313 bool TouchpadSettings::Update(const TouchpadSettings& settings, | 315 bool TouchpadSettings::Update(const TouchpadSettings& settings, |
314 std::vector<std::string>* argv) { | 316 std::vector<std::string>* argv) { |
315 if (argv) | 317 if (argv) |
316 argv->push_back(kTpControl); | 318 argv->push_back(kInputControl); |
317 bool updated = false; | 319 bool updated = false; |
318 if (sensitivity_.Update(settings.sensitivity_)) { | 320 if (sensitivity_.Update(settings.sensitivity_)) { |
319 updated = true; | 321 updated = true; |
320 if (argv) | 322 if (argv) |
321 AddSensitivityArguments(sensitivity_.value(), argv); | 323 AddSensitivityArguments(kDeviceTypeTouchpad, sensitivity_.value(), argv); |
322 } | 324 } |
323 if (tap_to_click_.Update(settings.tap_to_click_)) { | 325 if (tap_to_click_.Update(settings.tap_to_click_)) { |
324 updated = true; | 326 updated = true; |
325 if (argv) | 327 if (argv) |
326 AddTPControlArguments("taptoclick", tap_to_click_.value(), argv); | 328 AddTPControlArguments("tapclick", tap_to_click_.value(), argv); |
327 } | 329 } |
328 if (three_finger_click_.Update(settings.three_finger_click_)) { | 330 if (three_finger_click_.Update(settings.three_finger_click_)) { |
329 updated = true; | 331 updated = true; |
330 if (argv) | 332 if (argv) |
331 AddTPControlArguments("t5r2_three_finger_click", | 333 AddTPControlArguments("t5r2_three_finger_click", |
332 three_finger_click_.value(), | 334 three_finger_click_.value(), |
333 argv); | 335 argv); |
334 } | 336 } |
335 if (tap_dragging_.Update(settings.tap_dragging_)) { | 337 if (tap_dragging_.Update(settings.tap_dragging_)) { |
336 updated = true; | 338 updated = true; |
337 if (argv) | 339 if (argv) |
338 AddTPControlArguments("tap_dragging", tap_dragging_.value(), argv); | 340 AddTPControlArguments("tapdrag", tap_dragging_.value(), argv); |
339 } | 341 } |
340 return updated; | 342 return updated; |
341 } | 343 } |
342 | 344 |
343 MouseSettings::MouseSettings() {} | 345 MouseSettings::MouseSettings() {} |
344 | 346 |
345 MouseSettings& MouseSettings::operator=(const MouseSettings& other) { | 347 MouseSettings& MouseSettings::operator=(const MouseSettings& other) { |
346 if (&other != this) { | 348 if (&other != this) { |
347 sensitivity_ = other.sensitivity_; | 349 sensitivity_ = other.sensitivity_; |
348 primary_button_right_ = other.primary_button_right_; | 350 primary_button_right_ = other.primary_button_right_; |
(...skipping 13 matching lines...) Expand all Loading... |
362 primary_button_right_.Set(right); | 364 primary_button_right_.Set(right); |
363 } | 365 } |
364 | 366 |
365 bool MouseSettings::GetPrimaryButtonRight() const { | 367 bool MouseSettings::GetPrimaryButtonRight() const { |
366 return primary_button_right_.value(); | 368 return primary_button_right_.value(); |
367 } | 369 } |
368 | 370 |
369 bool MouseSettings::Update(const MouseSettings& settings, | 371 bool MouseSettings::Update(const MouseSettings& settings, |
370 std::vector<std::string>* argv) { | 372 std::vector<std::string>* argv) { |
371 if (argv) | 373 if (argv) |
372 argv->push_back(kMouseControl); | 374 argv->push_back(kInputControl); |
373 bool updated = false; | 375 bool updated = false; |
374 if (sensitivity_.Update(settings.sensitivity_)) { | 376 if (sensitivity_.Update(settings.sensitivity_)) { |
375 updated = true; | 377 updated = true; |
376 if (argv) | 378 if (argv) |
377 AddSensitivityArguments(sensitivity_.value(), argv); | 379 AddSensitivityArguments(kDeviceTypeMouse, sensitivity_.value(), argv); |
378 } | 380 } |
379 if (primary_button_right_.Update(settings.primary_button_right_)) { | 381 if (primary_button_right_.Update(settings.primary_button_right_)) { |
380 updated = true; | 382 updated = true; |
381 if (argv) { | 383 if (argv) { |
382 argv->push_back("swap_left_right"); | 384 AddTPControlArguments("mouse_swap_lr", primary_button_right_.value(), |
383 argv->push_back(settings.GetPrimaryButtonRight() ? "1" : "0"); | 385 argv); |
384 } | 386 } |
385 } | 387 } |
386 return updated; | 388 return updated; |
387 } | 389 } |
388 | 390 |
389 // static | 391 // static |
390 InputDeviceSettings* InputDeviceSettings::Get() { | 392 InputDeviceSettings* InputDeviceSettings::Get() { |
391 if (g_test_instance_) | 393 if (g_test_instance_) |
392 return g_test_instance_; | 394 return g_test_instance_; |
393 if (!g_instance_) | 395 if (!g_instance_) |
394 g_instance_ = new InputDeviceSettingsImpl; | 396 g_instance_ = new InputDeviceSettingsImpl; |
395 return g_instance_; | 397 return g_instance_; |
396 } | 398 } |
397 | 399 |
398 // static | 400 // static |
399 void InputDeviceSettings::SetSettingsForTesting( | 401 void InputDeviceSettings::SetSettingsForTesting( |
400 InputDeviceSettings* test_settings) { | 402 InputDeviceSettings* test_settings) { |
401 if (g_test_instance_ == test_settings) | 403 if (g_test_instance_ == test_settings) |
402 return; | 404 return; |
403 delete g_test_instance_; | 405 delete g_test_instance_; |
404 g_test_instance_ = test_settings; | 406 g_test_instance_ = test_settings; |
405 } | 407 } |
406 | 408 |
407 } // namespace system | 409 } // namespace system |
408 } // namespace chromeos | 410 } // namespace chromeos |
OLD | NEW |