Index: chrome/browser/component_updater/swiftshader_component_installer.cc |
diff --git a/chrome/browser/component_updater/swiftshader_component_installer.cc b/chrome/browser/component_updater/swiftshader_component_installer.cc |
index e4c410aeab2f28d4612bccf452c466a581cee8e7..e448dda12feb311119d07c35d512c5a061daf104 100644 |
--- a/chrome/browser/component_updater/swiftshader_component_installer.cc |
+++ b/chrome/browser/component_updater/swiftshader_component_installer.cc |
@@ -19,7 +19,6 @@ |
#include "base/strings/string_util.h" |
#include "base/values.h" |
#include "chrome/browser/component_updater/component_updater_service.h" |
-#include "chrome/common/chrome_paths.h" |
#include "content/public/browser/browser_thread.h" |
#include "content/public/browser/gpu_data_manager.h" |
#include "content/public/browser/gpu_data_manager_observer.h" |
@@ -46,28 +45,25 @@ const base::FilePath::CharType kSwiftShaderGlesName[] = |
const char kSwiftShaderManifestName[] = "SwiftShader"; |
+#if defined(ENABLE_SWIFTSHADER) |
const base::FilePath::CharType kSwiftShaderBaseDirectory[] = |
FILE_PATH_LITERAL("SwiftShader"); |
+#endif // ENABLE_SWIFTSHADER |
// If we don't have a SwiftShader component, this is the version we claim. |
const char kNullVersion[] = "0.0.0.0"; |
-// The base directory on windows looks like: |
-// <profile>\AppData\Local\Google\Chrome\User Data\SwiftShader\. |
-base::FilePath GetSwiftShaderBaseDirectory() { |
- base::FilePath result; |
- PathService::Get(chrome::DIR_USER_DATA, &result); |
- return result.Append(kSwiftShaderBaseDirectory); |
-} |
- |
// SwiftShader has version encoded in the path itself |
// so we need to enumerate the directories to find the full path. |
// On success it returns something like: |
// <profile>\AppData\Local\Google\Chrome\User Data\SwiftShader\10.3.44.555\. |
-bool GetLatestSwiftShaderDirectory(base::FilePath* result, |
+// Return true if a SwiftShader directory newer than |latest| was found. |
+// |result| must be initially an empty directory. |
+bool GetLatestSwiftShaderDirectory(const base::FilePath& base_dir, |
+ base::FilePath* result, |
Version* latest, |
std::vector<base::FilePath>* older_dirs) { |
- base::FilePath base_dir = GetSwiftShaderBaseDirectory(); |
+ DCHECK(result->empty()); |
bool found = false; |
base::FileEnumerator file_enumerator( |
base_dir, false, base::FileEnumerator::DIRECTORIES); |
@@ -79,7 +75,7 @@ bool GetLatestSwiftShaderDirectory(base::FilePath* result, |
if (version.CompareTo(*latest) > 0 && |
base::PathExists(path.Append(kSwiftShaderEglName)) && |
base::PathExists(path.Append(kSwiftShaderGlesName))) { |
- if (found && older_dirs) |
+ if (found && older_dirs && !result->empty()) |
older_dirs->push_back(*result); |
*latest = version; |
*result = path; |
@@ -99,7 +95,8 @@ void RegisterSwiftShaderWithChrome(const base::FilePath& path) { |
class SwiftShaderComponentInstaller : public ComponentInstaller { |
public: |
- explicit SwiftShaderComponentInstaller(const Version& version); |
+ explicit SwiftShaderComponentInstaller(const base::FilePath& base_dir, |
+ const Version& version); |
virtual ~SwiftShaderComponentInstaller() {} |
@@ -112,12 +109,15 @@ class SwiftShaderComponentInstaller : public ComponentInstaller { |
base::FilePath* installed_file) OVERRIDE; |
private: |
+ const base::FilePath base_dir_; |
Version current_version_; |
}; |
SwiftShaderComponentInstaller::SwiftShaderComponentInstaller( |
+ const base::FilePath& base_dir, |
const Version& version) |
- : current_version_(version) { |
+ : base_dir_(base_dir), |
+ current_version_(version) { |
DCHECK(version.IsValid()); |
} |
@@ -143,8 +143,7 @@ bool SwiftShaderComponentInstaller::Install( |
!base::PathExists(unpack_path.Append(kSwiftShaderGlesName))) |
return false; |
// Passed the basic tests. Time to install it. |
- base::FilePath path = |
- GetSwiftShaderBaseDirectory().AppendASCII(version.GetString()); |
+ base::FilePath path = base_dir_.AppendASCII(version.GetString()); |
if (base::PathExists(path)) |
return false; |
if (!base::Move(unpack_path, path)) |
@@ -163,13 +162,14 @@ bool SwiftShaderComponentInstaller::GetInstalledFile( |
return false; |
} |
-void FinishSwiftShaderUpdateRegistration(ComponentUpdateService* cus, |
+void FinishSwiftShaderUpdateRegistration(const base::FilePath& base_dir, |
+ ComponentUpdateService* cus, |
const Version& version) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
CrxComponent swiftshader; |
swiftshader.name = "Swift Shader"; |
- swiftshader.installer = new SwiftShaderComponentInstaller(version); |
+ swiftshader.installer = new SwiftShaderComponentInstaller(base_dir, version); |
swiftshader.version = version; |
swiftshader.pk_hash.assign(kSha2Hash, &kSha2Hash[sizeof(kSha2Hash)]); |
if (cus->RegisterComponent(swiftshader) != ComponentUpdateService::kOk) { |
@@ -179,15 +179,20 @@ void FinishSwiftShaderUpdateRegistration(ComponentUpdateService* cus, |
class UpdateChecker : public content::GpuDataManagerObserver { |
public: |
- explicit UpdateChecker(ComponentUpdateService* cus); |
+ explicit UpdateChecker(ComponentUpdateService* cus, |
+ const base::FilePath& base_dir); |
virtual void OnGpuInfoUpdate() OVERRIDE; |
private: |
ComponentUpdateService* cus_; |
+ const base::FilePath base_dir_; |
}; |
-UpdateChecker::UpdateChecker(ComponentUpdateService* cus) : cus_(cus) { |
+UpdateChecker::UpdateChecker(ComponentUpdateService* cus, |
+ const base::FilePath& base_dir) |
+ : cus_(cus), |
+ base_dir_(base_dir) { |
} |
void UpdateChecker::OnGpuInfoUpdate() { |
@@ -198,15 +203,16 @@ void UpdateChecker::OnGpuInfoUpdate() { |
gpu_data_manager->ShouldUseSwiftShader()) { |
gpu_data_manager->RemoveObserver(this); |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
- base::FilePath path = GetSwiftShaderBaseDirectory(); |
+ base::FilePath latest_dir; |
Version version(kNullVersion); |
- GetLatestSwiftShaderDirectory(&path, &version, NULL); |
+ GetLatestSwiftShaderDirectory(base_dir_, &latest_dir, &version, NULL); |
BrowserThread::PostTask( |
BrowserThread::UI, |
FROM_HERE, |
- base::Bind(&FinishSwiftShaderUpdateRegistration, cus_, version)); |
+ base::Bind(&FinishSwiftShaderUpdateRegistration, base_dir_, cus_, |
+ version)); |
} |
} |
@@ -214,24 +220,27 @@ void UpdateChecker::OnGpuInfoUpdate() { |
// Check if there already is a version of swiftshader installed, |
// and if so register it. |
-void RegisterSwiftShaderPath(ComponentUpdateService* cus) { |
+void RegisterSwiftShaderPath(ComponentUpdateService* cus, |
+ const base::FilePath& user_data_dir) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
- base::FilePath path = GetSwiftShaderBaseDirectory(); |
- if (!base::PathExists(path)) { |
- if (!base::CreateDirectory(path)) { |
+ base::FilePath base_dir = user_data_dir.Append(kSwiftShaderBaseDirectory); |
+ if (!base::PathExists(base_dir)) { |
+ if (!base::CreateDirectory(base_dir)) { |
NOTREACHED() << "Could not create SwiftShader directory."; |
return; |
} |
} |
+ base::FilePath latest_dir; |
Version version(kNullVersion); |
std::vector<base::FilePath> older_dirs; |
- if (GetLatestSwiftShaderDirectory(&path, &version, &older_dirs)) |
+ if (GetLatestSwiftShaderDirectory(&latest_dir, &version, &older_dirs)) |
BrowserThread::PostTask(BrowserThread::UI, |
FROM_HERE, |
- base::Bind(&RegisterSwiftShaderWithChrome, path)); |
+ base::Bind(&RegisterSwiftShaderWithChrome, |
+ latest_dir)); |
- UpdateChecker* update_checker = new UpdateChecker(cus); |
+ UpdateChecker* update_checker = new UpdateChecker(cus, base_dir); |
GpuDataManager::GetInstance()->AddObserver(update_checker); |
update_checker->OnGpuInfoUpdate(); |
// We leak update_checker here, because it has to stick around for the life |
@@ -249,7 +258,8 @@ void RegisterSwiftShaderPath(ComponentUpdateService* cus) { |
} // namespace |
-void RegisterSwiftShaderComponent(ComponentUpdateService* cus) { |
+void RegisterSwiftShaderComponent(ComponentUpdateService* cus, |
+ const base::FilePath& user_data_dir) { |
#if defined(ENABLE_SWIFTSHADER) |
base::CPU cpu; |