Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1143)

Side by Side Diff: chrome/browser/component_updater/swiftshader_component_installer.cc

Issue 2266543002: Consistently use namespaced base::Version in component_updater code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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/component_updater/swiftshader_component_installer.h" 5 #include "chrome/browser/component_updater/swiftshader_component_installer.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 if (!PathService::Get(DIR_SWIFT_SHADER, &result)) 56 if (!PathService::Get(DIR_SWIFT_SHADER, &result))
57 NOTREACHED() << "Couldn't get SwiftShader directory."; 57 NOTREACHED() << "Couldn't get SwiftShader directory.";
58 return result; 58 return result;
59 } 59 }
60 60
61 // SwiftShader has version encoded in the path itself 61 // SwiftShader has version encoded in the path itself
62 // so we need to enumerate the directories to find the full path. 62 // so we need to enumerate the directories to find the full path.
63 // On success it returns something like: 63 // On success it returns something like:
64 // <profile>\AppData\Local\Google\Chrome\User Data\SwiftShader\10.3.44.555\. 64 // <profile>\AppData\Local\Google\Chrome\User Data\SwiftShader\10.3.44.555\.
65 bool GetLatestSwiftShaderDirectory(base::FilePath* result, 65 bool GetLatestSwiftShaderDirectory(base::FilePath* result,
66 Version* latest, 66 base::Version* latest,
67 std::vector<base::FilePath>* older_dirs) { 67 std::vector<base::FilePath>* older_dirs) {
68 base::FilePath base_dir = GetSwiftShaderBaseDirectory(); 68 base::FilePath base_dir = GetSwiftShaderBaseDirectory();
69 bool found = false; 69 bool found = false;
70 base::FileEnumerator file_enumerator( 70 base::FileEnumerator file_enumerator(
71 base_dir, false, base::FileEnumerator::DIRECTORIES); 71 base_dir, false, base::FileEnumerator::DIRECTORIES);
72 for (base::FilePath path = file_enumerator.Next(); !path.value().empty(); 72 for (base::FilePath path = file_enumerator.Next(); !path.value().empty();
73 path = file_enumerator.Next()) { 73 path = file_enumerator.Next()) {
74 Version version(path.BaseName().MaybeAsASCII()); 74 base::Version version(path.BaseName().MaybeAsASCII());
75 if (!version.IsValid()) 75 if (!version.IsValid())
76 continue; 76 continue;
77 if (version.CompareTo(*latest) > 0 && 77 if (version.CompareTo(*latest) > 0 &&
78 base::PathExists(path.Append(kSwiftShaderEglName)) && 78 base::PathExists(path.Append(kSwiftShaderEglName)) &&
79 base::PathExists(path.Append(kSwiftShaderGlesName))) { 79 base::PathExists(path.Append(kSwiftShaderGlesName))) {
80 if (found && older_dirs) 80 if (found && older_dirs)
81 older_dirs->push_back(*result); 81 older_dirs->push_back(*result);
82 *latest = version; 82 *latest = version;
83 *result = path; 83 *result = path;
84 found = true; 84 found = true;
85 } else { 85 } else {
86 if (older_dirs) 86 if (older_dirs)
87 older_dirs->push_back(path); 87 older_dirs->push_back(path);
88 } 88 }
89 } 89 }
90 return found; 90 return found;
91 } 91 }
92 92
93 void RegisterSwiftShaderWithChrome(const base::FilePath& path) { 93 void RegisterSwiftShaderWithChrome(const base::FilePath& path) {
94 DCHECK_CURRENTLY_ON(BrowserThread::UI); 94 DCHECK_CURRENTLY_ON(BrowserThread::UI);
95 GpuDataManager::GetInstance()->RegisterSwiftShaderPath(path); 95 GpuDataManager::GetInstance()->RegisterSwiftShaderPath(path);
96 } 96 }
97 97
98 class SwiftShaderComponentInstaller : public update_client::CrxInstaller { 98 class SwiftShaderComponentInstaller : public update_client::CrxInstaller {
99 public: 99 public:
100 explicit SwiftShaderComponentInstaller(const Version& version); 100 explicit SwiftShaderComponentInstaller(const base::Version& version);
101 101
102 // ComponentInstaller implementation: 102 // ComponentInstaller implementation:
103 void OnUpdateError(int error) override; 103 void OnUpdateError(int error) override;
104 104
105 bool Install(const base::DictionaryValue& manifest, 105 bool Install(const base::DictionaryValue& manifest,
106 const base::FilePath& unpack_path) override; 106 const base::FilePath& unpack_path) override;
107 107
108 bool GetInstalledFile(const std::string& file, 108 bool GetInstalledFile(const std::string& file,
109 base::FilePath* installed_file) override; 109 base::FilePath* installed_file) override;
110 110
111 bool Uninstall() override; 111 bool Uninstall() override;
112 112
113 private: 113 private:
114 ~SwiftShaderComponentInstaller() override {} 114 ~SwiftShaderComponentInstaller() override {}
115 115
116 Version current_version_; 116 base::Version current_version_;
117 }; 117 };
118 118
119 SwiftShaderComponentInstaller::SwiftShaderComponentInstaller( 119 SwiftShaderComponentInstaller::SwiftShaderComponentInstaller(
120 const Version& version) 120 const base::Version& version)
121 : current_version_(version) { 121 : current_version_(version) {
122 DCHECK(version.IsValid()); 122 DCHECK(version.IsValid());
123 } 123 }
124 124
125 void SwiftShaderComponentInstaller::OnUpdateError(int error) { 125 void SwiftShaderComponentInstaller::OnUpdateError(int error) {
126 NOTREACHED() << "SwiftShader update error: " << error; 126 NOTREACHED() << "SwiftShader update error: " << error;
127 } 127 }
128 128
129 bool SwiftShaderComponentInstaller::Install( 129 bool SwiftShaderComponentInstaller::Install(
130 const base::DictionaryValue& manifest, 130 const base::DictionaryValue& manifest,
131 const base::FilePath& unpack_path) { 131 const base::FilePath& unpack_path) {
132 std::string name; 132 std::string name;
133 manifest.GetStringASCII("name", &name); 133 manifest.GetStringASCII("name", &name);
134 if (name != kSwiftShaderManifestName) 134 if (name != kSwiftShaderManifestName)
135 return false; 135 return false;
136 std::string proposed_version; 136 std::string proposed_version;
137 manifest.GetStringASCII("version", &proposed_version); 137 manifest.GetStringASCII("version", &proposed_version);
138 Version version(proposed_version.c_str()); 138 base::Version version(proposed_version.c_str());
139 if (!version.IsValid()) 139 if (!version.IsValid())
140 return false; 140 return false;
141 if (current_version_.CompareTo(version) >= 0) 141 if (current_version_.CompareTo(version) >= 0)
142 return false; 142 return false;
143 if (!base::PathExists(unpack_path.Append(kSwiftShaderEglName)) || 143 if (!base::PathExists(unpack_path.Append(kSwiftShaderEglName)) ||
144 !base::PathExists(unpack_path.Append(kSwiftShaderGlesName))) 144 !base::PathExists(unpack_path.Append(kSwiftShaderGlesName)))
145 return false; 145 return false;
146 // Passed the basic tests. Time to install it. 146 // Passed the basic tests. Time to install it.
147 base::FilePath path = 147 base::FilePath path =
148 GetSwiftShaderBaseDirectory().AppendASCII(version.GetString()); 148 GetSwiftShaderBaseDirectory().AppendASCII(version.GetString());
(...skipping 13 matching lines...) Expand all
162 const std::string& file, 162 const std::string& file,
163 base::FilePath* installed_file) { 163 base::FilePath* installed_file) {
164 return false; 164 return false;
165 } 165 }
166 166
167 bool SwiftShaderComponentInstaller::Uninstall() { 167 bool SwiftShaderComponentInstaller::Uninstall() {
168 return false; 168 return false;
169 } 169 }
170 170
171 void FinishSwiftShaderUpdateRegistration(ComponentUpdateService* cus, 171 void FinishSwiftShaderUpdateRegistration(ComponentUpdateService* cus,
172 const Version& version) { 172 const base::Version& version) {
173 DCHECK_CURRENTLY_ON(BrowserThread::UI); 173 DCHECK_CURRENTLY_ON(BrowserThread::UI);
174 174
175 update_client::CrxComponent swiftshader; 175 update_client::CrxComponent swiftshader;
176 swiftshader.name = "Swift Shader"; 176 swiftshader.name = "Swift Shader";
177 swiftshader.installer = new SwiftShaderComponentInstaller(version); 177 swiftshader.installer = new SwiftShaderComponentInstaller(version);
178 swiftshader.version = version; 178 swiftshader.version = version;
179 swiftshader.pk_hash.assign(kSha2Hash, &kSha2Hash[sizeof(kSha2Hash)]); 179 swiftshader.pk_hash.assign(kSha2Hash, &kSha2Hash[sizeof(kSha2Hash)]);
180 if (!cus->RegisterComponent(swiftshader)) { 180 if (!cus->RegisterComponent(swiftshader)) {
181 NOTREACHED() << "SwiftShader component registration fail"; 181 NOTREACHED() << "SwiftShader component registration fail";
182 } 182 }
(...skipping 15 matching lines...) Expand all
198 void UpdateChecker::OnGpuInfoUpdate() { 198 void UpdateChecker::OnGpuInfoUpdate() {
199 GpuDataManager* gpu_data_manager = GpuDataManager::GetInstance(); 199 GpuDataManager* gpu_data_manager = GpuDataManager::GetInstance();
200 200
201 if (!gpu_data_manager->GpuAccessAllowed(NULL) || 201 if (!gpu_data_manager->GpuAccessAllowed(NULL) ||
202 gpu_data_manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL) || 202 gpu_data_manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL) ||
203 gpu_data_manager->ShouldUseSwiftShader()) { 203 gpu_data_manager->ShouldUseSwiftShader()) {
204 gpu_data_manager->RemoveObserver(this); 204 gpu_data_manager->RemoveObserver(this);
205 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 205 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
206 base::FilePath path = GetSwiftShaderBaseDirectory(); 206 base::FilePath path = GetSwiftShaderBaseDirectory();
207 207
208 Version version(kNullVersion); 208 base::Version version(kNullVersion);
209 GetLatestSwiftShaderDirectory(&path, &version, NULL); 209 GetLatestSwiftShaderDirectory(&path, &version, NULL);
210 210
211 BrowserThread::PostTask( 211 BrowserThread::PostTask(
212 BrowserThread::UI, 212 BrowserThread::UI,
213 FROM_HERE, 213 FROM_HERE,
214 base::Bind(&FinishSwiftShaderUpdateRegistration, cus_, version)); 214 base::Bind(&FinishSwiftShaderUpdateRegistration, cus_, version));
215 } 215 }
216 } 216 }
217 217
218 #if defined(ENABLE_SWIFTSHADER) 218 #if defined(ENABLE_SWIFTSHADER)
219 219
220 // Check if there already is a version of swiftshader installed, 220 // Check if there already is a version of swiftshader installed,
221 // and if so register it. 221 // and if so register it.
222 void RegisterSwiftShaderPath(ComponentUpdateService* cus) { 222 void RegisterSwiftShaderPath(ComponentUpdateService* cus) {
223 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 223 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
224 base::FilePath path = GetSwiftShaderBaseDirectory(); 224 base::FilePath path = GetSwiftShaderBaseDirectory();
225 if (!base::PathExists(path)) { 225 if (!base::PathExists(path)) {
226 if (!base::CreateDirectory(path)) { 226 if (!base::CreateDirectory(path)) {
227 NOTREACHED() << "Could not create SwiftShader directory."; 227 NOTREACHED() << "Could not create SwiftShader directory.";
228 return; 228 return;
229 } 229 }
230 } 230 }
231 231
232 Version version(kNullVersion); 232 base::Version version(kNullVersion);
233 std::vector<base::FilePath> older_dirs; 233 std::vector<base::FilePath> older_dirs;
234 if (GetLatestSwiftShaderDirectory(&path, &version, &older_dirs)) 234 if (GetLatestSwiftShaderDirectory(&path, &version, &older_dirs))
235 BrowserThread::PostTask(BrowserThread::UI, 235 BrowserThread::PostTask(BrowserThread::UI,
236 FROM_HERE, 236 FROM_HERE,
237 base::Bind(&RegisterSwiftShaderWithChrome, path)); 237 base::Bind(&RegisterSwiftShaderWithChrome, path));
238 238
239 UpdateChecker* update_checker = new UpdateChecker(cus); 239 UpdateChecker* update_checker = new UpdateChecker(cus);
240 GpuDataManager::GetInstance()->AddObserver(update_checker); 240 GpuDataManager::GetInstance()->AddObserver(update_checker);
241 update_checker->OnGpuInfoUpdate(); 241 update_checker->OnGpuInfoUpdate();
242 // We leak update_checker here, because it has to stick around for the life 242 // We leak update_checker here, because it has to stick around for the life
(...skipping 13 matching lines...) Expand all
256 256
257 void RegisterSwiftShaderComponent(ComponentUpdateService* cus) { 257 void RegisterSwiftShaderComponent(ComponentUpdateService* cus) {
258 #if defined(ENABLE_SWIFTSHADER) 258 #if defined(ENABLE_SWIFTSHADER)
259 BrowserThread::PostTask(BrowserThread::FILE, 259 BrowserThread::PostTask(BrowserThread::FILE,
260 FROM_HERE, 260 FROM_HERE,
261 base::Bind(&RegisterSwiftShaderPath, cus)); 261 base::Bind(&RegisterSwiftShaderPath, cus));
262 #endif 262 #endif
263 } 263 }
264 264
265 } // namespace component_updater 265 } // namespace component_updater
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698