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 <stdint.h> | 7 #include <stdint.h> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 base::FilePath GetPlatformDir(const base::FilePath& base_path) { | 85 base::FilePath GetPlatformDir(const base::FilePath& base_path) { |
86 std::string arch = SanitizeForPath(UpdateQueryParams::GetNaclArch()); | 86 std::string arch = SanitizeForPath(UpdateQueryParams::GetNaclArch()); |
87 return base_path.AppendASCII("_platform_specific").AppendASCII(arch); | 87 return base_path.AppendASCII("_platform_specific").AppendASCII(arch); |
88 } | 88 } |
89 | 89 |
90 // Tell the rest of the world where to find the platform-specific PNaCl files. | 90 // Tell the rest of the world where to find the platform-specific PNaCl files. |
91 void OverrideDirPnaclComponent(const base::FilePath& base_path) { | 91 void OverrideDirPnaclComponent(const base::FilePath& base_path) { |
92 PathService::Override(chrome::DIR_PNACL_COMPONENT, GetPlatformDir(base_path)); | 92 PathService::Override(chrome::DIR_PNACL_COMPONENT, GetPlatformDir(base_path)); |
93 } | 93 } |
94 | 94 |
95 bool GetLatestPnaclDirectory(PnaclComponentInstaller* pci, | 95 bool GetLatestPnaclDirectory(const scoped_refptr<PnaclComponentInstaller>& pci, |
96 base::FilePath* latest_dir, | 96 base::FilePath* latest_dir, |
97 Version* latest_version, | 97 Version* latest_version, |
98 std::vector<base::FilePath>* older_dirs) { | 98 std::vector<base::FilePath>* older_dirs) { |
99 // Enumerate all versions starting from the base directory. | 99 // Enumerate all versions starting from the base directory. |
100 base::FilePath base_dir = pci->GetPnaclBaseDirectory(); | 100 base::FilePath base_dir = pci->GetPnaclBaseDirectory(); |
101 bool found = false; | 101 bool found = false; |
102 base::FileEnumerator file_enumerator( | 102 base::FileEnumerator file_enumerator( |
103 base_dir, false, base::FileEnumerator::DIRECTORIES); | 103 base_dir, false, base::FileEnumerator::DIRECTORIES); |
104 for (base::FilePath path = file_enumerator.Next(); !path.value().empty(); | 104 for (base::FilePath path = file_enumerator.Next(); !path.value().empty(); |
105 path = file_enumerator.Next()) { | 105 path = file_enumerator.Next()) { |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 pnacl_component.name = "pnacl"; | 286 pnacl_component.name = "pnacl"; |
287 pnacl_component.installer = this; | 287 pnacl_component.installer = this; |
288 pnacl_component.fingerprint = current_fingerprint(); | 288 pnacl_component.fingerprint = current_fingerprint(); |
289 SetPnaclHash(&pnacl_component); | 289 SetPnaclHash(&pnacl_component); |
290 | 290 |
291 return pnacl_component; | 291 return pnacl_component; |
292 } | 292 } |
293 | 293 |
294 namespace { | 294 namespace { |
295 | 295 |
296 void FinishPnaclUpdateRegistration(const Version& current_version, | 296 void FinishPnaclUpdateRegistration( |
297 const std::string& current_fingerprint, | 297 const Version& current_version, |
298 PnaclComponentInstaller* pci) { | 298 const std::string& current_fingerprint, |
| 299 const scoped_refptr<PnaclComponentInstaller>& pci) { |
299 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 300 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
300 pci->set_current_version(current_version); | 301 pci->set_current_version(current_version); |
301 CheckVersionCompatiblity(current_version); | 302 CheckVersionCompatiblity(current_version); |
302 pci->set_current_fingerprint(current_fingerprint); | 303 pci->set_current_fingerprint(current_fingerprint); |
303 CrxComponent pnacl_component = pci->GetCrxComponent(); | 304 CrxComponent pnacl_component = pci->GetCrxComponent(); |
304 | 305 |
305 ComponentUpdateService::Status status = | 306 ComponentUpdateService::Status status = |
306 pci->cus()->RegisterComponent(pnacl_component); | 307 pci->cus()->RegisterComponent(pnacl_component); |
307 if (status != ComponentUpdateService::kOk && | 308 if (status != ComponentUpdateService::kOk && |
308 status != ComponentUpdateService::kReplaced) { | 309 status != ComponentUpdateService::kReplaced) { |
309 NOTREACHED() << "Pnacl component registration failed."; | 310 NOTREACHED() << "Pnacl component registration failed."; |
310 } | 311 } |
311 } | 312 } |
312 | 313 |
313 // Check if there is an existing version on disk first to know when | 314 // Check if there is an existing version on disk first to know when |
314 // a hosted version is actually newer. | 315 // a hosted version is actually newer. |
315 void StartPnaclUpdateRegistration(PnaclComponentInstaller* pci) { | 316 void StartPnaclUpdateRegistration( |
| 317 const scoped_refptr<PnaclComponentInstaller>& pci) { |
316 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 318 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
317 base::FilePath path = pci->GetPnaclBaseDirectory(); | 319 base::FilePath path = pci->GetPnaclBaseDirectory(); |
318 if (!base::PathExists(path)) { | 320 if (!base::PathExists(path)) { |
319 if (!base::CreateDirectory(path)) { | 321 if (!base::CreateDirectory(path)) { |
320 NOTREACHED() << "Could not create base Pnacl directory."; | 322 NOTREACHED() << "Could not create base Pnacl directory."; |
321 return; | 323 return; |
322 } | 324 } |
323 } | 325 } |
324 | 326 |
325 Version current_version(kNullVersion); | 327 Version current_version(kNullVersion); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 ++iter) { | 360 ++iter) { |
359 base::DeleteFile(*iter, true); | 361 base::DeleteFile(*iter, true); |
360 } | 362 } |
361 } | 363 } |
362 | 364 |
363 } // namespace | 365 } // namespace |
364 | 366 |
365 void PnaclComponentInstaller::RegisterPnaclComponent( | 367 void PnaclComponentInstaller::RegisterPnaclComponent( |
366 ComponentUpdateService* cus) { | 368 ComponentUpdateService* cus) { |
367 cus_ = cus; | 369 cus_ = cus; |
368 BrowserThread::PostTask(BrowserThread::FILE, | 370 BrowserThread::PostTask( |
369 FROM_HERE, | 371 BrowserThread::FILE, FROM_HERE, |
370 base::Bind(&StartPnaclUpdateRegistration, this)); | 372 base::Bind(&StartPnaclUpdateRegistration, make_scoped_refptr(this))); |
371 } | 373 } |
372 | 374 |
373 } // namespace component_updater | 375 } // namespace component_updater |
374 | 376 |
375 namespace pnacl { | 377 namespace pnacl { |
376 | 378 |
377 bool NeedsOnDemandUpdate() { | 379 bool NeedsOnDemandUpdate() { |
378 return base::subtle::NoBarrier_Load( | 380 return base::subtle::NoBarrier_Load( |
379 &component_updater::needs_on_demand_update) != 0; | 381 &component_updater::needs_on_demand_update) != 0; |
380 } | 382 } |
381 | 383 |
382 } // namespace pnacl | 384 } // namespace pnacl |
OLD | NEW |