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

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

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

Powered by Google App Engine
This is Rietveld 408576698