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 base::FilePath GetPnaclBaseDirectory() { | 141 base::FilePath GetPnaclBaseDirectory() { |
141 base::FilePath result; | 142 base::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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
308 // then be able to reload the page and retry (or something). | 309 // then be able to reload the page and retry (or something). |
309 // See: http://code.google.com/p/chromium/issues/detail?id=107438 | 310 // See: http://code.google.com/p/chromium/issues/detail?id=107438 |
310 current_version_ = version; | 311 current_version_ = version; |
311 | 312 |
312 PathService::Override(chrome::DIR_PNACL_COMPONENT, path); | 313 PathService::Override(chrome::DIR_PNACL_COMPONENT, path); |
313 return true; | 314 return true; |
314 } | 315 } |
315 | 316 |
316 namespace { | 317 namespace { |
317 | 318 |
319 void DoCheckForUpdate(ComponentUpdateService* cus, | |
320 const CrxComponent& pnacl) { | |
321 if (cus->CheckForUpdateSoon(pnacl) != ComponentUpdateService::kOk) { | |
322 LOG(WARNING) << "Pnacl check for update failed."; | |
323 } | |
324 } | |
325 | |
318 // Finally, do the registration with the right version number. | 326 // Finally, do the registration with the right version number. |
319 void FinishPnaclUpdateRegistration(ComponentUpdateService* cus, | 327 void FinishPnaclUpdateRegistration(ComponentUpdateService* cus, |
320 const Version& current_version) { | 328 const Version& current_version) { |
321 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 329 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
322 // Note: the source is the default of BANDAID, even though the | 330 // Note: the source is the default of BANDAID, even though the |
323 // crxes are hosted from CWS. | 331 // crxes are hosted from CWS. |
324 CrxComponent pnacl; | 332 CrxComponent pnacl; |
325 pnacl.name = "pnacl"; | 333 pnacl.name = "pnacl"; |
326 pnacl.installer = new PnaclComponentInstaller(current_version); | 334 pnacl.installer = new PnaclComponentInstaller(current_version); |
327 pnacl.version = current_version; | 335 pnacl.version = current_version; |
328 SetPnaclHash(&pnacl); | 336 SetPnaclHash(&pnacl); |
329 if (cus->RegisterComponent(pnacl) != ComponentUpdateService::kOk) { | 337 if (cus->RegisterComponent(pnacl) != ComponentUpdateService::kOk) { |
330 NOTREACHED() << "Pnacl component registration failed."; | 338 NOTREACHED() << "Pnacl component registration failed."; |
331 } | 339 } |
340 | |
341 // If PNaCl is not yet installed but it is requested by --enable-pnacl, | |
342 // we want it to be available "soon", so kick off an update check | |
cpu_(ooo_6.6-7.5)
2013/02/12 23:34:26
wait, where is the command line check?
jvoung (off chromium)
2013/02/12 23:38:37
In chrome/browser/chrome_browser_main.cc, PNaCl is
| |
343 // earlier than usual. | |
344 Version null_version(kNullVersion); | |
345 if (current_version.Equals(null_version)) { | |
346 BrowserThread::PostDelayedTask( | |
347 BrowserThread::UI, FROM_HERE, | |
348 base::Bind(DoCheckForUpdate, cus, pnacl), | |
349 base::TimeDelta::FromSeconds(kInitialDelaySeconds)); | |
350 } | |
332 } | 351 } |
333 | 352 |
334 // Check if there is an existing version on disk first to know when | 353 // Check if there is an existing version on disk first to know when |
335 // a hosted version is actually newer. | 354 // a hosted version is actually newer. |
336 void StartPnaclUpdateRegistration(ComponentUpdateService* cus) { | 355 void StartPnaclUpdateRegistration(ComponentUpdateService* cus) { |
337 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 356 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
338 base::FilePath path = GetPnaclBaseDirectory(); | 357 base::FilePath path = GetPnaclBaseDirectory(); |
339 if (!file_util::PathExists(path)) { | 358 if (!file_util::PathExists(path)) { |
340 if (!file_util::CreateDirectory(path)) { | 359 if (!file_util::CreateDirectory(path)) { |
341 NOTREACHED() << "Could not create base Pnacl directory."; | 360 NOTREACHED() << "Could not create base Pnacl directory."; |
(...skipping 22 matching lines...) Expand all Loading... | |
364 } | 383 } |
365 } | 384 } |
366 | 385 |
367 } // namespace | 386 } // namespace |
368 | 387 |
369 void RegisterPnaclComponent(ComponentUpdateService* cus) { | 388 void RegisterPnaclComponent(ComponentUpdateService* cus) { |
370 BrowserThread::PostTask( | 389 BrowserThread::PostTask( |
371 BrowserThread::FILE, FROM_HERE, | 390 BrowserThread::FILE, FROM_HERE, |
372 base::Bind(&StartPnaclUpdateRegistration, cus)); | 391 base::Bind(&StartPnaclUpdateRegistration, cus)); |
373 } | 392 } |
OLD | NEW |