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

Side by Side Diff: remoting/host/setup/daemon_controller_linux.cc

Issue 12163003: Add FilePath to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 months 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
« no previous file with comments | « remoting/host/sas_injector_win.cc ('k') | remoting/host/setup/daemon_controller_mac.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "remoting/host/setup/daemon_controller.h" 5 #include "remoting/host/setup/daemon_controller.h"
6 6
7 #include <unistd.h> 7 #include <unistd.h>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 const CompletionCallback& done) OVERRIDE; 61 const CompletionCallback& done) OVERRIDE;
62 virtual void UpdateConfig(scoped_ptr<base::DictionaryValue> config, 62 virtual void UpdateConfig(scoped_ptr<base::DictionaryValue> config,
63 const CompletionCallback& done_callback) OVERRIDE; 63 const CompletionCallback& done_callback) OVERRIDE;
64 virtual void Stop(const CompletionCallback& done_callback) OVERRIDE; 64 virtual void Stop(const CompletionCallback& done_callback) OVERRIDE;
65 virtual void SetWindow(void* window_handle) OVERRIDE; 65 virtual void SetWindow(void* window_handle) OVERRIDE;
66 virtual void GetVersion(const GetVersionCallback& done_callback) OVERRIDE; 66 virtual void GetVersion(const GetVersionCallback& done_callback) OVERRIDE;
67 virtual void GetUsageStatsConsent( 67 virtual void GetUsageStatsConsent(
68 const GetUsageStatsConsentCallback& done) OVERRIDE; 68 const GetUsageStatsConsentCallback& done) OVERRIDE;
69 69
70 private: 70 private:
71 FilePath GetConfigPath(); 71 base::FilePath GetConfigPath();
72 72
73 void DoGetConfig(const GetConfigCallback& callback); 73 void DoGetConfig(const GetConfigCallback& callback);
74 void DoSetConfigAndStart(scoped_ptr<base::DictionaryValue> config, 74 void DoSetConfigAndStart(scoped_ptr<base::DictionaryValue> config,
75 const CompletionCallback& done); 75 const CompletionCallback& done);
76 void DoUpdateConfig(scoped_ptr<base::DictionaryValue> config, 76 void DoUpdateConfig(scoped_ptr<base::DictionaryValue> config,
77 const CompletionCallback& done_callback); 77 const CompletionCallback& done_callback);
78 void DoStop(const CompletionCallback& done_callback); 78 void DoStop(const CompletionCallback& done_callback);
79 void DoGetVersion(const GetVersionCallback& done_callback); 79 void DoGetVersion(const GetVersionCallback& done_callback);
80 80
81 base::Thread file_io_thread_; 81 base::Thread file_io_thread_;
82 82
83 DISALLOW_COPY_AND_ASSIGN(DaemonControllerLinux); 83 DISALLOW_COPY_AND_ASSIGN(DaemonControllerLinux);
84 }; 84 };
85 85
86 DaemonControllerLinux::DaemonControllerLinux() 86 DaemonControllerLinux::DaemonControllerLinux()
87 : file_io_thread_("DaemonControllerFileIO") { 87 : file_io_thread_("DaemonControllerFileIO") {
88 file_io_thread_.Start(); 88 file_io_thread_.Start();
89 } 89 }
90 90
91 static bool GetScriptPath(FilePath* result) { 91 static bool GetScriptPath(base::FilePath* result) {
92 FilePath candidate_exe(kDaemonScript); 92 base::FilePath candidate_exe(kDaemonScript);
93 if (access(candidate_exe.value().c_str(), X_OK) == 0) { 93 if (access(candidate_exe.value().c_str(), X_OK) == 0) {
94 *result = candidate_exe; 94 *result = candidate_exe;
95 return true; 95 return true;
96 } 96 }
97 return false; 97 return false;
98 } 98 }
99 99
100 static bool RunHostScriptWithTimeout( 100 static bool RunHostScriptWithTimeout(
101 const std::vector<std::string>& args, 101 const std::vector<std::string>& args,
102 base::TimeDelta timeout, 102 base::TimeDelta timeout,
103 int* exit_code) { 103 int* exit_code) {
104 // As long as we're relying on running an external binary from the 104 // As long as we're relying on running an external binary from the
105 // PATH, don't do it as root. 105 // PATH, don't do it as root.
106 if (getuid() == 0) { 106 if (getuid() == 0) {
107 return false; 107 return false;
108 } 108 }
109 FilePath script_path; 109 base::FilePath script_path;
110 if (!GetScriptPath(&script_path)) { 110 if (!GetScriptPath(&script_path)) {
111 return false; 111 return false;
112 } 112 }
113 CommandLine command_line(script_path); 113 CommandLine command_line(script_path);
114 for (unsigned int i = 0; i < args.size(); ++i) { 114 for (unsigned int i = 0; i < args.size(); ++i) {
115 command_line.AppendArg(args[i]); 115 command_line.AppendArg(args[i]);
116 } 116 }
117 base::ProcessHandle process_handle; 117 base::ProcessHandle process_handle;
118 bool result = base::LaunchProcess(command_line, 118 bool result = base::LaunchProcess(command_line,
119 base::LaunchOptions(), 119 base::LaunchOptions(),
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 // noop 193 // noop
194 } 194 }
195 195
196 void DaemonControllerLinux::GetVersion( 196 void DaemonControllerLinux::GetVersion(
197 const GetVersionCallback& done_callback) { 197 const GetVersionCallback& done_callback) {
198 file_io_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( 198 file_io_thread_.message_loop()->PostTask(FROM_HERE, base::Bind(
199 &DaemonControllerLinux::DoGetVersion, base::Unretained(this), 199 &DaemonControllerLinux::DoGetVersion, base::Unretained(this),
200 done_callback)); 200 done_callback));
201 } 201 }
202 202
203 FilePath DaemonControllerLinux::GetConfigPath() { 203 base::FilePath DaemonControllerLinux::GetConfigPath() {
204 std::string filename = "host#" + GetMd5(net::GetHostName()) + ".json"; 204 std::string filename = "host#" + GetMd5(net::GetHostName()) + ".json";
205 return file_util::GetHomeDir(). 205 return file_util::GetHomeDir().
206 Append(".config/chrome-remote-desktop").Append(filename); 206 Append(".config/chrome-remote-desktop").Append(filename);
207 } 207 }
208 208
209 void DaemonControllerLinux::DoGetConfig(const GetConfigCallback& callback) { 209 void DaemonControllerLinux::DoGetConfig(const GetConfigCallback& callback) {
210 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue()); 210 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue());
211 211
212 if (GetState() != remoting::DaemonController::STATE_NOT_IMPLEMENTED) { 212 if (GetState() != remoting::DaemonController::STATE_NOT_IMPLEMENTED) {
213 JsonHostConfig config(GetConfigPath()); 213 JsonHostConfig config(GetConfigPath());
(...skipping 24 matching lines...) Expand all
238 if (!RunHostScriptWithTimeout( 238 if (!RunHostScriptWithTimeout(
239 args, base::TimeDelta::FromMilliseconds(kSudoTimeoutMs), 239 args, base::TimeDelta::FromMilliseconds(kSudoTimeoutMs),
240 &exit_code) || 240 &exit_code) ||
241 exit_code != 0) { 241 exit_code != 0) {
242 LOG(ERROR) << "Failed to add user to chrome-remote-desktop group."; 242 LOG(ERROR) << "Failed to add user to chrome-remote-desktop group.";
243 done_callback.Run(RESULT_FAILED); 243 done_callback.Run(RESULT_FAILED);
244 return; 244 return;
245 } 245 }
246 246
247 // Ensure the configuration directory exists. 247 // Ensure the configuration directory exists.
248 FilePath config_dir = GetConfigPath().DirName(); 248 base::FilePath config_dir = GetConfigPath().DirName();
249 if (!file_util::DirectoryExists(config_dir) && 249 if (!file_util::DirectoryExists(config_dir) &&
250 !file_util::CreateDirectory(config_dir)) { 250 !file_util::CreateDirectory(config_dir)) {
251 LOG(ERROR) << "Failed to create config directory " << config_dir.value(); 251 LOG(ERROR) << "Failed to create config directory " << config_dir.value();
252 done_callback.Run(RESULT_FAILED); 252 done_callback.Run(RESULT_FAILED);
253 return; 253 return;
254 } 254 }
255 255
256 // Write config. 256 // Write config.
257 JsonHostConfig config_file(GetConfigPath()); 257 JsonHostConfig config_file(GetConfigPath());
258 if (!config_file.CopyFrom(config.get()) || 258 if (!config_file.CopyFrom(config.get()) ||
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 if (RunHostScript(args, &exit_code)) { 307 if (RunHostScript(args, &exit_code)) {
308 result = (exit_code == 0) ? RESULT_OK : RESULT_FAILED; 308 result = (exit_code == 0) ? RESULT_OK : RESULT_FAILED;
309 } else { 309 } else {
310 result = RESULT_FAILED; 310 result = RESULT_FAILED;
311 } 311 }
312 done_callback.Run(result); 312 done_callback.Run(result);
313 } 313 }
314 314
315 void DaemonControllerLinux::DoGetVersion( 315 void DaemonControllerLinux::DoGetVersion(
316 const GetVersionCallback& done_callback) { 316 const GetVersionCallback& done_callback) {
317 FilePath script_path; 317 base::FilePath script_path;
318 if (!GetScriptPath(&script_path)) { 318 if (!GetScriptPath(&script_path)) {
319 done_callback.Run(""); 319 done_callback.Run("");
320 return; 320 return;
321 } 321 }
322 CommandLine command_line(script_path); 322 CommandLine command_line(script_path);
323 command_line.AppendArg("--host-version"); 323 command_line.AppendArg("--host-version");
324 324
325 std::string version; 325 std::string version;
326 int exit_code = 0; 326 int exit_code = 0;
327 int result = 327 int result =
(...skipping 15 matching lines...) Expand all
343 done_callback.Run(version); 343 done_callback.Run(version);
344 } 344 }
345 345
346 } // namespace 346 } // namespace
347 347
348 scoped_ptr<DaemonController> remoting::DaemonController::Create() { 348 scoped_ptr<DaemonController> remoting::DaemonController::Create() {
349 return scoped_ptr<DaemonController>(new DaemonControllerLinux()); 349 return scoped_ptr<DaemonController>(new DaemonControllerLinux());
350 } 350 }
351 351
352 } // namespace remoting 352 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/sas_injector_win.cc ('k') | remoting/host/setup/daemon_controller_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698