OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "win8/test/metro_registration_helper.h" | |
6 | |
7 #include "base/command_line.h" | |
8 #include "base/file_path.h" | |
9 #include "base/file_util.h" | |
10 #include "base/logging.h" | |
11 #include "base/path_service.h" | |
12 #include "base/process.h" | |
13 #include "base/process_util.h" | |
14 #include "win8/test/test_registrar_constants.h" | |
grt (UTC plus 2)
2013/02/12 15:37:43
#include "base/win/scoped_handle.h"
robertshield
2013/02/12 16:57:08
Done.
| |
15 | |
16 namespace { | |
17 | |
18 const int kRegistrationTimeout = 30000; | |
19 | |
20 // Copied from util_constants.cc to avoid taking a dependency on installer_util. | |
21 const wchar_t kChromeExe[] = L"chrome.exe"; | |
22 const wchar_t kRegistrar[] = L"test_registrar.exe"; | |
23 | |
24 } | |
25 | |
26 namespace win8 { | |
27 | |
28 bool RegisterTestDefaultBrowser(const string16& app_user_model_id) { | |
29 FilePath dir; | |
30 if (!PathService::Get(base::DIR_EXE, &dir)) | |
31 return false; | |
32 | |
33 FilePath chrome_exe(dir.Append(kChromeExe)); | |
34 FilePath registrar(dir.Append(kRegistrar)); | |
35 | |
36 if (!file_util::PathExists(chrome_exe) || !file_util::PathExists(registrar)) { | |
37 LOG(ERROR) << "Could not locate " << kChromeExe << " and " << kRegistrar; | |
grt (UTC plus 2)
2013/02/12 15:37:43
and -> and/or
robertshield
2013/02/12 16:57:08
Done.
| |
38 return false; | |
39 } | |
40 | |
41 // Perform the registration by invoking test_delegate_execute.exe with the | |
grt (UTC plus 2)
2013/02/12 15:37:43
update comment
robertshield
2013/02/12 16:57:08
Done.
| |
42 // necessary flags: | |
43 // test_delegate_execute.exe /RegServer --appid=<appid> | |
44 CommandLine register_command(registrar); | |
45 register_command.AppendArg("/RegServer"); | |
46 register_command.AppendSwitchNative(win8::test::kTestAppUserModelId, | |
47 app_user_model_id); | |
48 | |
49 base::ProcessHandle register_handle; | |
grt (UTC plus 2)
2013/02/12 15:37:43
base::win::ScopedHandle register_handle;
robertshield
2013/02/12 16:57:08
Done.
| |
50 if (base::LaunchProcess(register_command, base::LaunchOptions(), | |
51 ®ister_handle)) { | |
grt (UTC plus 2)
2013/02/12 15:37:43
register_handle.Receive()
robertshield
2013/02/12 16:57:08
Done.
| |
52 DWORD result = WaitForSingleObject(register_handle, kRegistrationTimeout); | |
grt (UTC plus 2)
2013/02/12 15:37:43
int ret = 0;
if (base::WaitForExitCodeWithTimeout(
robertshield
2013/02/12 16:57:08
Done.
| |
53 if (result == WAIT_OBJECT_0) { | |
54 DWORD ret = 0; | |
55 if (::GetExitCodeProcess(register_handle, &ret)) | |
56 return ret == 0; | |
57 } | |
58 } | |
59 | |
60 LOG(ERROR) << "Win8 registration using " << kRegistrar << " timed out."; | |
61 return false; | |
62 } | |
63 | |
64 } // namespace win8 | |
OLD | NEW |