diff options
-rw-r--r-- | chrome/installer/setup/uninstall.cc | 32 | ||||
-rw-r--r-- | chrome/installer/util/auto_launch_util.cc | 22 | ||||
-rw-r--r-- | chrome/installer/util/helper.cc | 36 | ||||
-rw-r--r-- | chrome/installer/util/helper.h | 10 | ||||
-rw-r--r-- | chrome/installer/util/product.cc | 4 | ||||
-rw-r--r-- | chrome/installer/util/product.h | 7 | ||||
-rw-r--r-- | chrome/installer/util/product_unittest.cc | 22 | ||||
-rw-r--r-- | chrome/installer/util/user_experiment.cc | 33 | ||||
-rw-r--r-- | chrome/installer/util/util_constants.cc | 1 | ||||
-rw-r--r-- | chrome/installer/util/util_constants.h | 1 |
10 files changed, 61 insertions, 107 deletions
diff --git a/chrome/installer/setup/uninstall.cc b/chrome/installer/setup/uninstall.cc index 9150214..e99914b 100644 --- a/chrome/installer/setup/uninstall.cc +++ b/chrome/installer/setup/uninstall.cc @@ -24,7 +24,7 @@ #include "base/win/shortcut.h" #include "base/win/windows_version.h" #include "chrome/common/chrome_constants.h" -#include "chrome/common/chrome_paths_internal.h" +#include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_result_codes.h" #include "chrome/installer/launcher_support/chrome_launcher_support.h" #include "chrome/installer/setup/install.h" @@ -388,20 +388,25 @@ DeleteResult DeleteEmptyDir(const base::FilePath& path) { return DELETE_FAILED; } +// Get the user data directory, which is *not* DIR_USER_DATA for Chrome Frame. +// TODO(grt): Remove Chrome Frame uninstall support when usage is low enough. base::FilePath GetUserDataDir(const Product& product) { - // Obtain the location of the user profile data. - base::FilePath user_data_dir = product.GetUserDataPath(); - LOG_IF(ERROR, user_data_dir.empty()) - << "Could not retrieve user's profile directory."; - - return user_data_dir; + base::FilePath path; + bool is_chrome_frame = product.is_chrome_frame(); + int key = is_chrome_frame ? base::DIR_LOCAL_APP_DATA : chrome::DIR_USER_DATA; + if (!PathService::Get(key, &path)) + return base::FilePath(); + if (is_chrome_frame) { + path = path.Append(product.distribution()->GetInstallSubDir()); + path = path.Append(chrome::kUserDataDirname); + } + return path; } // Creates a copy of the local state file and returns a path to the copy. base::FilePath BackupLocalStateFile(const base::FilePath& user_data_dir) { base::FilePath backup; - base::FilePath state_file( - user_data_dir.Append(chrome::kLocalStateFilename)); + base::FilePath state_file(user_data_dir.Append(chrome::kLocalStateFilename)); if (!base::CreateTemporaryFile(&backup)) LOG(ERROR) << "Failed to create temporary file for Local State."; else @@ -1327,7 +1332,14 @@ InstallStatus UninstallProduct(const InstallationState& original_state, // (aka non-multi) installation or we are the Chrome Binaries. base::FilePath user_data_dir(GetUserDataDir(product)); - base::FilePath backup_state_file(BackupLocalStateFile(user_data_dir)); + base::FilePath backup_state_file; + if (!user_data_dir.empty()) { + backup_state_file = BackupLocalStateFile(user_data_dir); + } else { + LOG(ERROR) << "Could not retrieve the user's profile directory."; + ret = installer::UNINSTALL_FAILED; + delete_profile = false; + } if (product.is_chrome_app_host()) { DeleteAppHostFilesAndFolders(installer_state, product_state->version()); diff --git a/chrome/installer/util/auto_launch_util.cc b/chrome/installer/util/auto_launch_util.cc index 6dd5d35..7ad2315 100644 --- a/chrome/installer/util/auto_launch_util.cc +++ b/chrome/installer/util/auto_launch_util.cc @@ -12,10 +12,9 @@ #include "base/strings/utf_string_conversions.h" #include "base/win/win_util.h" #include "chrome/common/chrome_constants.h" +#include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_version_info.h" -#include "chrome/installer/util/browser_distribution.h" -#include "chrome/installer/util/product.h" #include "chrome/installer/util/util_constants.h" #include "crypto/sha2.h" @@ -36,25 +35,15 @@ enum FlagSetting { FLAG_PRESERVE, // Preserve the value that the flag has currently. }; -// A helper function that takes a |profile_path| and builds a registry key +// A helper function that takes a |profile_directory| and builds a registry key // name to use when deciding where to read/write the auto-launch value // to/from. It takes into account the name of the profile (so that different // installations of Chrome don't conflict, and so the in the future different // profiles can be auto-launched (or not) separately). base::string16 ProfileToKeyName(const base::string16& profile_directory) { base::FilePath path; - const CommandLine& command_line = *CommandLine::ForCurrentProcess(); - if (command_line.HasSwitch(switches::kUserDataDir)) { - path = command_line.GetSwitchValuePath(switches::kUserDataDir); - } else { - // Get the path from the same source as the installer, to make sure there - // are no differences. - BrowserDistribution* distribution = - BrowserDistribution::GetSpecificDistribution( - BrowserDistribution::CHROME_BROWSER); - installer::Product product(distribution); - path = product.GetUserDataPath(); - } + const bool success = PathService::Get(chrome::DIR_USER_DATA, &path); + DCHECK(success); path = path.Append(profile_directory); std::string input(path.AsUTF8Unsafe()); @@ -212,8 +201,7 @@ void SetWillLaunchAtLogin(const base::FilePath& application_path, cmd_line += ASCIIToUTF16("\""); } - base::win::AddCommandToAutoRun( - HKEY_CURRENT_USER, key_name, cmd_line); + base::win::AddCommandToAutoRun(HKEY_CURRENT_USER, key_name, cmd_line); } else { base::win::RemoveCommandFromAutoRun(HKEY_CURRENT_USER, key_name); } diff --git a/chrome/installer/util/helper.cc b/chrome/installer/util/helper.cc index df63dc0..f76213d 100644 --- a/chrome/installer/util/helper.cc +++ b/chrome/installer/util/helper.cc @@ -12,39 +12,17 @@ #include "chrome/installer/util/installation_state.h" #include "chrome/installer/util/util_constants.h" -namespace { - -base::FilePath GetChromeInstallBasePath(bool system, - BrowserDistribution* distribution, - const wchar_t* sub_path) { - base::FilePath install_path; - if (system) { - PathService::Get(base::DIR_PROGRAM_FILES, &install_path); - } else { - PathService::Get(base::DIR_LOCAL_APP_DATA, &install_path); - } - - if (!install_path.empty()) { - install_path = install_path.Append(distribution->GetInstallSubDir()); - install_path = install_path.Append(sub_path); - } - - return install_path; -} - -} // namespace - namespace installer { base::FilePath GetChromeInstallPath(bool system_install, BrowserDistribution* dist) { - return GetChromeInstallBasePath(system_install, dist, kInstallBinaryDir); -} - -base::FilePath GetChromeUserDataPath(BrowserDistribution* dist) { - // TODO(msw): Remove this method and make callers use PathService directly to - // obtain the right DIR_USER_DATA. - return GetChromeInstallBasePath(false, dist, kInstallUserDataDir); + base::FilePath install_path; + int key = system_install ? base::DIR_PROGRAM_FILES : base::DIR_LOCAL_APP_DATA; + if (PathService::Get(key, &install_path)) { + install_path = install_path.Append(dist->GetInstallSubDir()); + install_path = install_path.Append(kInstallBinaryDir); + } + return install_path; } BrowserDistribution* GetBinariesDistribution(bool system_install) { diff --git a/chrome/installer/util/helper.h b/chrome/installer/util/helper.h index 152a160..940db44 100644 --- a/chrome/installer/util/helper.h +++ b/chrome/installer/util/helper.h @@ -22,14 +22,8 @@ namespace installer { // system_install: if true, the function returns system wide location // (ProgramFiles\Google). Otherwise it returns user specific // location (Document And Settings\<user>\Local Settings...) -base::FilePath GetChromeInstallPath(bool system_install, BrowserDistribution* dist); - -// Returns the path to the directory that holds the user data. This is always -// inside a user's local application data folder (e.g., "AppData\Local" or -// "Local Settings\Application Data" in %USERPROFILE%). Note that this is the -// default user data directory and does not take into account that it can be -// overriden with a command line parameter. -base::FilePath GetChromeUserDataPath(BrowserDistribution* dist); +base::FilePath GetChromeInstallPath(bool system_install, + BrowserDistribution* dist); // Returns the distribution corresponding to the current process's binaries. // In the case of a multi-install product, this will be the CHROME_BINARIES diff --git a/chrome/installer/util/product.cc b/chrome/installer/util/product.cc index 1d11a7e..7ade852 100644 --- a/chrome/installer/util/product.cc +++ b/chrome/installer/util/product.cc @@ -62,10 +62,6 @@ void Product::InitializeFromUninstallCommand( operations_->ReadOptions(uninstall_command, &options_); } -base::FilePath Product::GetUserDataPath() const { - return GetChromeUserDataPath(distribution_); -} - bool Product::LaunchChrome(const base::FilePath& application_path) const { bool success = !application_path.empty(); if (success) { diff --git a/chrome/installer/util/product.h b/chrome/installer/util/product.h index c9da906..a815fb2 100644 --- a/chrome/installer/util/product.h +++ b/chrome/installer/util/product.h @@ -81,13 +81,6 @@ class Product { return options_.erase(option) != 0; } - // Returns the path to the directory that holds the user data. This is always - // inside a user's local application data folder (e.g., "AppData\Local" or - // "Local Settings\Application Data" in %USERPROFILE%). Note that this is the - // default user data directory and does not take into account that it can be - // overriden with a command line parameter. - base::FilePath GetUserDataPath() const; - // Launches Chrome without waiting for it to exit. bool LaunchChrome(const base::FilePath& application_path) const; diff --git a/chrome/installer/util/product_unittest.cc b/chrome/installer/util/product_unittest.cc index fa4c27e..eabade7 100644 --- a/chrome/installer/util/product_unittest.cc +++ b/chrome/installer/util/product_unittest.cc @@ -5,8 +5,10 @@ #include "chrome/installer/util/product_unittest.h" #include "base/logging.h" +#include "base/path_service.h" #include "base/strings/utf_string_conversions.h" #include "base/test/test_reg_util_win.h" +#include "chrome/common/chrome_paths.h" #include "chrome/installer/util/chrome_frame_distribution.h" #include "chrome/installer/util/google_update_constants.h" #include "chrome/installer/util/installation_state.h" @@ -45,14 +47,7 @@ class ProductTest : public TestWithTempDirAndDeleteTempOverrideKeys { protected: }; -// This test is flaky on Win, see http://crbug.com/100567 -#if defined(OS_WIN) -#define MAYBE_ProductInstallBasic DISABLED_ProductInstallBasic -#else -#define MAYBE_ProductInstallBasic ProductInstallBasic -#endif - -TEST_F(ProductTest, MAYBE_ProductInstallBasic) { +TEST_F(ProductTest, ProductInstallBasic) { // TODO(tommi): We should mock this and use our mocked distribution. const bool multi_install = false; const bool system_level = true; @@ -70,17 +65,16 @@ TEST_F(ProductTest, MAYBE_ProductInstallBasic) { BrowserDistribution* distribution = product->distribution(); EXPECT_EQ(BrowserDistribution::CHROME_BROWSER, distribution->GetType()); - base::FilePath user_data(product->GetUserDataPath()); - EXPECT_FALSE(user_data.empty()); - EXPECT_NE(std::wstring::npos, - user_data.value().find(installer::kInstallUserDataDir)); + base::FilePath user_data_dir; + ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)); + EXPECT_FALSE(user_data_dir.empty()); base::FilePath program_files; - PathService::Get(base::DIR_PROGRAM_FILES, &program_files); + ASSERT_TRUE(PathService::Get(base::DIR_PROGRAM_FILES, &program_files)); // The User Data path should never be under program files, even though // system_level is true. EXPECT_EQ(std::wstring::npos, - user_data.value().find(program_files.value())); + user_data_dir.value().find(program_files.value())); // There should be no installed version in the registry. machine_state.Initialize(); diff --git a/chrome/installer/util/user_experiment.cc b/chrome/installer/util/user_experiment.cc index 73de5a6..68e4eac 100644 --- a/chrome/installer/util/user_experiment.cc +++ b/chrome/installer/util/user_experiment.cc @@ -11,6 +11,7 @@ #include "base/command_line.h" #include "base/files/file_path.h" +#include "base/path_service.h" #include "base/process/launch.h" #include "base/rand_util.h" #include "base/strings/string_number_conversions.h" @@ -20,6 +21,7 @@ #include "base/win/scoped_handle.h" #include "base/win/windows_version.h" #include "chrome/common/attrition_experiments.h" +#include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_result_codes.h" #include "chrome/common/chrome_switches.h" #include "chrome/installer/util/browser_distribution.h" @@ -85,11 +87,14 @@ int GetDirectoryWriteTimeInHours(const wchar_t* path) { return ::GetFileTime(file, NULL, NULL, &time) ? FileTimeToHours(time) : -1; } -// Returns the directory last-write time age in hours, relative to current -// time, so if it returns 14 it means that the directory was last written 14 -// hours ago. Returns -1 if there was an error retrieving the directory. -int GetDirectoryWriteAgeInHours(const wchar_t* path) { - int dir_time = GetDirectoryWriteTimeInHours(path); +// Returns the time in hours since the last write to the user data directory. +// A return value of 14 means that the directory was last written 14 hours ago. +// Returns -1 if there was an error retrieving the directory. +int GetUserDataDirectoryWriteAgeInHours() { + base::FilePath user_data_dir; + if (!PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) + return -1; + int dir_time = GetDirectoryWriteTimeInHours(user_data_dir.value().c_str()); if (dir_time < 0) return dir_time; FILETIME time; @@ -425,21 +430,17 @@ void LaunchBrowserUserExperiment(const CommandLine& base_cmd_line, return; } } - // Check browser usage inactivity by the age of the last-write time of the - // most recently-used chrome user data directory. - BrowserDistribution* dist = BrowserDistribution::GetSpecificDistribution( - BrowserDistribution::CHROME_BROWSER); - base::FilePath user_data_dir(GetChromeUserDataPath(dist)); - const bool experiment_enabled = false; - const int kThirtyDays = 30 * 24; - - int dir_age_hours = GetDirectoryWriteAgeInHours( - user_data_dir.value().c_str()); if (!experiment_enabled) { VLOG(1) << "Toast experiment is disabled."; return; - } else if (dir_age_hours < 0) { + } + + // Check browser usage inactivity by the age of the last-write time of the + // relevant chrome user data directory. + const int kThirtyDays = 30 * 24; + const int dir_age_hours = GetUserDataDirectoryWriteAgeInHours(); + if (dir_age_hours < 0) { // This means that we failed to find the user data dir. The most likely // cause is that this user has not ever used chrome at all which can // happen in a system-level install. diff --git a/chrome/installer/util/util_constants.cc b/chrome/installer/util/util_constants.cc index b4639e5..8800c5c 100644 --- a/chrome/installer/util/util_constants.cc +++ b/chrome/installer/util/util_constants.cc @@ -238,7 +238,6 @@ const wchar_t kGoogleChromeInstallSubDir2[] = L"Chrome"; const wchar_t kInstallBinaryDir[] = L"Application"; const wchar_t kInstallerDir[] = L"Installer"; const wchar_t kInstallTempDir[] = L"Temp"; -const wchar_t kInstallUserDataDir[] = L"User Data"; const wchar_t kLnkExt[] = L".lnk"; const wchar_t kNaClExe[] = L"nacl64.exe"; const wchar_t kSetupExe[] = L"setup.exe"; diff --git a/chrome/installer/util/util_constants.h b/chrome/installer/util/util_constants.h index d5d6281..09416e4 100644 --- a/chrome/installer/util/util_constants.h +++ b/chrome/installer/util/util_constants.h @@ -224,7 +224,6 @@ extern const wchar_t kGoogleChromeInstallSubDir2[]; extern const wchar_t kInstallBinaryDir[]; extern const wchar_t kInstallerDir[]; extern const wchar_t kInstallTempDir[]; -extern const wchar_t kInstallUserDataDir[]; extern const wchar_t kLnkExt[]; extern const wchar_t kNaClExe[]; extern const wchar_t kSetupExe[]; |