helper.cc revision 5821806d5e7f356e8fa4b058a389a808ea183019
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/logging.h" 8#include "base/file_path.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/installation_state.h" 14#include "chrome/installer/util/install_util.h" 15#include "chrome/installer/util/util_constants.h" 16 17namespace { 18 19FilePath GetChromeInstallBasePath(bool system, 20 BrowserDistribution* distribution, 21 const wchar_t* sub_path) { 22 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 39namespace installer { 40 41FilePath GetChromeInstallPath(bool system_install, BrowserDistribution* dist) { 42 return GetChromeInstallBasePath(system_install, dist, kInstallBinaryDir); 43} 44 45void GetChromeUserDataPaths(BrowserDistribution* dist, 46 std::vector<FilePath>* paths) { 47 const bool has_metro_data = dist->CanSetAsDefault() && 48 base::win::GetVersion() >= base::win::VERSION_WIN8; 49 FilePath data_dir(GetChromeInstallBasePath(false, dist, kInstallUserDataDir)); 50 if (data_dir.empty()) { 51 paths->clear(); 52 } else { 53 paths->resize(has_metro_data ? 2 : 1); 54 (*paths)[0] = data_dir; 55 if (has_metro_data) { 56 (*paths)[1] = data_dir.DirName().Append( 57 chrome::kMetroChromeUserDataSubDir); 58 } 59 } 60 DCHECK(!paths->empty()); 61} 62 63BrowserDistribution* GetBinariesDistribution(bool system_install) { 64 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 65 ProductState state; 66 67 // If we're part of a multi-install, we need to poll using the multi-installer 68 // package's app guid rather than the browser's or Chrome Frame's app guid. 69 // If we can't read the app's state from the registry, assume it isn't 70 // multi-installed. 71 if (state.Initialize(system_install, dist) && state.is_multi_install()) { 72 return BrowserDistribution::GetSpecificDistribution( 73 BrowserDistribution::CHROME_BINARIES); 74 } else { 75 return dist; 76 } 77} 78 79std::wstring GetAppGuidForUpdates(bool system_install) { 80 return GetBinariesDistribution(system_install)->GetAppGuid(); 81} 82 83} // namespace installer. 84