| 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 "cloud_print/service/win/chrome_launcher.h" | 5 #include "cloud_print/service/win/chrome_launcher.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/process.h" | 8 #include "base/process.h" |
| 9 #include "base/process_util.h" | 9 #include "base/process_util.h" |
| 10 #include "base/win/scoped_handle.h" | 10 #include "base/win/scoped_handle.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 *process_handle = process_info.TakeProcessHandle(); | 44 *process_handle = process_info.TakeProcessHandle(); |
| 45 | 45 |
| 46 if (thread_id) | 46 if (thread_id) |
| 47 *thread_id = process_info.thread_id(); | 47 *thread_id = process_info.thread_id(); |
| 48 | 48 |
| 49 return true; | 49 return true; |
| 50 } | 50 } |
| 51 | 51 |
| 52 } // namespace | 52 } // namespace |
| 53 | 53 |
| 54 ChromeLauncher::ChromeLauncher(const FilePath& user_data) | 54 ChromeLauncher::ChromeLauncher(const base::FilePath& user_data) |
| 55 : stop_event_(true, true), | 55 : stop_event_(true, true), |
| 56 user_data_(user_data) { | 56 user_data_(user_data) { |
| 57 } | 57 } |
| 58 | 58 |
| 59 ChromeLauncher::~ChromeLauncher() { | 59 ChromeLauncher::~ChromeLauncher() { |
| 60 } | 60 } |
| 61 | 61 |
| 62 bool ChromeLauncher::Start() { | 62 bool ChromeLauncher::Start() { |
| 63 stop_event_.Reset(); | 63 stop_event_.Reset(); |
| 64 thread_.reset(new base::DelegateSimpleThread(this, "chrome_launcher")); | 64 thread_.reset(new base::DelegateSimpleThread(this, "chrome_launcher")); |
| 65 thread_->Start(); | 65 thread_->Start(); |
| 66 return true; | 66 return true; |
| 67 } | 67 } |
| 68 | 68 |
| 69 void ChromeLauncher::Stop() { | 69 void ChromeLauncher::Stop() { |
| 70 stop_event_.Signal(); | 70 stop_event_.Signal(); |
| 71 thread_->Join(); | 71 thread_->Join(); |
| 72 thread_.reset(); | 72 thread_.reset(); |
| 73 } | 73 } |
| 74 | 74 |
| 75 void ChromeLauncher::Run() { | 75 void ChromeLauncher::Run() { |
| 76 const base::TimeDelta default_time_out = base::TimeDelta::FromSeconds(1); | 76 const base::TimeDelta default_time_out = base::TimeDelta::FromSeconds(1); |
| 77 const base::TimeDelta max_time_out = base::TimeDelta::FromHours(1); | 77 const base::TimeDelta max_time_out = base::TimeDelta::FromHours(1); |
| 78 | 78 |
| 79 for (base::TimeDelta time_out = default_time_out;; | 79 for (base::TimeDelta time_out = default_time_out;; |
| 80 time_out = std::min(time_out * 2, max_time_out)) { | 80 time_out = std::min(time_out * 2, max_time_out)) { |
| 81 FilePath chrome_path = chrome_launcher_support::GetAnyChromePath(); | 81 base::FilePath chrome_path = chrome_launcher_support::GetAnyChromePath(); |
| 82 | 82 |
| 83 if (!chrome_path.empty()) { | 83 if (!chrome_path.empty()) { |
| 84 CommandLine cmd(chrome_path); | 84 CommandLine cmd(chrome_path); |
| 85 cmd.AppendSwitchASCII(kChromeTypeSwitch, "service"); | 85 cmd.AppendSwitchASCII(kChromeTypeSwitch, "service"); |
| 86 cmd.AppendSwitchPath(kUserDataDirSwitch, user_data_); | 86 cmd.AppendSwitchPath(kUserDataDirSwitch, user_data_); |
| 87 base::win::ScopedHandle chrome_handle; | 87 base::win::ScopedHandle chrome_handle; |
| 88 base::Time started = base::Time::Now(); | 88 base::Time started = base::Time::Now(); |
| 89 DWORD thread_id = 0; | 89 DWORD thread_id = 0; |
| 90 LaunchProcess(cmd, chrome_handle.Receive(), &thread_id); | 90 LaunchProcess(cmd, chrome_handle.Receive(), &thread_id); |
| 91 int exit_code = 0; | 91 int exit_code = 0; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 104 // Reset timeout because process worked long enough. | 104 // Reset timeout because process worked long enough. |
| 105 time_out = default_time_out; | 105 time_out = default_time_out; |
| 106 } | 106 } |
| 107 } | 107 } |
| 108 if (stop_event_.TimedWait(time_out)) | 108 if (stop_event_.TimedWait(time_out)) |
| 109 break; | 109 break; |
| 110 } | 110 } |
| 111 } | 111 } |
| 112 | 112 |
| 113 | 113 |
| OLD | NEW |