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/pnacl/pnacl_component_installer.h" | 5 #include "chrome/browser/component_updater/pnacl/pnacl_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/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/json/json_file_value_serializer.h" | 13 #include "base/json/json_file_value_serializer.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/path_service.h" | 15 #include "base/path_service.h" |
16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
17 #include "base/values.h" | 17 #include "base/values.h" |
18 #include "base/version.h" | 18 #include "base/version.h" |
19 #include "base/win/windows_version.h" | 19 #include "base/win/windows_version.h" |
20 #include "build/build_config.h" | 20 #include "build/build_config.h" |
21 #include "chrome/browser/component_updater/component_updater_service.h" | 21 #include "chrome/browser/component_updater/component_updater_service.h" |
22 #include "chrome/common/chrome_paths.h" | 22 #include "chrome/common/chrome_paths.h" |
23 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
| 24 #include "chrome/common/omaha_query_params.h" |
24 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
25 | 26 |
| 27 using chrome::OmahaQueryParams; |
26 using content::BrowserThread; | 28 using content::BrowserThread; |
27 | 29 |
28 namespace { | 30 namespace { |
29 | 31 |
30 // If PNaCl isn't installed yet, but a user is running chrome with | 32 // If PNaCl isn't installed yet, but a user is running chrome with |
31 // --enable-pnacl, this is the amount of time to wait before starting | 33 // --enable-pnacl, this is the amount of time to wait before starting |
32 // a background install. | 34 // a background install. |
33 const int kInitialDelaySeconds = 10; | 35 const int kInitialDelaySeconds = 10; |
34 | 36 |
35 // One of the Pnacl component files, for checking that expected files exist. | 37 // One of the Pnacl component files, for checking that expected files exist. |
36 // TODO(jvoung): perhaps replace this with a list of the expected files in the | 38 // TODO(jvoung): perhaps replace this with a list of the expected files in the |
37 // manifest.json. Use that to check that everything is unpacked. | 39 // manifest.json. Use that to check that everything is unpacked. |
38 // However, that would make startup detection even slower (need to check for | 40 // However, that would make startup detection even slower (need to check for |
39 // more than one file!). | 41 // more than one file!). |
40 const char kPnaclCompilerFileName[] = "llc_nexe"; | 42 const char kPnaclCompilerFileName[] = "llc_nexe"; |
41 | 43 |
42 // Name of the Pnacl component specified in the manifest. | 44 // Name of the Pnacl component specified in the manifest. |
43 const char kPnaclManifestNamePrefix[] = "PNaCl"; | 45 const char kPnaclManifestNamePrefix[] = "PNaCl"; |
44 | 46 |
45 // Returns the name of the Pnacl architecture supported by an install. | 47 // Sanitize characters from Pnacl Arch value so that they can be used |
46 // NOTE: this is independent of the Omaha "arch" query parameter. | |
47 const char* PnaclArch() { | |
48 #if defined(ARCH_CPU_X86_FAMILY) | |
49 #if defined(ARCH_CPU_X86_64) | |
50 return "x86-64"; | |
51 #elif defined(OS_WIN) | |
52 bool x86_64 = (base::win::OSInfo::GetInstance()->wow64_status() == | |
53 base::win::OSInfo::WOW64_ENABLED); | |
54 return x86_64 ? "x86-64" : "x86-32"; | |
55 #else | |
56 return "x86-32"; | |
57 #endif | |
58 #elif defined(ARCH_CPU_ARMEL) | |
59 return "arm"; | |
60 #elif defined(ARCH_CPU_MIPSEL) | |
61 return "mips32"; | |
62 #else | |
63 #error "Add support for your architecture to Pnacl Component Installer." | |
64 #endif | |
65 } | |
66 | |
67 // Sanitize characters given by PnaclArch so that they can be used | |
68 // in path names. This should only be characters in the set: [a-z0-9_]. | 48 // in path names. This should only be characters in the set: [a-z0-9_]. |
69 // Keep in sync with chrome/browser/nacl_host/pnacl_file_host. | 49 // Keep in sync with chrome/browser/nacl_host/pnacl_file_host. |
70 std::string SanitizeForPath(const std::string& input) { | 50 std::string SanitizeForPath(const std::string& input) { |
71 std::string result; | 51 std::string result; |
72 ReplaceChars(input, "-", "_", &result); | 52 ReplaceChars(input, "-", "_", &result); |
73 return result; | 53 return result; |
74 } | 54 } |
75 | 55 |
76 // Set the component's hash to the arch-specific PNaCl package. | 56 // Set the component's hash to the arch-specific PNaCl package. |
77 void SetPnaclHash(CrxComponent* component) { | 57 void SetPnaclHash(CrxComponent* component) { |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 manifest->GetStringASCII("version", &proposed_version); | 193 manifest->GetStringASCII("version", &proposed_version); |
214 Version version(proposed_version.c_str()); | 194 Version version(proposed_version.c_str()); |
215 if (!version.IsValid()) { | 195 if (!version.IsValid()) { |
216 LOG(WARNING) << "'version' field in manifest is invalid " | 196 LOG(WARNING) << "'version' field in manifest is invalid " |
217 << version.GetString(); | 197 << version.GetString(); |
218 return false; | 198 return false; |
219 } | 199 } |
220 | 200 |
221 std::string arch; | 201 std::string arch; |
222 pnacl_manifest->GetStringASCII("pnacl-arch", &arch); | 202 pnacl_manifest->GetStringASCII("pnacl-arch", &arch); |
223 if (arch.compare(PnaclArch()) != 0) { | 203 if (arch.compare(OmahaQueryParams::getNaclArch()) != 0) { |
224 LOG(WARNING) << "'pnacl-arch' field in manifest is invalid (" | 204 LOG(WARNING) << "'pnacl-arch' field in manifest is invalid (" |
225 << arch << " vs " << PnaclArch() << ")"; | 205 << arch << " vs " << OmahaQueryParams::getNaclArch() << ")"; |
226 return false; | 206 return false; |
227 } | 207 } |
228 | 208 |
229 *version_out = version; | 209 *version_out = version; |
230 return true; | 210 return true; |
231 } | 211 } |
232 | 212 |
233 class PnaclComponentInstaller : public ComponentInstaller { | 213 class PnaclComponentInstaller : public ComponentInstaller { |
234 public: | 214 public: |
235 explicit PnaclComponentInstaller(const Version& version); | 215 explicit PnaclComponentInstaller(const Version& version); |
(...skipping 16 matching lines...) Expand all Loading... |
252 | 232 |
253 void PnaclComponentInstaller::OnUpdateError(int error) { | 233 void PnaclComponentInstaller::OnUpdateError(int error) { |
254 NOTREACHED() << "Pnacl update error: " << error; | 234 NOTREACHED() << "Pnacl update error: " << error; |
255 } | 235 } |
256 | 236 |
257 namespace { | 237 namespace { |
258 | 238 |
259 bool PathContainsPnacl(const base::FilePath& base_path) { | 239 bool PathContainsPnacl(const base::FilePath& base_path) { |
260 // Check that at least one of the compiler files exists, for the current ISA. | 240 // Check that at least one of the compiler files exists, for the current ISA. |
261 std::string expected_filename("pnacl_public_"); | 241 std::string expected_filename("pnacl_public_"); |
262 std::string arch = PnaclArch(); | 242 std::string arch = OmahaQueryParams::getNaclArch(); |
263 expected_filename = expected_filename + SanitizeForPath(arch) + | 243 expected_filename = expected_filename + SanitizeForPath(arch) + |
264 "_" + kPnaclCompilerFileName; | 244 "_" + kPnaclCompilerFileName; |
265 return file_util::PathExists(base_path.AppendASCII(expected_filename)); | 245 return file_util::PathExists(base_path.AppendASCII(expected_filename)); |
266 } | 246 } |
267 | 247 |
268 } // namespace | 248 } // namespace |
269 | 249 |
270 bool PnaclComponentInstaller::Install(base::DictionaryValue* manifest, | 250 bool PnaclComponentInstaller::Install(base::DictionaryValue* manifest, |
271 const base::FilePath& unpack_path) { | 251 const base::FilePath& unpack_path) { |
272 scoped_ptr<base::DictionaryValue> pnacl_manifest( | 252 scoped_ptr<base::DictionaryValue> pnacl_manifest( |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 void RegisterPnaclComponent(ComponentUpdateService* cus, | 370 void RegisterPnaclComponent(ComponentUpdateService* cus, |
391 const CommandLine& command_line) { | 371 const CommandLine& command_line) { |
392 // Only register when given the right flag. This is important since | 372 // Only register when given the right flag. This is important since |
393 // we do an early component updater check above (in DoCheckForUpdate). | 373 // we do an early component updater check above (in DoCheckForUpdate). |
394 if (command_line.HasSwitch(switches::kEnablePnacl)) { | 374 if (command_line.HasSwitch(switches::kEnablePnacl)) { |
395 BrowserThread::PostTask( | 375 BrowserThread::PostTask( |
396 BrowserThread::FILE, FROM_HERE, | 376 BrowserThread::FILE, FROM_HERE, |
397 base::Bind(&StartPnaclUpdateRegistration, cus)); | 377 base::Bind(&StartPnaclUpdateRegistration, cus)); |
398 } | 378 } |
399 } | 379 } |
OLD | NEW |