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

Unified Diff: chrome/browser/extensions/app_host/app_host_main.cc

Issue 12035043: Implementing app command to query EULA acceptance state for Chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Code complete: added app command install and app_host.exe wait/forward. Created 7 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/app_host/app_host_main.cc
diff --git a/chrome/browser/extensions/app_host/app_host_main.cc b/chrome/browser/extensions/app_host/app_host_main.cc
index 387a356e27597352037493a578bdc62e5c5cb836..811a7f1e2cbe25137770baaba07b3dc1096ade40 100644
--- a/chrome/browser/extensions/app_host/app_host_main.cc
+++ b/chrome/browser/extensions/app_host/app_host_main.cc
@@ -13,9 +13,58 @@
#include "chrome/browser/extensions/app_host/update.h"
#include "chrome/installer/launcher_support/chrome_launcher_support.h"
+namespace {
+
+HRESULT LaunchChromeAndProceed(const CommandLine& cmd_line) {
+ bool success = base::LaunchProcess(cmd_line, base::LaunchOptions(), NULL);
+ if (success) {
+ LOG(INFO) << "Delegated to Chrome executable at "
+ << cmd_line.GetProgram().value();
+ } else {
+ LOG(INFO) << "Failed to launch Chrome executable at "
+ << cmd_line.GetProgram().value();
+ }
+ return success ? S_OK : E_FAIL;
+}
+
+HRESULT LaunchChromeAndWait(const CommandLine& cmd_line) {
+ const DWORD kTimeOutInMilliseconds = 20000;
+ HANDLE proc = 0;
+ bool success = base::LaunchProcess(cmd_line, base::LaunchOptions(), &proc);
+ if (!success) {
+ LOG(INFO) << "Failed to launch Chrome executable at "
+ << cmd_line.GetProgram().value();
+ return E_FAIL;
+ }
+
+ LOG(INFO) << "Delegated to Chrome executable at "
+ << cmd_line.GetProgram().value();
+ DWORD res = WaitForSingleObject(proc, kTimeOutInMilliseconds);
+ if (res != WAIT_OBJECT_0) {
+ LOG(INFO) << " Failed to wailt.";
+ return E_FAIL;
+ }
+
+ if (!GetExitCodeProcess(proc, &res)) {
+ LOG(INFO) << " Failed to get exit code.";
+ return E_FAIL;
+ }
+ // Since we know that the process has terminated, we need not worry about
+ // the case where |res| should be interested as STILL_ACTIVE.
+
+ LOG(INFO) << " Exit code: " << res;
+ DCHECK(res != STILL_ACTIVE);
+ return res;
+}
+
+} // namespace
+
int APIENTRY wWinMain(HINSTANCE, HINSTANCE, wchar_t*, int) {
base::AtExitManager exit_manager;
+ // From chrome_switches.cc
+ const char kQueryEULAAcceptance[] = "query-eula-acceptance";
+
// Initialize the commandline singleton from the environment.
CommandLine::Init(0, NULL);
@@ -25,29 +74,33 @@ int APIENTRY wWinMain(HINSTANCE, HINSTANCE, wchar_t*, int) {
HRESULT hr = app_host::InstallBinaries();
if (FAILED(hr)) {
LOG(ERROR) << "Failed to install the Chrome Binaries. Error: " << hr;
- return 1;
+ return E_FAIL;
} else {
chrome_exe = chrome_launcher_support::GetAnyChromePath();
if (chrome_exe.empty()) {
LOG(ERROR) << "Failed to find the Chrome Binaries despite a "
<< "'successful' installation.";
- return 1;
+ return E_FAIL;
}
}
}
+ CommandLine command_line(*CommandLine::ForCurrentProcess());
CommandLine chrome_exe_command_line(chrome_exe);
- chrome_exe_command_line.AppendArguments(
- *CommandLine::ForCurrentProcess(), false);
- // Launch Chrome before checking for update, for faster user experience.
- bool launch_result = base::LaunchProcess(chrome_exe_command_line,
- base::LaunchOptions(), NULL);
- if (launch_result)
- LOG(INFO) << "Delegated to Chrome executable at " << chrome_exe.value();
- else
- LOG(INFO) << "Failed to launch Chrome executable at " << chrome_exe.value();
-
- app_host::EnsureAppHostUpToDate();
-
- return !launch_result;
+ chrome_exe_command_line.AppendArguments(command_line, false);
+
+ bool wait_for_chrome = false;
+ if (command_line.HasSwitch(kQueryEULAAcceptance))
+ wait_for_chrome = true;
+
+ if (!wait_for_chrome) {
+ // Launch Chrome before checking for update, for faster user experience.
+ HRESULT ret = LaunchChromeAndProceed(chrome_exe_command_line);
+ app_host::EnsureAppHostUpToDate();
+ return ret;
+
+ } else {
+ // We wait, so do not slow things more by trying to update app_host.exe.
+ return LaunchChromeAndWait(chrome_exe_command_line);
+ }
}

Powered by Google App Engine
This is Rietveld 408576698