OLD | NEW |
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 "base/base_paths.h" | 7 #include "base/base_paths.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/cpu.h" | 10 #include "base/cpu.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 base::FilePath base_dir = GetSwiftShaderBaseDirectory(); | 65 base::FilePath base_dir = GetSwiftShaderBaseDirectory(); |
66 bool found = false; | 66 bool found = false; |
67 base::FileEnumerator | 67 base::FileEnumerator |
68 file_enumerator(base_dir, false, base::FileEnumerator::DIRECTORIES); | 68 file_enumerator(base_dir, false, base::FileEnumerator::DIRECTORIES); |
69 for (base::FilePath path = file_enumerator.Next(); !path.value().empty(); | 69 for (base::FilePath path = file_enumerator.Next(); !path.value().empty(); |
70 path = file_enumerator.Next()) { | 70 path = file_enumerator.Next()) { |
71 Version version(path.BaseName().MaybeAsASCII()); | 71 Version version(path.BaseName().MaybeAsASCII()); |
72 if (!version.IsValid()) | 72 if (!version.IsValid()) |
73 continue; | 73 continue; |
74 if (version.CompareTo(*latest) > 0 && | 74 if (version.CompareTo(*latest) > 0 && |
75 file_util::PathExists(path.Append(kSwiftShaderEglName)) && | 75 base::PathExists(path.Append(kSwiftShaderEglName)) && |
76 file_util::PathExists(path.Append(kSwiftShaderGlesName))) { | 76 base::PathExists(path.Append(kSwiftShaderGlesName))) { |
77 if (found && older_dirs) | 77 if (found && older_dirs) |
78 older_dirs->push_back(*result); | 78 older_dirs->push_back(*result); |
79 *latest = version; | 79 *latest = version; |
80 *result = path; | 80 *result = path; |
81 found = true; | 81 found = true; |
82 } else { | 82 } else { |
83 if (older_dirs) | 83 if (older_dirs) |
84 older_dirs->push_back(path); | 84 older_dirs->push_back(path); |
85 } | 85 } |
86 } | 86 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 manifest.GetStringASCII("name", &name); | 128 manifest.GetStringASCII("name", &name); |
129 if (name != kSwiftShaderManifestName) | 129 if (name != kSwiftShaderManifestName) |
130 return false; | 130 return false; |
131 std::string proposed_version; | 131 std::string proposed_version; |
132 manifest.GetStringASCII("version", &proposed_version); | 132 manifest.GetStringASCII("version", &proposed_version); |
133 Version version(proposed_version.c_str()); | 133 Version version(proposed_version.c_str()); |
134 if (!version.IsValid()) | 134 if (!version.IsValid()) |
135 return false; | 135 return false; |
136 if (current_version_.CompareTo(version) >= 0) | 136 if (current_version_.CompareTo(version) >= 0) |
137 return false; | 137 return false; |
138 if (!file_util::PathExists(unpack_path.Append(kSwiftShaderEglName)) || | 138 if (!base::PathExists(unpack_path.Append(kSwiftShaderEglName)) || |
139 !file_util::PathExists(unpack_path.Append(kSwiftShaderGlesName))) | 139 !base::PathExists(unpack_path.Append(kSwiftShaderGlesName))) |
140 return false; | 140 return false; |
141 // Passed the basic tests. Time to install it. | 141 // Passed the basic tests. Time to install it. |
142 base::FilePath path = | 142 base::FilePath path = |
143 GetSwiftShaderBaseDirectory().AppendASCII(version.GetString()); | 143 GetSwiftShaderBaseDirectory().AppendASCII(version.GetString()); |
144 if (file_util::PathExists(path)) | 144 if (base::PathExists(path)) |
145 return false; | 145 return false; |
146 if (!base::Move(unpack_path, path)) | 146 if (!base::Move(unpack_path, path)) |
147 return false; | 147 return false; |
148 // Installation is done. Now tell the rest of chrome. | 148 // Installation is done. Now tell the rest of chrome. |
149 current_version_ = version; | 149 current_version_ = version; |
150 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 150 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
151 base::Bind(&RegisterSwiftShaderWithChrome, path)); | 151 base::Bind(&RegisterSwiftShaderWithChrome, path)); |
152 return true; | 152 return true; |
153 } | 153 } |
154 | 154 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 201 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
202 base::Bind(&FinishSwiftShaderUpdateRegistration, cus_, version)); | 202 base::Bind(&FinishSwiftShaderUpdateRegistration, cus_, version)); |
203 } | 203 } |
204 } | 204 } |
205 | 205 |
206 // Check if there already is a version of swiftshader installed, | 206 // Check if there already is a version of swiftshader installed, |
207 // and if so register it. | 207 // and if so register it. |
208 void RegisterSwiftShaderPath(ComponentUpdateService* cus) { | 208 void RegisterSwiftShaderPath(ComponentUpdateService* cus) { |
209 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 209 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
210 base::FilePath path = GetSwiftShaderBaseDirectory(); | 210 base::FilePath path = GetSwiftShaderBaseDirectory(); |
211 if (!file_util::PathExists(path)) { | 211 if (!base::PathExists(path)) { |
212 if (!file_util::CreateDirectory(path)) { | 212 if (!file_util::CreateDirectory(path)) { |
213 NOTREACHED() << "Could not create SwiftShader directory."; | 213 NOTREACHED() << "Could not create SwiftShader directory."; |
214 return; | 214 return; |
215 } | 215 } |
216 } | 216 } |
217 | 217 |
218 Version version(kNullVersion); | 218 Version version(kNullVersion); |
219 std::vector<base::FilePath> older_dirs; | 219 std::vector<base::FilePath> older_dirs; |
220 if (GetLatestSwiftShaderDirectory(&path, &version, &older_dirs)) | 220 if (GetLatestSwiftShaderDirectory(&path, &version, &older_dirs)) |
221 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 221 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
(...skipping 15 matching lines...) Expand all Loading... |
237 void RegisterSwiftShaderComponent(ComponentUpdateService* cus) { | 237 void RegisterSwiftShaderComponent(ComponentUpdateService* cus) { |
238 #if defined(ENABLE_SWIFTSHADER) | 238 #if defined(ENABLE_SWIFTSHADER) |
239 base::CPU cpu; | 239 base::CPU cpu; |
240 | 240 |
241 if (!cpu.has_sse2()) | 241 if (!cpu.has_sse2()) |
242 return; | 242 return; |
243 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 243 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
244 base::Bind(&RegisterSwiftShaderPath, cus)); | 244 base::Bind(&RegisterSwiftShaderPath, cus)); |
245 #endif | 245 #endif |
246 } | 246 } |
OLD | NEW |