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

Side by Side Diff: cloud_print/service/win/chrome_launcher.cc

Issue 14358019: Added Cloud Print Service installer/uninstaller. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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
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 "cloud_print/service/win/chrome_launcher.h" 5 #include "cloud_print/service/win/chrome_launcher.h"
6 6
7 #include "base/base_switches.h" 7 #include "base/base_switches.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/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
11 #include "base/json/json_reader.h" 11 #include "base/json/json_reader.h"
12 #include "base/json/json_writer.h" 12 #include "base/json/json_writer.h"
13 #include "base/process.h" 13 #include "base/process.h"
14 #include "base/process_util.h" 14 #include "base/process_util.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "base/win/registry.h" 16 #include "base/win/registry.h"
17 #include "base/win/scoped_handle.h" 17 #include "base/win/scoped_handle.h"
18 #include "base/win/scoped_process_information.h" 18 #include "base/win/scoped_process_information.h"
19 #include "chrome/common/chrome_constants.h" 19 #include "chrome/common/chrome_constants.h"
20 #include "chrome/common/chrome_switches.h" 20 #include "chrome/common/chrome_switches.h"
21 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
22 #include "chrome/installer/launcher_support/chrome_launcher_support.h" 22 #include "chrome/installer/launcher_support/chrome_launcher_support.h"
23 #include "cloud_print/common/win/cloud_print_utils.h"
24 #include "cloud_print/service/service_constants.h"
23 #include "google_apis/gaia/gaia_urls.h" 25 #include "google_apis/gaia/gaia_urls.h"
24 #include "googleurl/src/gurl.h" 26 #include "googleurl/src/gurl.h"
25 #include "net/base/url_util.h" 27 #include "net/base/url_util.h"
26 28
27 namespace { 29 namespace {
28 30
29 const int kShutdownTimeoutMs = 30 * 1000; 31 const int kShutdownTimeoutMs = 30 * 1000;
32 const int kUsageUpdateTimeoutMs = 6 * 3600 * 1000;
gene 2013/04/23 01:13:59 add comment here: // 6 hours
Vitaly Buka (NO REVIEWS) 2013/04/23 04:58:51 Done.
30 33
31 static const char16 kAutoRunKeyPath[] = 34 static const char16 kAutoRunKeyPath[] =
32 L"Software\\Microsoft\\Windows\\CurrentVersion\\Run"; 35 L"Software\\Microsoft\\Windows\\CurrentVersion\\Run";
33 36
34 void ShutdownChrome(HANDLE process, DWORD thread_id) { 37 void ShutdownChrome(HANDLE process, DWORD thread_id) {
35 if (::PostThreadMessage(thread_id, WM_QUIT, 0, 0) && 38 if (::PostThreadMessage(thread_id, WM_QUIT, 0, 0) &&
36 WAIT_OBJECT_0 == ::WaitForSingleObject(process, kShutdownTimeoutMs)) { 39 WAIT_OBJECT_0 == ::WaitForSingleObject(process, kShutdownTimeoutMs)) {
37 return; 40 return;
38 } 41 }
39 LOG(ERROR) << "Failed to shutdown process."; 42 LOG(ERROR) << "Failed to shutdown process.";
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 cmd.AppendSwitch(switches::kDisableGpu); 198 cmd.AppendSwitch(switches::kDisableGpu);
196 cmd.AppendSwitch(switches::kDisableSoftwareRasterizer); 199 cmd.AppendSwitch(switches::kDisableSoftwareRasterizer);
197 cmd.AppendSwitch(switches::kDisableSync); 200 cmd.AppendSwitch(switches::kDisableSync);
198 cmd.AppendSwitch(switches::kNoFirstRun); 201 cmd.AppendSwitch(switches::kNoFirstRun);
199 cmd.AppendSwitch(switches::kNoStartupWindow); 202 cmd.AppendSwitch(switches::kNoStartupWindow);
200 203
201 base::win::ScopedHandle chrome_handle; 204 base::win::ScopedHandle chrome_handle;
202 base::Time started = base::Time::Now(); 205 base::Time started = base::Time::Now();
203 DWORD thread_id = 0; 206 DWORD thread_id = 0;
204 LaunchProcess(cmd, chrome_handle.Receive(), &thread_id); 207 LaunchProcess(cmd, chrome_handle.Receive(), &thread_id);
205 int exit_code = 0; 208
206 HANDLE handles[] = {stop_event_.handle(), chrome_handle}; 209 HANDLE handles[] = {stop_event_.handle(), chrome_handle};
207 DWORD wait_result = ::WaitForMultipleObjects(arraysize(handles), handles, 210 DWORD wait_result = WAIT_TIMEOUT;
208 FALSE, INFINITE); 211 while (wait_result == WAIT_TIMEOUT) {
212 cloud_print::SetGoogleUpdateUsage(kGoogleUpdateId);
213 wait_result = ::WaitForMultipleObjects(arraysize(handles), handles,
214 FALSE, kUsageUpdateTimeoutMs);
215 }
209 if (wait_result == WAIT_OBJECT_0) { 216 if (wait_result == WAIT_OBJECT_0) {
210 ShutdownChrome(chrome_handle, thread_id); 217 ShutdownChrome(chrome_handle, thread_id);
211 break; 218 break;
212 } else if (wait_result == WAIT_OBJECT_0 + 1) { 219 } else if (wait_result == WAIT_OBJECT_0 + 1) {
213 LOG(ERROR) << "Chrome process exited."; 220 LOG(ERROR) << "Chrome process exited.";
214 } else { 221 } else {
215 LOG(ERROR) << "Error waiting Chrome (" << ::GetLastError() << ")."; 222 LOG(ERROR) << "Error waiting Chrome (" << ::GetLastError() << ").";
216 } 223 }
217 if (base::Time::Now() - started > base::TimeDelta::FromHours(1)) { 224 if (base::Time::Now() - started > base::TimeDelta::FromHours(1)) {
218 // Reset timeout because process worked long enough. 225 // Reset timeout because process worked long enough.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 289
283 cmd.AppendArg(GetCloudPrintServiceEnableURLWithSignin(proxy_id).spec()); 290 cmd.AppendArg(GetCloudPrintServiceEnableURLWithSignin(proxy_id).spec());
284 291
285 base::win::ScopedHandle chrome_handle; 292 base::win::ScopedHandle chrome_handle;
286 DWORD thread_id = 0; 293 DWORD thread_id = 0;
287 if (!LaunchProcess(cmd, chrome_handle.Receive(), &thread_id)) { 294 if (!LaunchProcess(cmd, chrome_handle.Receive(), &thread_id)) {
288 LOG(ERROR) << "Unable to launch Chrome."; 295 LOG(ERROR) << "Unable to launch Chrome.";
289 return result; 296 return result;
290 } 297 }
291 298
292 int exit_code = 0;
293 DWORD wait_result = ::WaitForSingleObject(chrome_handle, INFINITE); 299 DWORD wait_result = ::WaitForSingleObject(chrome_handle, INFINITE);
294 if (wait_result != WAIT_OBJECT_0) { 300 if (wait_result != WAIT_OBJECT_0) {
295 LOG(ERROR) << "Chrome launch failed."; 301 LOG(ERROR) << "Chrome launch failed.";
296 return result; 302 return result;
297 } 303 }
298 304
299 std::string json; 305 std::string json;
300 if (!file_util::ReadFileToString( 306 if (!file_util::ReadFileToString(
301 temp_user_data.path().Append(chrome::kServiceStateFileName), &json)) { 307 temp_user_data.path().Append(chrome::kServiceStateFileName), &json)) {
302 return result; 308 return result;
303 } 309 }
304 310
305 return UpdateServiceState(json, proxy_id); 311 return UpdateServiceState(json, proxy_id);
306 } 312 }
307 313
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698