Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(223)

Side by Side Diff: chrome/browser/component_updater/pnacl/pnacl_component_installer.cc

Issue 12054003: Add an API to component_updater that asks to do an update check "now". (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: move commandline check Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/compiler_specific.h" 10 #include "base/compiler_specific.h"
10 #include "base/file_path.h" 11 #include "base/file_path.h"
11 #include "base/file_util.h" 12 #include "base/file_util.h"
12 #include "base/json/json_file_value_serializer.h" 13 #include "base/json/json_file_value_serializer.h"
13 #include "base/logging.h" 14 #include "base/logging.h"
14 #include "base/path_service.h" 15 #include "base/path_service.h"
15 #include "base/string_util.h" 16 #include "base/string_util.h"
16 #include "base/values.h" 17 #include "base/values.h"
17 #include "base/version.h" 18 #include "base/version.h"
18 #include "base/win/windows_version.h" 19 #include "base/win/windows_version.h"
19 #include "build/build_config.h" 20 #include "build/build_config.h"
20 #include "chrome/browser/component_updater/component_updater_service.h" 21 #include "chrome/browser/component_updater/component_updater_service.h"
21 #include "chrome/common/chrome_paths.h" 22 #include "chrome/common/chrome_paths.h"
23 #include "chrome/common/chrome_switches.h"
22 #include "content/public/browser/browser_thread.h" 24 #include "content/public/browser/browser_thread.h"
23 25
24 using content::BrowserThread; 26 using content::BrowserThread;
25 27
26 namespace { 28 namespace {
27 29
30 // 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
32 // a background install.
33 const int kInitialDelaySeconds = 10;
34
28 // One of the Pnacl component files, for checking that expected files exist. 35 // 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 36 // 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. 37 // manifest.json. Use that to check that everything is unpacked.
31 // However, that would make startup detection even slower (need to check for 38 // However, that would make startup detection even slower (need to check for
32 // more than one file!). 39 // more than one file!).
33 const char kPnaclCompilerFileName[] = "llc_nexe"; 40 const char kPnaclCompilerFileName[] = "llc_nexe";
34 41
35 // Name of the Pnacl component specified in the manifest. 42 // Name of the Pnacl component specified in the manifest.
36 const char kPnaclManifestNamePrefix[] = "PNaCl"; 43 const char kPnaclManifestNamePrefix[] = "PNaCl";
37 44
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 127
121 component->pk_hash.assign(mips32_sha256_hash, 128 component->pk_hash.assign(mips32_sha256_hash,
122 &mips32_sha256_hash[sizeof(mips32_sha256_hash)]); 129 &mips32_sha256_hash[sizeof(mips32_sha256_hash)]);
123 #else 130 #else
124 #error "Add support for your architecture to Pnacl Component Installer." 131 #error "Add support for your architecture to Pnacl Component Installer."
125 #endif 132 #endif
126 } 133 }
127 134
128 135
129 // If we don't have Pnacl installed, this is the version we claim. 136 // 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"; 137 const char kNullVersion[] = "0.0.0.0";
135 138
136 // Pnacl components have the version encoded in the path itself: 139 // Pnacl components have the version encoded in the path itself:
137 // <profile>\AppData\Local\Google\Chrome\User Data\Pnacl\0.1.2.3\. 140 // <profile>\AppData\Local\Google\Chrome\User Data\Pnacl\0.1.2.3\.
138 // and the base directory will be: 141 // and the base directory will be:
139 // <profile>\AppData\Local\Google\Chrome\User Data\Pnacl\. 142 // <profile>\AppData\Local\Google\Chrome\User Data\Pnacl\.
140 base::FilePath GetPnaclBaseDirectory() { 143 base::FilePath GetPnaclBaseDirectory() {
141 base::FilePath result; 144 base::FilePath result;
142 CHECK(PathService::Get(chrome::DIR_PNACL_BASE, &result)); 145 CHECK(PathService::Get(chrome::DIR_PNACL_BASE, &result));
143 return result; 146 return result;
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 // then be able to reload the page and retry (or something). 311 // then be able to reload the page and retry (or something).
309 // See: http://code.google.com/p/chromium/issues/detail?id=107438 312 // See: http://code.google.com/p/chromium/issues/detail?id=107438
310 current_version_ = version; 313 current_version_ = version;
311 314
312 PathService::Override(chrome::DIR_PNACL_COMPONENT, path); 315 PathService::Override(chrome::DIR_PNACL_COMPONENT, path);
313 return true; 316 return true;
314 } 317 }
315 318
316 namespace { 319 namespace {
317 320
321 void DoCheckForUpdate(ComponentUpdateService* cus,
322 const CrxComponent& pnacl) {
323 if (cus->CheckForUpdateSoon(pnacl) != ComponentUpdateService::kOk) {
324 LOG(WARNING) << "Pnacl check for update failed.";
325 }
326 }
327
318 // Finally, do the registration with the right version number. 328 // Finally, do the registration with the right version number.
319 void FinishPnaclUpdateRegistration(ComponentUpdateService* cus, 329 void FinishPnaclUpdateRegistration(ComponentUpdateService* cus,
320 const Version& current_version) { 330 const Version& current_version) {
321 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 331 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
322 // Note: the source is the default of BANDAID, even though the 332 // Note: the source is the default of BANDAID, even though the
323 // crxes are hosted from CWS. 333 // crxes are hosted from CWS.
324 CrxComponent pnacl; 334 CrxComponent pnacl;
325 pnacl.name = "pnacl"; 335 pnacl.name = "pnacl";
326 pnacl.installer = new PnaclComponentInstaller(current_version); 336 pnacl.installer = new PnaclComponentInstaller(current_version);
327 pnacl.version = current_version; 337 pnacl.version = current_version;
328 SetPnaclHash(&pnacl); 338 SetPnaclHash(&pnacl);
329 if (cus->RegisterComponent(pnacl) != ComponentUpdateService::kOk) { 339 if (cus->RegisterComponent(pnacl) != ComponentUpdateService::kOk) {
330 NOTREACHED() << "Pnacl component registration failed."; 340 NOTREACHED() << "Pnacl component registration failed.";
331 } 341 }
342
343 // If PNaCl is not yet installed but it is requested by --enable-pnacl,
344 // we want it to be available "soon", so kick off an update check
345 // earlier than usual.
346 Version null_version(kNullVersion);
347 if (current_version.Equals(null_version)) {
348 BrowserThread::PostDelayedTask(
349 BrowserThread::UI, FROM_HERE,
350 base::Bind(DoCheckForUpdate, cus, pnacl),
351 base::TimeDelta::FromSeconds(kInitialDelaySeconds));
352 }
332 } 353 }
333 354
334 // Check if there is an existing version on disk first to know when 355 // Check if there is an existing version on disk first to know when
335 // a hosted version is actually newer. 356 // a hosted version is actually newer.
336 void StartPnaclUpdateRegistration(ComponentUpdateService* cus) { 357 void StartPnaclUpdateRegistration(ComponentUpdateService* cus) {
337 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 358 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
338 base::FilePath path = GetPnaclBaseDirectory(); 359 base::FilePath path = GetPnaclBaseDirectory();
339 if (!file_util::PathExists(path)) { 360 if (!file_util::PathExists(path)) {
340 if (!file_util::CreateDirectory(path)) { 361 if (!file_util::CreateDirectory(path)) {
341 NOTREACHED() << "Could not create base Pnacl directory."; 362 NOTREACHED() << "Could not create base Pnacl directory.";
(...skipping 17 matching lines...) Expand all
359 380
360 // Remove older versions of PNaCl. 381 // Remove older versions of PNaCl.
361 for (std::vector<base::FilePath>::iterator iter = older_dirs.begin(); 382 for (std::vector<base::FilePath>::iterator iter = older_dirs.begin();
362 iter != older_dirs.end(); ++iter) { 383 iter != older_dirs.end(); ++iter) {
363 file_util::Delete(*iter, true); 384 file_util::Delete(*iter, true);
364 } 385 }
365 } 386 }
366 387
367 } // namespace 388 } // namespace
368 389
369 void RegisterPnaclComponent(ComponentUpdateService* cus) { 390 void RegisterPnaclComponent(ComponentUpdateService* cus,
370 BrowserThread::PostTask( 391 const CommandLine& command_line) {
371 BrowserThread::FILE, FROM_HERE, 392 // Only register when given the right flag. This is important since
372 base::Bind(&StartPnaclUpdateRegistration, cus)); 393 // we do an early component updater check above (in DoCheckForUpdate).
394 if (command_line.HasSwitch(switches::kEnablePnacl)) {
395 BrowserThread::PostTask(
396 BrowserThread::FILE, FROM_HERE,
397 base::Bind(&StartPnaclUpdateRegistration, cus));
398 }
373 } 399 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698