| Index: chrome/app_installer/win/app_installer_util.cc
|
| diff --git a/chrome/app_installer/win/app_installer_main.cc b/chrome/app_installer/win/app_installer_util.cc
|
| similarity index 68%
|
| copy from chrome/app_installer/win/app_installer_main.cc
|
| copy to chrome/app_installer/win/app_installer_util.cc
|
| index 0a5ce8fbab08100be0c2d353bfe9cf882d0dc8de..5dc834482e4f098e481519a3623ff8e070b38f34 100644
|
| --- a/chrome/app_installer/win/app_installer_main.cc
|
| +++ b/chrome/app_installer/win/app_installer_util.cc
|
| @@ -2,18 +2,17 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| +#include "chrome/app_installer/win/app_installer_util.h"
|
| +
|
| #include <windows.h>
|
| -#include <initguid.h>
|
| #include <urlmon.h>
|
| #pragma comment(lib, "urlmon.lib")
|
|
|
| -#include "base/at_exit.h"
|
| #include "base/base_paths.h"
|
| #include "base/basictypes.h"
|
| #include "base/command_line.h"
|
| #include "base/files/file_util.h"
|
| #include "base/logging.h"
|
| -#include "base/logging_win.h"
|
| #include "base/memory/scoped_ptr.h"
|
| #include "base/path_service.h"
|
| #include "base/process/launch.h"
|
| @@ -29,33 +28,12 @@
|
|
|
| namespace app_installer {
|
|
|
| -enum ExitCode {
|
| - SUCCESS = 0,
|
| - COULD_NOT_GET_FILE_PATH,
|
| - COULD_NOT_READ_TAG,
|
| - COULD_NOT_PARSE_TAG,
|
| - INVALID_APP_ID,
|
| - EULA_CANCELLED,
|
| - COULD_NOT_FIND_CHROME,
|
| - COULD_NOT_GET_TMP_FILE_PATH,
|
| - FAILED_TO_DOWNLOAD_CHROME_SETUP,
|
| - FAILED_TO_LAUNCH_CHROME_SETUP,
|
| -};
|
| +const char kInstallChromeApp[] = "install-chrome-app";
|
|
|
| namespace {
|
|
|
| -// Log provider UUID. Required for logging to Sawbuck.
|
| -// {d82c3b59-bacd-4625-8282-4d570c4dad12}
|
| -DEFINE_GUID(kAppInstallerLogProvider,
|
| - 0xd82c3b59,
|
| - 0xbacd,
|
| - 0x4625,
|
| - 0x82, 0x82, 0x4d, 0x57, 0x0c, 0x4d, 0xad, 0x12);
|
| -
|
| const int kMaxTagLength = 4096;
|
|
|
| -const char kInstallChromeApp[] = "install-chrome-app";
|
| -
|
| const wchar_t kDownloadAndEulaPage[] =
|
| L"https://tools.google.com/dlpage/chromeappinstaller";
|
|
|
| @@ -108,6 +86,21 @@ class DownloadAndEulaHTMLDialog {
|
| DISALLOW_COPY_AND_ASSIGN(DownloadAndEulaHTMLDialog);
|
| };
|
|
|
| +bool IsStringPrintable(const std::string& s) {
|
| + return std::find_if_not(s.begin(), s.end(), isprint) == s.end();
|
| +}
|
| +
|
| +bool IsLegalDataKeyChar(int c) {
|
| + return isalnum(c) || c == '-' || c == '_' || c == '$';
|
| +}
|
| +
|
| +bool IsDataKeyValid(const std::string& key) {
|
| + return std::find_if_not(key.begin(), key.end(), IsLegalDataKeyChar) ==
|
| + key.end();
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| // Gets the tag attached to a file by dl.google.com. This uses the same format
|
| // as Omaha. Returns the empty string on failure.
|
| std::string GetTag(const base::FilePath& file_name_path) {
|
| @@ -132,19 +125,6 @@ std::string GetTag(const base::FilePath& file_name_path) {
|
| return std::string(tag_buffer.get(), tag_buffer_size - 1);
|
| }
|
|
|
| -bool IsStringPrintable(const std::string& s) {
|
| - return std::find_if_not(s.begin(), s.end(), isprint) == s.end();
|
| -}
|
| -
|
| -bool IsLegalDataKeyChar(int c) {
|
| - return isalnum(c) || c == '-' || c == '_' || c == '$';
|
| -}
|
| -
|
| -bool IsDataKeyValid(const std::string& key) {
|
| - return std::find_if_not(key.begin(), key.end(), IsLegalDataKeyChar) ==
|
| - key.end();
|
| -}
|
| -
|
| // Parses |tag| as key-value pairs and overwrites |parsed_pairs| with
|
| // the result. |tag| should be a '&'-delimited list of '='-separated
|
| // key-value pairs, e.g. "key1=value1&key2=value2".
|
| @@ -223,79 +203,4 @@ ExitCode GetChrome(bool is_canary) {
|
| return launch_success ? SUCCESS : FAILED_TO_LAUNCH_CHROME_SETUP;
|
| }
|
|
|
| -} // namespace
|
| -
|
| -extern "C"
|
| -int WINAPI wWinMain(HINSTANCE instance,
|
| - HINSTANCE prev_instance,
|
| - wchar_t* command_line,
|
| - int show_command) {
|
| - base::AtExitManager exit_manager;
|
| - base::CommandLine::Init(0, NULL);
|
| - logging::LogEventProvider::Initialize(kAppInstallerLogProvider);
|
| - logging::LoggingSettings settings;
|
| - settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
|
| - logging::InitLogging(settings);
|
| -
|
| - std::string app_id =
|
| - base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
|
| - switches::kAppId);
|
| - const char* sxs = installer::switches::kChromeSxS;
|
| - // --chrome-sxs on the command line takes precedence over chrome-sxs in the
|
| - // tag.
|
| - bool is_canary = base::CommandLine::ForCurrentProcess()->HasSwitch(sxs);
|
| -
|
| - // --app-id on the command line inhibits tag parsing altogether.
|
| - if (app_id.empty()) {
|
| - base::FilePath current_exe;
|
| - if (!PathService::Get(base::FILE_EXE, ¤t_exe))
|
| - return COULD_NOT_GET_FILE_PATH;
|
| -
|
| - // Get the tag added by dl.google.com. Note that this is passed in via URL
|
| - // parameters when requesting a file to download, so it must be validated
|
| - // before use.
|
| - std::string tag = GetTag(current_exe);
|
| - if (tag.empty())
|
| - return COULD_NOT_READ_TAG;
|
| -
|
| - DVLOG(1) << "Tag: " << tag;
|
| -
|
| - std::map<std::string, std::string> parsed_pairs;
|
| - if (!ParseTag(tag, &parsed_pairs))
|
| - return COULD_NOT_PARSE_TAG;
|
| -
|
| - auto result = parsed_pairs.find(switches::kAppId);
|
| - if (result != parsed_pairs.end())
|
| - app_id = result->second;
|
| -
|
| - if (!is_canary) {
|
| - result = parsed_pairs.find(sxs);
|
| - is_canary = result != parsed_pairs.end() && result->second == "1";
|
| - }
|
| - }
|
| -
|
| - if (!IsValidAppId(app_id))
|
| - return INVALID_APP_ID;
|
| -
|
| - base::FilePath chrome_path = GetChromeExePath(is_canary);
|
| - // If none found, show EULA, download, and install Chrome.
|
| - if (chrome_path.empty()) {
|
| - ExitCode get_chrome_result = GetChrome(is_canary);
|
| - if (get_chrome_result != SUCCESS)
|
| - return get_chrome_result;
|
| -
|
| - chrome_path = GetChromeExePath(is_canary);
|
| - if (chrome_path.empty())
|
| - return COULD_NOT_FIND_CHROME;
|
| - }
|
| -
|
| - base::CommandLine cmd(chrome_path);
|
| - cmd.AppendSwitchASCII(kInstallChromeApp, app_id);
|
| - DVLOG(1) << "Install command: " << cmd.GetCommandLineString();
|
| - bool launched = base::LaunchProcess(cmd, base::LaunchOptions(), NULL);
|
| - DVLOG(1) << "Launch " << (launched ? "success." : "failed.");
|
| -
|
| - return SUCCESS;
|
| -}
|
| -
|
| } // namespace app_installer
|
|
|