summaryrefslogtreecommitdiffstats
path: root/apps/app_host/app_host_main.cc
blob: cf0fd265e5de09646884d69f83e63f8ec267c6af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <windows.h>

#include "apps/app_host/binaries_installer.h"
#include "apps/app_host/update.h"
#include "base/at_exit.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/process_util.h"
#include "chrome/installer/launcher_support/chrome_launcher_support.h"

int APIENTRY wWinMain(HINSTANCE, HINSTANCE, wchar_t*, int) {
  base::AtExitManager exit_manager;

  // Initialize the commandline singleton from the environment.
  CommandLine::Init(0, NULL);

  base::FilePath chrome_exe(chrome_launcher_support::GetAnyChromePath());
  if (chrome_exe.empty()) {
    LOG(INFO) << "No Chrome executable could be found. Let's install it.";
    HRESULT hr = app_host::InstallBinaries();
    if (FAILED(hr)) {
      LOG(ERROR) << "Failed to install the Chrome Binaries. Error: " << hr;
      return 1;
    } 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;
      }
    }
  }

  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;
}