| 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> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/atomicops.h" | 10 #include "base/atomicops.h" |
| 11 #include "base/base_paths.h" | 11 #include "base/base_paths.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/command_line.h" | |
| 15 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 16 #include "base/file_util.h" | 15 #include "base/file_util.h" |
| 17 #include "base/files/file_enumerator.h" | 16 #include "base/files/file_enumerator.h" |
| 18 #include "base/files/file_path.h" | 17 #include "base/files/file_path.h" |
| 19 #include "base/json/json_file_value_serializer.h" | 18 #include "base/json/json_file_value_serializer.h" |
| 20 #include "base/logging.h" | 19 #include "base/logging.h" |
| 21 #include "base/path_service.h" | 20 #include "base/path_service.h" |
| 22 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
| 23 #include "base/values.h" | 22 #include "base/values.h" |
| 24 #include "base/version.h" | 23 #include "base/version.h" |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 << " vs " << OmahaQueryParams::GetNaclArch() << ")"; | 195 << " vs " << OmahaQueryParams::GetNaclArch() << ")"; |
| 197 return false; | 196 return false; |
| 198 } | 197 } |
| 199 | 198 |
| 200 *version_out = version; | 199 *version_out = version; |
| 201 return true; | 200 return true; |
| 202 } | 201 } |
| 203 | 202 |
| 204 } // namespace | 203 } // namespace |
| 205 | 204 |
| 206 PnaclComponentInstaller::PnaclComponentInstaller() | 205 PnaclComponentInstaller::PnaclComponentInstaller() : cus_(NULL) { |
| 207 : updates_disabled_(false), cus_(NULL) { | |
| 208 } | 206 } |
| 209 | 207 |
| 210 PnaclComponentInstaller::~PnaclComponentInstaller() { | 208 PnaclComponentInstaller::~PnaclComponentInstaller() { |
| 211 } | 209 } |
| 212 | 210 |
| 213 void PnaclComponentInstaller::OnUpdateError(int error) { | 211 void PnaclComponentInstaller::OnUpdateError(int error) { |
| 214 NOTREACHED() << "Pnacl update error: " << error; | 212 NOTREACHED() << "Pnacl update error: " << error; |
| 215 } | 213 } |
| 216 | 214 |
| 217 // Pnacl components have the version encoded in the path itself: | 215 // Pnacl components have the version encoded in the path itself: |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 &manifest_version) || | 336 &manifest_version) || |
| 339 !current_version.Equals(manifest_version)) { | 337 !current_version.Equals(manifest_version)) { |
| 340 current_version = Version(kNullVersion); | 338 current_version = Version(kNullVersion); |
| 341 } else { | 339 } else { |
| 342 OverrideDirPnaclComponent(path); | 340 OverrideDirPnaclComponent(path); |
| 343 base::ReadFileToString(path.AppendASCII("manifest.fingerprint"), | 341 base::ReadFileToString(path.AppendASCII("manifest.fingerprint"), |
| 344 ¤t_fingerprint); | 342 ¤t_fingerprint); |
| 345 } | 343 } |
| 346 } | 344 } |
| 347 | 345 |
| 348 // If updates are disabled, only discover the current version | |
| 349 // and OverrideDirPnaclComponent. That way, developers can use | |
| 350 // a pinned version. Do not actually finish registration with | |
| 351 // the component update service. | |
| 352 if (pci->updates_disabled()) | |
| 353 return; | |
| 354 | |
| 355 BrowserThread::PostTask(BrowserThread::UI, | 346 BrowserThread::PostTask(BrowserThread::UI, |
| 356 FROM_HERE, | 347 FROM_HERE, |
| 357 base::Bind(&FinishPnaclUpdateRegistration, | 348 base::Bind(&FinishPnaclUpdateRegistration, |
| 358 current_version, | 349 current_version, |
| 359 current_fingerprint, | 350 current_fingerprint, |
| 360 pci)); | 351 pci)); |
| 361 | 352 |
| 362 // Remove older versions of PNaCl. | 353 // Remove older versions of PNaCl. |
| 363 for (std::vector<base::FilePath>::iterator iter = older_dirs.begin(); | 354 for (std::vector<base::FilePath>::iterator iter = older_dirs.begin(); |
| 364 iter != older_dirs.end(); | 355 iter != older_dirs.end(); |
| 365 ++iter) { | 356 ++iter) { |
| 366 base::DeleteFile(*iter, true); | 357 base::DeleteFile(*iter, true); |
| 367 } | 358 } |
| 368 } | 359 } |
| 369 | 360 |
| 370 } // namespace | 361 } // namespace |
| 371 | 362 |
| 372 void PnaclComponentInstaller::RegisterPnaclComponent( | 363 void PnaclComponentInstaller::RegisterPnaclComponent( |
| 373 ComponentUpdateService* cus, | 364 ComponentUpdateService* cus) { |
| 374 const CommandLine& command_line) { | |
| 375 // Register PNaCl by default (can be disabled). | |
| 376 updates_disabled_ = command_line.HasSwitch(switches::kDisablePnaclInstall); | |
| 377 cus_ = cus; | 365 cus_ = cus; |
| 378 BrowserThread::PostTask(BrowserThread::FILE, | 366 BrowserThread::PostTask(BrowserThread::FILE, |
| 379 FROM_HERE, | 367 FROM_HERE, |
| 380 base::Bind(&StartPnaclUpdateRegistration, this)); | 368 base::Bind(&StartPnaclUpdateRegistration, this)); |
| 381 } | 369 } |
| 382 | 370 |
| 383 } // namespace component_updater | 371 } // namespace component_updater |
| 384 | 372 |
| 385 namespace pnacl { | 373 namespace pnacl { |
| 386 | 374 |
| 387 bool NeedsOnDemandUpdate() { | 375 bool NeedsOnDemandUpdate() { |
| 388 return base::subtle::NoBarrier_Load( | 376 return base::subtle::NoBarrier_Load( |
| 389 &component_updater::needs_on_demand_update) != 0; | 377 &component_updater::needs_on_demand_update) != 0; |
| 390 } | 378 } |
| 391 | 379 |
| 392 } // namespace pnacl | 380 } // namespace pnacl |
| OLD | NEW |