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 "base/win/scoped_handle.h" |
| 15 #include "win8/test/test_registrar_constants.h" |
| 16 |
| 17 namespace { |
| 18 |
| 19 const int kRegistrationTimeoutSeconds = 30; |
| 20 |
| 21 // Copied from util_constants.cc to avoid taking a dependency on installer_util. |
| 22 const wchar_t kChromeExe[] = L"chrome.exe"; |
| 23 const wchar_t kRegistrar[] = L"test_registrar.exe"; |
| 24 |
| 25 } |
| 26 |
| 27 namespace win8 { |
| 28 |
| 29 bool RegisterTestDefaultBrowser(const string16& app_user_model_id, |
| 30 const string16& viewer_process_name) { |
| 31 FilePath dir; |
| 32 if (!PathService::Get(base::DIR_EXE, &dir)) |
| 33 return false; |
| 34 |
| 35 FilePath chrome_exe(dir.Append(kChromeExe)); |
| 36 FilePath registrar(dir.Append(kRegistrar)); |
| 37 |
| 38 if (!file_util::PathExists(chrome_exe) || !file_util::PathExists(registrar)) { |
| 39 LOG(ERROR) << "Could not locate " << kChromeExe << " or " << kRegistrar; |
| 40 return false; |
| 41 } |
| 42 |
| 43 // Perform the registration by invoking test_registrar.exe with the |
| 44 // necessary flags: |
| 45 // test_registrar.exe /RegServer --appid=<appid> --exe-name=<name> |
| 46 CommandLine register_command(registrar); |
| 47 register_command.AppendArg("/RegServer"); |
| 48 register_command.AppendSwitchNative(win8::test::kTestAppUserModelId, |
| 49 app_user_model_id); |
| 50 register_command.AppendSwitchNative(win8::test::kTestExeName, |
| 51 viewer_process_name); |
| 52 |
| 53 base::win::ScopedHandle register_handle; |
| 54 if (base::LaunchProcess(register_command, base::LaunchOptions(), |
| 55 register_handle.Receive())) { |
| 56 int ret = 0; |
| 57 if (base::WaitForExitCodeWithTimeout( |
| 58 register_handle, &ret, |
| 59 base::TimeDelta::FromSeconds(kRegistrationTimeoutSeconds))) { |
| 60 if (ret == 0) { |
| 61 return true; |
| 62 } else { |
| 63 LOG(ERROR) << "Win8 registration using " |
| 64 << register_command.GetCommandLineString() |
| 65 << " failed with error code " << ret; |
| 66 } |
| 67 } else { |
| 68 LOG(ERROR) << "Win8 registration using " |
| 69 << register_command.GetCommandLineString() << " timed out."; |
| 70 } |
| 71 } |
| 72 |
| 73 PLOG(ERROR) << "Failed to launch Win8 registration utility using " |
| 74 << register_command.GetCommandLineString(); |
| 75 return false; |
| 76 } |
| 77 |
| 78 } // namespace win8 |
OLD | NEW |