helper.cc revision c5cede9ae108bb15f6b7a8aea21c7e1fefa2834c
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
3// found in the LICENSE file.
4
5#include "chrome/installer/util/helper.h"
6
7#include "base/files/file_path.h"
8#include "base/logging.h"
9#include "base/path_service.h"
10#include "chrome/installer/util/browser_distribution.h"
11#include "chrome/installer/util/install_util.h"
12#include "chrome/installer/util/installation_state.h"
13#include "chrome/installer/util/util_constants.h"
14
15namespace {
16
17base::FilePath GetChromeInstallBasePath(bool system,
18                                        BrowserDistribution* distribution,
19                                        const wchar_t* sub_path) {
20  base::FilePath install_path;
21  if (system) {
22    PathService::Get(base::DIR_PROGRAM_FILES, &install_path);
23  } else {
24    PathService::Get(base::DIR_LOCAL_APP_DATA, &install_path);
25  }
26
27  if (!install_path.empty()) {
28    install_path = install_path.Append(distribution->GetInstallSubDir());
29    install_path = install_path.Append(sub_path);
30  }
31
32  return install_path;
33}
34
35}  // namespace
36
37namespace installer {
38
39base::FilePath GetChromeInstallPath(bool system_install,
40                                    BrowserDistribution* dist) {
41  return GetChromeInstallBasePath(system_install, dist, kInstallBinaryDir);
42}
43
44base::FilePath GetChromeUserDataPath(BrowserDistribution* dist) {
45  return GetChromeInstallBasePath(false, dist, kInstallUserDataDir);
46}
47
48BrowserDistribution* GetBinariesDistribution(bool system_install) {
49  BrowserDistribution* dist = BrowserDistribution::GetDistribution();
50  ProductState state;
51
52  // If we're part of a multi-install, we need to poll using the multi-installer
53  // package's app guid rather than the browser's or Chrome Frame's app guid.
54  // If we can't read the app's state from the registry, assume it isn't
55  // multi-installed.
56  if (state.Initialize(system_install, dist) && state.is_multi_install()) {
57    return BrowserDistribution::GetSpecificDistribution(
58        BrowserDistribution::CHROME_BINARIES);
59  } else {
60    return dist;
61  }
62}
63
64std::wstring GetAppGuidForUpdates(bool system_install) {
65  return GetBinariesDistribution(system_install)->GetAppGuid();
66}
67
68}  // namespace installer.
69