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/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/json/json_file_value_serializer.h" | 12 #include "base/json/json_file_value_serializer.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
16 #include "base/values.h" | 16 #include "base/values.h" |
17 #include "base/version.h" | 17 #include "base/version.h" |
18 #include "base/win/windows_version.h" | 18 #include "base/win/windows_version.h" |
19 #include "build/build_config.h" | 19 #include "build/build_config.h" |
20 #include "chrome/browser/component_updater/component_updater_service.h" | 20 #include "chrome/browser/component_updater/component_updater_service.h" |
21 #include "chrome/common/chrome_paths.h" | 21 #include "chrome/common/chrome_paths.h" |
22 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
23 | 23 |
24 using content::BrowserThread; | 24 using content::BrowserThread; |
25 | 25 |
26 namespace { | 26 namespace { |
27 | 27 |
| 28 // If PNaCl isn't installed yet, but a user is running chrome with |
| 29 // --enable-pnacl, this is the amount of time to wait before starting |
| 30 // a background install. |
| 31 const int kInitialDelaySeconds = 10; |
| 32 |
28 // One of the Pnacl component files, for checking that expected files exist. | 33 // One of the Pnacl component files, for checking that expected files exist. |
29 // TODO(jvoung): perhaps replace this with a list of the expected files in the | 34 // TODO(jvoung): perhaps replace this with a list of the expected files in the |
30 // manifest.json. Use that to check that everything is unpacked. | 35 // manifest.json. Use that to check that everything is unpacked. |
31 // However, that would make startup detection even slower (need to check for | 36 // However, that would make startup detection even slower (need to check for |
32 // more than one file!). | 37 // more than one file!). |
33 const char kPnaclCompilerFileName[] = "llc_nexe"; | 38 const char kPnaclCompilerFileName[] = "llc_nexe"; |
34 | 39 |
35 // Name of the Pnacl component specified in the manifest. | 40 // Name of the Pnacl component specified in the manifest. |
36 const char kPnaclManifestNamePrefix[] = "PNaCl"; | 41 const char kPnaclManifestNamePrefix[] = "PNaCl"; |
37 | 42 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 | 125 |
121 component->pk_hash.assign(mips32_sha256_hash, | 126 component->pk_hash.assign(mips32_sha256_hash, |
122 &mips32_sha256_hash[sizeof(mips32_sha256_hash)]); | 127 &mips32_sha256_hash[sizeof(mips32_sha256_hash)]); |
123 #else | 128 #else |
124 #error "Add support for your architecture to Pnacl Component Installer." | 129 #error "Add support for your architecture to Pnacl Component Installer." |
125 #endif | 130 #endif |
126 } | 131 } |
127 | 132 |
128 | 133 |
129 // If we don't have Pnacl installed, this is the version we claim. | 134 // If we don't have Pnacl installed, this is the version we claim. |
130 // TODO(jvoung): Is there a way to trick the configurator to ping the server | |
131 // earlier if there are components that are not yet installed (version 0.0.0.0), | |
132 // So that they will be available ASAP? Be careful not to hurt startup speed. | |
133 // Make kNullVersion part of ComponentUpdater in that case, to avoid skew? | |
134 const char kNullVersion[] = "0.0.0.0"; | 135 const char kNullVersion[] = "0.0.0.0"; |
135 | 136 |
136 // Pnacl components have the version encoded in the path itself: | 137 // Pnacl components have the version encoded in the path itself: |
137 // <profile>\AppData\Local\Google\Chrome\User Data\Pnacl\0.1.2.3\. | 138 // <profile>\AppData\Local\Google\Chrome\User Data\Pnacl\0.1.2.3\. |
138 // and the base directory will be: | 139 // and the base directory will be: |
139 // <profile>\AppData\Local\Google\Chrome\User Data\Pnacl\. | 140 // <profile>\AppData\Local\Google\Chrome\User Data\Pnacl\. |
140 FilePath GetPnaclBaseDirectory() { | 141 FilePath GetPnaclBaseDirectory() { |
141 FilePath result; | 142 FilePath result; |
142 CHECK(PathService::Get(chrome::DIR_PNACL_BASE, &result)); | 143 CHECK(PathService::Get(chrome::DIR_PNACL_BASE, &result)); |
143 return result; | 144 return result; |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 // then be able to reload the page and retry (or something). | 308 // then be able to reload the page and retry (or something). |
308 // See: http://code.google.com/p/chromium/issues/detail?id=107438 | 309 // See: http://code.google.com/p/chromium/issues/detail?id=107438 |
309 current_version_ = version; | 310 current_version_ = version; |
310 | 311 |
311 PathService::Override(chrome::DIR_PNACL_COMPONENT, path); | 312 PathService::Override(chrome::DIR_PNACL_COMPONENT, path); |
312 return true; | 313 return true; |
313 } | 314 } |
314 | 315 |
315 namespace { | 316 namespace { |
316 | 317 |
| 318 void DoCheckForUpdate(ComponentUpdateService* cus, |
| 319 const CrxComponent& pnacl) { |
| 320 if (cus->CheckForUpdateSoon(pnacl) != ComponentUpdateService::kOk) { |
| 321 LOG(WARNING) << "Pnacl check for update failed."; |
| 322 } |
| 323 } |
| 324 |
317 // Finally, do the registration with the right version number. | 325 // Finally, do the registration with the right version number. |
318 void FinishPnaclUpdateRegistration(ComponentUpdateService* cus, | 326 void FinishPnaclUpdateRegistration(ComponentUpdateService* cus, |
319 const Version& current_version) { | 327 const Version& current_version) { |
320 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 328 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
321 // Note: the source is the default of BANDAID, even though the | 329 // Note: the source is the default of BANDAID, even though the |
322 // crxes are hosted from CWS. | 330 // crxes are hosted from CWS. |
323 CrxComponent pnacl; | 331 CrxComponent pnacl; |
324 pnacl.name = "pnacl"; | 332 pnacl.name = "pnacl"; |
325 pnacl.installer = new PnaclComponentInstaller(current_version); | 333 pnacl.installer = new PnaclComponentInstaller(current_version); |
326 pnacl.version = current_version; | 334 pnacl.version = current_version; |
327 SetPnaclHash(&pnacl); | 335 SetPnaclHash(&pnacl); |
328 if (cus->RegisterComponent(pnacl) != ComponentUpdateService::kOk) { | 336 if (cus->RegisterComponent(pnacl) != ComponentUpdateService::kOk) { |
329 NOTREACHED() << "Pnacl component registration failed."; | 337 NOTREACHED() << "Pnacl component registration failed."; |
330 } | 338 } |
| 339 |
| 340 // If Pnacl is not yet installed, but it is requested by --enable-pnacl, |
| 341 // we want it to be available "soon", so kick off an update check. |
| 342 Version null_version(kNullVersion); |
| 343 if (current_version.Equals(null_version)) { |
| 344 BrowserThread::PostDelayedTask( |
| 345 BrowserThread::UI, FROM_HERE, |
| 346 base::Bind(DoCheckForUpdate, cus, pnacl), |
| 347 base::TimeDelta::FromSeconds(kInitialDelaySeconds)); |
| 348 } |
331 } | 349 } |
332 | 350 |
333 // Check if there is an existing version on disk first to know when | 351 // Check if there is an existing version on disk first to know when |
334 // a hosted version is actually newer. | 352 // a hosted version is actually newer. |
335 void StartPnaclUpdateRegistration(ComponentUpdateService* cus) { | 353 void StartPnaclUpdateRegistration(ComponentUpdateService* cus) { |
336 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 354 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
337 FilePath path = GetPnaclBaseDirectory(); | 355 FilePath path = GetPnaclBaseDirectory(); |
338 if (!file_util::PathExists(path)) { | 356 if (!file_util::PathExists(path)) { |
339 if (!file_util::CreateDirectory(path)) { | 357 if (!file_util::CreateDirectory(path)) { |
340 NOTREACHED() << "Could not create base Pnacl directory."; | 358 NOTREACHED() << "Could not create base Pnacl directory."; |
(...skipping 22 matching lines...) Expand all Loading... |
363 } | 381 } |
364 } | 382 } |
365 | 383 |
366 } // namespace | 384 } // namespace |
367 | 385 |
368 void RegisterPnaclComponent(ComponentUpdateService* cus) { | 386 void RegisterPnaclComponent(ComponentUpdateService* cus) { |
369 BrowserThread::PostTask( | 387 BrowserThread::PostTask( |
370 BrowserThread::FILE, FROM_HERE, | 388 BrowserThread::FILE, FROM_HERE, |
371 base::Bind(&StartPnaclUpdateRegistration, cus)); | 389 base::Bind(&StartPnaclUpdateRegistration, cus)); |
372 } | 390 } |
OLD | NEW |