| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/downgrade/user_data_downgrade.h" | 5 #include "chrome/browser/downgrade/user_data_downgrade.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
| 25 #include "chrome/common/chrome_version.h" | 25 #include "chrome/common/chrome_version.h" |
| 26 #include "chrome/installer/util/google_update_constants.h" | 26 #include "chrome/installer/util/google_update_constants.h" |
| 27 #include "chrome/installer/util/install_util.h" | 27 #include "chrome/installer/util/install_util.h" |
| 28 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
| 29 | 29 |
| 30 namespace downgrade { | 30 namespace downgrade { |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 bool g_is_browser_test = false; | |
| 35 | |
| 36 // Return the disk cache dir override value if exists or empty path for default | 34 // Return the disk cache dir override value if exists or empty path for default |
| 37 // disk cache dir. | 35 // disk cache dir. |
| 38 base::FilePath GetDiskCacheDir() { | 36 base::FilePath GetDiskCacheDir() { |
| 39 base::FilePath disk_cache_dir; | 37 base::FilePath disk_cache_dir; |
| 40 policy::path_parser::CheckDiskCacheDirPolicy(&disk_cache_dir); | 38 policy::path_parser::CheckDiskCacheDirPolicy(&disk_cache_dir); |
| 41 if (disk_cache_dir.empty()) { | 39 if (disk_cache_dir.empty()) { |
| 42 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 40 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 43 disk_cache_dir = command_line->GetSwitchValuePath(switches::kDiskCacheDir); | 41 disk_cache_dir = command_line->GetSwitchValuePath(switches::kDiskCacheDir); |
| 44 } | 42 } |
| 45 if (disk_cache_dir.ReferencesParent()) | 43 if (disk_cache_dir.ReferencesParent()) |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 return base::Version( | 163 return base::Version( |
| 166 base::TrimWhitespaceASCII(last_version_str, base::TRIM_ALL) | 164 base::TrimWhitespaceASCII(last_version_str, base::TRIM_ALL) |
| 167 .as_string()); | 165 .as_string()); |
| 168 } | 166 } |
| 169 return base::Version(); | 167 return base::Version(); |
| 170 } | 168 } |
| 171 | 169 |
| 172 void DeleteMovedUserDataSoon() { | 170 void DeleteMovedUserDataSoon() { |
| 173 base::FilePath user_data_dir; | 171 base::FilePath user_data_dir; |
| 174 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | 172 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 175 if (g_is_browser_test) { | 173 content::BrowserThread::PostAfterStartupTask( |
| 176 // Delete task will always be posted and executed for browser test. | 174 FROM_HERE, content::BrowserThread::GetBlockingPool() |
| 177 content::BrowserThread::PostBlockingPoolTask( | 175 ->GetTaskRunnerWithShutdownBehavior( |
| 178 FROM_HERE, | 176 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN), |
| 179 base::Bind(&DeleteMovedUserData, user_data_dir, GetDiskCacheDir())); | 177 base::Bind(&DeleteMovedUserData, user_data_dir, GetDiskCacheDir())); |
| 180 } else { | |
| 181 content::BrowserThread::PostAfterStartupTask( | |
| 182 FROM_HERE, content::BrowserThread::GetBlockingPool() | |
| 183 ->GetTaskRunnerWithShutdownBehavior( | |
| 184 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN), | |
| 185 base::Bind(&DeleteMovedUserData, user_data_dir, GetDiskCacheDir())); | |
| 186 } | |
| 187 } | 178 } |
| 188 | 179 |
| 189 bool IsMSIInstall() { | 180 bool IsMSIInstall() { |
| 190 InstallLevel install_level = GetInstallLevel(); | 181 InstallLevel install_level = GetInstallLevel(); |
| 191 base::win::RegKey key; | 182 base::win::RegKey key; |
| 192 DWORD is_msi = 3; | 183 DWORD is_msi = 3; |
| 193 return install_level != UNKNOWN && | 184 return install_level != UNKNOWN && |
| 194 key.Open((install_level == SYSTEM_INSTALL) ? HKEY_LOCAL_MACHINE | 185 key.Open((install_level == SYSTEM_INSTALL) ? HKEY_LOCAL_MACHINE |
| 195 : HKEY_CURRENT_USER, | 186 : HKEY_CURRENT_USER, |
| 196 BrowserDistribution::GetDistribution()->GetStateKey().c_str(), | 187 BrowserDistribution::GetDistribution()->GetStateKey().c_str(), |
| 197 KEY_QUERY_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS && | 188 KEY_QUERY_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS && |
| 198 key.ReadValueDW(google_update::kRegMSIField, &is_msi) == | 189 key.ReadValueDW(google_update::kRegMSIField, &is_msi) == |
| 199 ERROR_SUCCESS && | 190 ERROR_SUCCESS && |
| 200 is_msi != 0; | 191 is_msi != 0; |
| 201 } | 192 } |
| 202 | 193 |
| 203 void SetSimulateDowngradeForTest(bool is_browser_test) { | |
| 204 g_is_browser_test = is_browser_test; | |
| 205 } | |
| 206 | |
| 207 } // namespace downgrade | 194 } // namespace downgrade |
| OLD | NEW |