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 <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
14 #include "base/json/json_file_value_serializer.h" | 14 #include "base/json/json_file_value_serializer.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/path_service.h" | 16 #include "base/path_service.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 "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
24 | 24 |
25 using content::BrowserThread; | 25 using content::BrowserThread; |
26 | 26 |
27 namespace { | 27 namespace { |
28 | 28 |
| 29 // If PNaCl isn't installed yet, but a user is running chrome with |
| 30 // --enable-pnacl, this is the amount of time to wait before starting |
| 31 // a background install. |
| 32 const int kInitialDelaySeconds = 10; |
| 33 |
29 // CRX hash. This corresponds to AppId: emkhcgigkicgidendmffimilfehocheg | 34 // CRX hash. This corresponds to AppId: emkhcgigkicgidendmffimilfehocheg |
30 const uint8 sha256_hash[] = { | 35 const uint8 sha256_hash[] = { |
31 0x4c, 0xa7, 0x26, 0x86, 0xa8, 0x26, 0x83, 0x4d, 0x3c, 0x55, | 36 0x4c, 0xa7, 0x26, 0x86, 0xa8, 0x26, 0x83, 0x4d, 0x3c, 0x55, |
32 0x8c, 0x8b, 0x54, 0x7e, 0x27, 0x46, 0xa0, 0xf8, 0xd5, 0x0e, 0xea, | 37 0x8c, 0x8b, 0x54, 0x7e, 0x27, 0x46, 0xa0, 0xf8, 0xd5, 0x0e, 0xea, |
33 0x33, 0x46, 0x6e, 0xab, 0x6c, 0xde, 0xba, 0xc0, 0x91, 0xd4, 0x5e }; | 38 0x33, 0x46, 0x6e, 0xab, 0x6c, 0xde, 0xba, 0xc0, 0x91, 0xd4, 0x5e }; |
34 | 39 |
35 // One of the Pnacl component files, for checking that expected files exist. | 40 // 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 | 41 // 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. | 42 // manifest.json. Use that to check that everything is unpacked. |
38 // However, that would make startup detection even slower (need to check for | 43 // However, that would make startup detection even slower (need to check for |
(...skipping 23 matching lines...) Expand all Loading... |
62 // choice, which would require substantial refactoring. | 67 // choice, which would require substantial refactoring. |
63 return "arm"; | 68 return "arm"; |
64 #elif defined(ARCH_CPU_MIPSEL) | 69 #elif defined(ARCH_CPU_MIPSEL) |
65 return "mips32"; | 70 return "mips32"; |
66 #else | 71 #else |
67 #error "Add support for your architecture to Pnacl Component Installer." | 72 #error "Add support for your architecture to Pnacl Component Installer." |
68 #endif | 73 #endif |
69 } | 74 } |
70 | 75 |
71 // If we don't have Pnacl installed, this is the version we claim. | 76 // If we don't have Pnacl installed, this is the version we claim. |
72 // TODO(jvoung): Is there a way to trick the configurator to ping the server | |
73 // earlier if there are components that are not yet installed (version 0.0.0.0), | |
74 // So that they will be available ASAP? Be careful not to hurt startup speed. | |
75 // Make kNullVersion part of ComponentUpdater in that case, to avoid skew? | |
76 const char kNullVersion[] = "0.0.0.0"; | 77 const char kNullVersion[] = "0.0.0.0"; |
77 | 78 |
78 // Pnacl components have the version encoded in the path itself: | 79 // Pnacl components have the version encoded in the path itself: |
79 // <profile>\AppData\Local\Google\Chrome\User Data\Pnacl\0.1.2.3\. | 80 // <profile>\AppData\Local\Google\Chrome\User Data\Pnacl\0.1.2.3\. |
80 // and the base directory will be: | 81 // and the base directory will be: |
81 // <profile>\AppData\Local\Google\Chrome\User Data\Pnacl\. | 82 // <profile>\AppData\Local\Google\Chrome\User Data\Pnacl\. |
82 FilePath GetPnaclBaseDirectory() { | 83 FilePath GetPnaclBaseDirectory() { |
83 FilePath result; | 84 FilePath result; |
84 CHECK(PathService::Get(chrome::DIR_PNACL_BASE, &result)); | 85 CHECK(PathService::Get(chrome::DIR_PNACL_BASE, &result)); |
85 return result; | 86 return result; |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 // then be able to reload the page and retry (or something). | 243 // then be able to reload the page and retry (or something). |
243 // See: http://code.google.com/p/chromium/issues/detail?id=107438 | 244 // See: http://code.google.com/p/chromium/issues/detail?id=107438 |
244 current_version_ = version; | 245 current_version_ = version; |
245 | 246 |
246 PathService::Override(chrome::DIR_PNACL_COMPONENT, path); | 247 PathService::Override(chrome::DIR_PNACL_COMPONENT, path); |
247 return true; | 248 return true; |
248 } | 249 } |
249 | 250 |
250 namespace { | 251 namespace { |
251 | 252 |
| 253 void DoPingUpdater(ComponentUpdateService* cus, |
| 254 const CrxComponent& pnacl) { |
| 255 if (cus->PingUpdateCheck(pnacl) != ComponentUpdateService::kOk) { |
| 256 NOTREACHED() << "Pnacl ping update failed."; |
| 257 } |
| 258 } |
| 259 |
252 // Finally, do the registration with the right version number. | 260 // Finally, do the registration with the right version number. |
253 void FinishPnaclUpdateRegistration(ComponentUpdateService* cus, | 261 void FinishPnaclUpdateRegistration(ComponentUpdateService* cus, |
254 const Version& version) { | 262 const Version& version) { |
255 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 263 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
256 CrxComponent pnacl; | 264 CrxComponent pnacl; |
257 pnacl.name = "pnacl"; | 265 pnacl.name = "pnacl"; |
258 pnacl.installer = new PnaclComponentInstaller(version); | 266 pnacl.installer = new PnaclComponentInstaller(version); |
259 pnacl.version = version; | 267 pnacl.version = version; |
260 pnacl.pk_hash.assign(sha256_hash, &sha256_hash[sizeof(sha256_hash)]); | 268 pnacl.pk_hash.assign(sha256_hash, &sha256_hash[sizeof(sha256_hash)]); |
261 if (cus->RegisterComponent(pnacl) != ComponentUpdateService::kOk) { | 269 if (cus->RegisterComponent(pnacl) != ComponentUpdateService::kOk) { |
262 NOTREACHED() << "Pnacl component registration failed."; | 270 NOTREACHED() << "Pnacl component registration failed."; |
263 } | 271 } |
| 272 |
| 273 // If Pnacl is not yet installed, but it is requested by --enable-pnacl, |
| 274 // we want it to be available "soon", so kick off an update check. |
| 275 Version null_version(kNullVersion); |
| 276 if (version.Equals(null_version)) { |
| 277 BrowserThread::PostDelayedTask( |
| 278 BrowserThread::UI, FROM_HERE, |
| 279 base::Bind(DoPingUpdater, cus, pnacl), |
| 280 base::TimeDelta::FromSeconds(kInitialDelaySeconds)); |
| 281 } |
264 } | 282 } |
265 | 283 |
266 // Check if there is an existing version on disk first to know when | 284 // Check if there is an existing version on disk first to know when |
267 // a hosted version is actually newer. | 285 // a hosted version is actually newer. |
268 void StartPnaclUpdateRegistration(ComponentUpdateService* cus) { | 286 void StartPnaclUpdateRegistration(ComponentUpdateService* cus) { |
269 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 287 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
270 FilePath path = GetPnaclBaseDirectory(); | 288 FilePath path = GetPnaclBaseDirectory(); |
271 if (!file_util::PathExists(path)) { | 289 if (!file_util::PathExists(path)) { |
272 if (!file_util::CreateDirectory(path)) { | 290 if (!file_util::CreateDirectory(path)) { |
273 NOTREACHED() << "Could not create base Pnacl directory."; | 291 NOTREACHED() << "Could not create base Pnacl directory."; |
(...skipping 22 matching lines...) Expand all Loading... |
296 } | 314 } |
297 } | 315 } |
298 | 316 |
299 } // namespace | 317 } // namespace |
300 | 318 |
301 void RegisterPnaclComponent(ComponentUpdateService* cus) { | 319 void RegisterPnaclComponent(ComponentUpdateService* cus) { |
302 BrowserThread::PostTask( | 320 BrowserThread::PostTask( |
303 BrowserThread::FILE, FROM_HERE, | 321 BrowserThread::FILE, FROM_HERE, |
304 base::Bind(&StartPnaclUpdateRegistration, cus)); | 322 base::Bind(&StartPnaclUpdateRegistration, cus)); |
305 } | 323 } |
OLD | NEW |