Home | History | Annotate | Download | only in util
      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 "base/win/windows_version.h"
     11 #include "chrome/common/chrome_constants.h"
     12 #include "chrome/installer/util/browser_distribution.h"
     13 #include "chrome/installer/util/install_util.h"
     14 #include "chrome/installer/util/installation_state.h"
     15 #include "chrome/installer/util/util_constants.h"
     16 
     17 namespace {
     18 
     19 base::FilePath GetChromeInstallBasePath(bool system,
     20                                         BrowserDistribution* distribution,
     21                                         const wchar_t* sub_path) {
     22   base::FilePath install_path;
     23   if (system) {
     24     PathService::Get(base::DIR_PROGRAM_FILES, &install_path);
     25   } else {
     26     PathService::Get(base::DIR_LOCAL_APP_DATA, &install_path);
     27   }
     28 
     29   if (!install_path.empty()) {
     30     install_path = install_path.Append(distribution->GetInstallSubDir());
     31     install_path = install_path.Append(sub_path);
     32   }
     33 
     34   return install_path;
     35 }
     36 
     37 }  // namespace
     38 
     39 namespace installer {
     40 
     41 base::FilePath GetChromeInstallPath(bool system_install,
     42                                     BrowserDistribution* dist) {
     43   return GetChromeInstallBasePath(system_install, dist, kInstallBinaryDir);
     44 }
     45 
     46 void GetChromeUserDataPaths(BrowserDistribution* dist,
     47                             std::vector<base::FilePath>* paths) {
     48   const bool has_metro_data = dist->CanSetAsDefault() &&
     49       base::win::GetVersion() >= base::win::VERSION_WIN8;
     50   base::FilePath data_dir(GetChromeInstallBasePath(false, dist,
     51                                                    kInstallUserDataDir));
     52   if (data_dir.empty()) {
     53     paths->clear();
     54   } else {
     55     paths->resize(has_metro_data ? 2 : 1);
     56     (*paths)[0] = data_dir;
     57     if (has_metro_data) {
     58       (*paths)[1] = data_dir.DirName().Append(
     59           chrome::kMetroChromeUserDataSubDir);
     60     }
     61   }
     62   DCHECK(!paths->empty());
     63 }
     64 
     65 BrowserDistribution* GetBinariesDistribution(bool system_install) {
     66   BrowserDistribution* dist = BrowserDistribution::GetDistribution();
     67   ProductState state;
     68 
     69   // If we're part of a multi-install, we need to poll using the multi-installer
     70   // package's app guid rather than the browser's or Chrome Frame's app guid.
     71   // If we can't read the app's state from the registry, assume it isn't
     72   // multi-installed.
     73   if (state.Initialize(system_install, dist) && state.is_multi_install()) {
     74     return BrowserDistribution::GetSpecificDistribution(
     75         BrowserDistribution::CHROME_BINARIES);
     76   } else {
     77     return dist;
     78   }
     79 }
     80 
     81 std::wstring GetAppGuidForUpdates(bool system_install) {
     82   return GetBinariesDistribution(system_install)->GetAppGuid();
     83 }
     84 
     85 }  // namespace installer.
     86