Chromium Code Reviews| 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 "base/at_exit.h" | 5 #include "base/at_exit.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/process_util.h" | 9 #include "base/process_util.h" |
| 10 #include "base/string16.h" | |
|
erikwright (departed)
2012/09/13 01:13:44
do you still need this?
huangs
2012/09/13 04:40:47
Nope. Deleted.
| |
| 11 #include "base/version.h" | |
| 12 #include "chrome/browser/extensions/app_host/app_host_upgrade.h" | |
| 10 #include "chrome/browser/extensions/app_host/binaries_installer.h" | 13 #include "chrome/browser/extensions/app_host/binaries_installer.h" |
| 11 #include "chrome/installer/launcher_support/chrome_launcher_support.h" | 14 #include "chrome/installer/launcher_support/chrome_launcher_support.h" |
| 12 | 15 |
| 13 int main(int /* argc */, char* /* argv[] */) { | 16 int main(int /* argc */, char* /* argv[] */) { |
| 17 using namespace app_host; | |
| 18 using namespace chrome_launcher_support; | |
| 14 base::AtExitManager exit_manager; | 19 base::AtExitManager exit_manager; |
| 15 | 20 |
| 16 // Initialize the commandline singleton from the environment. | 21 // Initialize the commandline singleton from the environment. |
| 17 CommandLine::Init(0, NULL); | 22 CommandLine::Init(0, NULL); |
| 18 | 23 |
| 19 FilePath chrome_exe(chrome_launcher_support::GetAnyChromePath()); | 24 FilePath chrome_exe(GetAnyChromePath()); |
| 20 | 25 |
| 21 if (chrome_exe.empty()) { | 26 if (chrome_exe.empty()) { |
| 22 LOG(INFO) << "No Chrome executable could be found. Let's install it."; | 27 LOG(INFO) << "No Chrome executable could be found. Let's install it."; |
| 23 HRESULT hr = app_host::InstallBinaries(); | 28 HRESULT hr = app_host::InstallBinaries(); |
| 24 if (FAILED(hr)) { | 29 if (FAILED(hr)) { |
| 25 LOG(ERROR) << "Failed to install the Chrome Binaries. Error: " << hr; | 30 LOG(ERROR) << "Failed to install the Chrome Binaries. Error: " << hr; |
| 26 return 1; | 31 return 1; |
| 27 } else { | 32 } else { |
| 28 chrome_exe = chrome_launcher_support::GetAnyChromePath(); | 33 chrome_exe = GetAnyChromePath(); |
| 29 if (chrome_exe.empty()) { | 34 if (chrome_exe.empty()) { |
| 30 LOG(ERROR) << "Failed to find the Chrome Binaries despite a " | 35 LOG(ERROR) << "Failed to find the Chrome Binaries despite a " |
| 31 << "'successful' installation."; | 36 << "'successful' installation."; |
| 32 return 1; | 37 return 1; |
| 33 } | 38 } |
| 34 } | 39 } |
| 35 } | 40 } |
| 36 | 41 |
| 37 CommandLine chrome_exe_command_line(chrome_exe); | 42 CommandLine chrome_exe_command_line(chrome_exe); |
| 38 chrome_exe_command_line.AppendArguments( | 43 chrome_exe_command_line.AppendArguments( |
| 39 *CommandLine::ForCurrentProcess(), false); | 44 *CommandLine::ForCurrentProcess(), false); |
| 40 | 45 |
| 41 if (base::LaunchProcess(chrome_exe_command_line, | 46 // Launch Chrome before checking for updates, for faster user experience. |
| 42 base::LaunchOptions(), | 47 bool launch_result = base::LaunchProcess(chrome_exe_command_line, |
| 43 NULL)) { | 48 base::LaunchOptions(), |
| 49 NULL); | |
| 50 if (launch_result) { | |
| 44 LOG(INFO) << "Delegated to Chrome executable at " << chrome_exe.value(); | 51 LOG(INFO) << "Delegated to Chrome executable at " << chrome_exe.value(); |
| 45 return 0; | |
| 46 } else { | 52 } else { |
| 47 LOG(INFO) << "Failed to launch Chrome executable at " << chrome_exe.value(); | 53 LOG(INFO) << "Failed to launch Chrome executable at " << chrome_exe.value(); |
| 48 return 1; | |
| 49 } | 54 } |
| 55 | |
| 56 // If system-level Chrome Binary is installed, and if its version is | |
| 57 // newer than App Host's, then upgrade App Host by calling setup.exe. | |
| 58 Version chrome_binaries_version; | |
| 59 if (GetAppVersionForInstallationLevel(kMultiInstallAppGuid, | |
| 60 true, // System-level. | |
| 61 &chrome_binaries_version)) { | |
| 62 Version app_host_version; | |
| 63 if (GetAppVersionForInstallationLevel(kChromeAppHostAppGuid, | |
| 64 false, // User-level. | |
| 65 &app_host_version)) { | |
| 66 LOG(INFO) << "App Host version: " << app_host_version.GetString(); | |
|
erikwright (departed)
2012/09/13 01:13:44
Remove these two log statements, though it would b
huangs
2012/09/13 04:40:47
Done.
| |
| 67 LOG(INFO) << "Chrome binaries version: " << | |
| 68 chrome_binaries_version.GetString(); | |
| 69 if (app_host_version.IsOlderThan(chrome_binaries_version.GetString())) { | |
| 70 LOG(INFO) << "App Host out of date -- running setup.exe to upgrade"; | |
| 71 if (!UpgradeAppHost(true)) { // Use system-level setup.exe | |
|
erikwright (departed)
2012/09/13 01:13:44
No need for UpgradeAppHost to take a parameter. It
huangs
2012/09/13 04:40:47
I did this to make the routine generic and dumb, s
| |
| 72 LOG(ERROR) << "Failed to upgrade App Host"; | |
| 73 } | |
| 74 } | |
| 75 } else { | |
| 76 LOG(INFO) << "Failed to get App Host version"; | |
| 77 } | |
| 78 } // Else there is no system-level Chrome, so do nothing. | |
| 79 | |
| 80 return launch_result ? 0 : 1; | |
| 50 } | 81 } |
| OLD | NEW |