OLD | NEW |
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/chromeos/system/touchpad_settings.h" | 5 #include "chrome/browser/chromeos/system/touchpad_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_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "base/process_util.h" | 12 #include "base/process_util.h" |
13 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
14 #include "chrome/browser/chromeos/system/runtime_environment.h" | 14 #include "chrome/browser/chromeos/system/runtime_environment.h" |
15 #include "content/browser/browser_thread.h" | 15 #include "content/browser/browser_thread.h" |
16 | 16 |
17 namespace chromeos { | 17 namespace chromeos { |
18 namespace system { | 18 namespace system { |
19 namespace touchpad_settings { | 19 namespace touchpad_settings { |
20 namespace { | 20 namespace { |
21 const char* kTpControl = "/opt/google/touchpad/tpcontrol"; | 21 const char* kTpControl = "/opt/google/touchpad/tpcontrol"; |
22 } // namespace | 22 |
| 23 bool TPCtrlExists() { |
| 24 return file_util::PathExists(FilePath(kTpControl)); |
| 25 } |
23 | 26 |
24 // Launches the tpcontrol command asynchronously, if it exists. | 27 // Launches the tpcontrol command asynchronously, if it exists. |
25 void LaunchTpControl(const std::vector<std::string>& argv) { | 28 void LaunchTpControl(const std::vector<std::string>& argv) { |
26 if (!system::runtime_environment::IsRunningOnChromeOS()) { | 29 if (!TPCtrlExists()) |
27 // Do nothing on Linux desktop, as the command does not exist. | |
28 return; | 30 return; |
29 } | |
30 | 31 |
31 if (!file_util::PathExists(FilePath(argv[0]))) { | 32 base::LaunchProcess(CommandLine(argv), base::LaunchOptions(), NULL); |
32 LOG(ERROR) << argv[0] << " not found"; | 33 } |
33 return; | |
34 } | |
35 | 34 |
36 base::LaunchOptions options; | 35 } // namespace |
37 options.wait = false; // Launch asynchronously. | |
38 | 36 |
39 base::LaunchProcess(CommandLine(argv), options, NULL); | 37 bool TouchpadExists() { |
| 38 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 39 static bool init = false; |
| 40 static bool exists = false; |
| 41 |
| 42 if (init) |
| 43 return exists; |
| 44 |
| 45 init = true; |
| 46 if (!TPCtrlExists()) |
| 47 return exists; |
| 48 |
| 49 std::vector<std::string> argv; |
| 50 argv.push_back(kTpControl); |
| 51 argv.push_back("status"); |
| 52 std::string output; |
| 53 // On devices with no touchpad, output is empty. |
| 54 exists = base::GetAppOutput(CommandLine(argv), &output) && !output.empty(); |
| 55 return exists; |
40 } | 56 } |
41 | 57 |
42 void SetSensitivity(int value) { | 58 void SetSensitivity(int value) { |
43 // Run this on the FILE thread. | 59 // Run this on the FILE thread. |
44 if (!BrowserThread::CurrentlyOn(BrowserThread::FILE)) { | 60 if (!BrowserThread::CurrentlyOn(BrowserThread::FILE)) { |
45 BrowserThread::PostTask( | 61 BrowserThread::PostTask( |
46 BrowserThread::FILE, FROM_HERE, | 62 BrowserThread::FILE, FROM_HERE, |
47 base::Bind(&SetSensitivity, value)); | 63 base::Bind(&SetSensitivity, value)); |
48 return; | 64 return; |
49 } | 65 } |
(...skipping 19 matching lines...) Expand all Loading... |
69 argv.push_back(kTpControl); | 85 argv.push_back(kTpControl); |
70 argv.push_back("taptoclick"); | 86 argv.push_back("taptoclick"); |
71 argv.push_back(enabled ? "on" : "off"); | 87 argv.push_back(enabled ? "on" : "off"); |
72 | 88 |
73 LaunchTpControl(argv); | 89 LaunchTpControl(argv); |
74 } | 90 } |
75 | 91 |
76 } // namespace touchpad_settings | 92 } // namespace touchpad_settings |
77 } // namespace system | 93 } // namespace system |
78 } // namespace chromeos | 94 } // namespace chromeos |
OLD | NEW |