Chromium Code Reviews| 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/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 return false; | 184 return false; |
| 185 } | 185 } |
| 186 | 186 |
| 187 *version_out = version; | 187 *version_out = version; |
| 188 return true; | 188 return true; |
| 189 } | 189 } |
| 190 | 190 |
| 191 PnaclComponentInstaller::PnaclComponentInstaller() | 191 PnaclComponentInstaller::PnaclComponentInstaller() |
| 192 : per_user_(false), | 192 : per_user_(false), |
| 193 updates_disabled_(false), | 193 updates_disabled_(false), |
| 194 cus_(NULL), | 194 cus_(NULL) { |
| 195 callback_nums_(0) { | |
| 196 #if defined(OS_CHROMEOS) | 195 #if defined(OS_CHROMEOS) |
| 197 per_user_ = true; | 196 per_user_ = true; |
| 198 #endif | 197 #endif |
| 199 updater_observer_.reset(new PnaclUpdaterObserver(this)); | 198 updater_observer_.reset(new PnaclUpdaterObserver(this)); |
| 200 } | 199 } |
| 201 | 200 |
| 202 PnaclComponentInstaller::~PnaclComponentInstaller() { | 201 PnaclComponentInstaller::~PnaclComponentInstaller() { |
| 203 } | 202 } |
| 204 | 203 |
| 205 void PnaclComponentInstaller::OnUpdateError(int error) { | 204 void PnaclComponentInstaller::OnUpdateError(int error) { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 295 return false; | 294 return false; |
| 296 | 295 |
| 297 *installed_file = GetPnaclBaseDirectory().AppendASCII( | 296 *installed_file = GetPnaclBaseDirectory().AppendASCII( |
| 298 current_version().GetString()).AppendASCII(file); | 297 current_version().GetString()).AppendASCII(file); |
| 299 return true; | 298 return true; |
| 300 } | 299 } |
| 301 | 300 |
| 302 void PnaclComponentInstaller::AddInstallCallback( | 301 void PnaclComponentInstaller::AddInstallCallback( |
| 303 const InstallCallback& cb) { | 302 const InstallCallback& cb) { |
| 304 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 303 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 305 int num = ++callback_nums_; | 304 updater_observer_->EnsureObserving(); |
| 306 install_callbacks_.push_back(std::make_pair(cb, num)); | 305 install_callbacks_.push_back(cb); |
| 307 } | |
| 308 | |
| 309 void PnaclComponentInstaller::CancelCallback(int num) { | |
| 310 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 311 for (std::list<std::pair<InstallCallback, int> >::iterator | |
| 312 i = install_callbacks_.begin(), | |
| 313 e = install_callbacks_.end(); i != e; ++i) { | |
| 314 if (i->second == num) { | |
| 315 i->first.Run(false); | |
| 316 install_callbacks_.erase(i); | |
| 317 return; | |
| 318 } | |
| 319 } | |
| 320 } | 306 } |
| 321 | 307 |
| 322 void PnaclComponentInstaller::NotifyAllWithResult(bool status) { | 308 void PnaclComponentInstaller::NotifyAllWithResult(bool status) { |
| 323 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 309 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 324 while (!install_callbacks_.empty()) { | 310 while (!install_callbacks_.empty()) { |
| 325 install_callbacks_.front().first.Run(status); | 311 install_callbacks_.front().Run(status); |
| 326 install_callbacks_.pop_front(); | 312 install_callbacks_.pop_front(); |
| 327 } | 313 } |
| 328 } | 314 } |
| 329 | 315 |
| 330 void PnaclComponentInstaller::NotifyInstallError() { | 316 void PnaclComponentInstaller::NotifyInstallError() { |
| 331 if (!install_callbacks_.empty()) { | 317 if (!install_callbacks_.empty()) { |
| 332 BrowserThread::PostTask( | 318 BrowserThread::PostTask( |
| 333 BrowserThread::UI, FROM_HERE, | 319 BrowserThread::UI, FROM_HERE, |
| 334 base::Bind(&PnaclComponentInstaller::NotifyAllWithResult, | 320 base::Bind(&PnaclComponentInstaller::NotifyAllWithResult, |
| 335 // Unretained because installer lives until process shutdown. | 321 // Unretained because installer lives until process shutdown. |
| 336 base::Unretained(this), false)); | 322 base::Unretained(this), false)); |
| 337 } | 323 } |
| 338 } | 324 } |
| 339 | 325 |
| 340 void PnaclComponentInstaller::NotifyInstallSuccess() { | 326 void PnaclComponentInstaller::NotifyInstallSuccess() { |
| 341 if (!install_callbacks_.empty()) { | 327 if (!install_callbacks_.empty()) { |
| 342 BrowserThread::PostTask( | 328 BrowserThread::PostTask( |
| 343 BrowserThread::UI, FROM_HERE, | 329 BrowserThread::UI, FROM_HERE, |
| 344 base::Bind(&PnaclComponentInstaller::NotifyAllWithResult, | 330 base::Bind(&PnaclComponentInstaller::NotifyAllWithResult, |
| 345 // Unretained because installer lives until process shutdown. | 331 // Unretained because installer lives until process shutdown. |
| 346 base::Unretained(this), true)); | 332 base::Unretained(this), true)); |
| 347 } | 333 } |
| 348 } | 334 } |
| 349 | 335 |
| 336 CrxComponent PnaclComponentInstaller::GetCrxComponent() const { | |
|
Sorin Jianu
2013/07/03 23:10:04
In this case, I suggest dropping the const declara
jvoung (off chromium)
2013/07/04 01:11:04
Done.
| |
| 337 CrxComponent pnacl_component; | |
| 338 pnacl_component.version = current_version(); | |
| 339 pnacl_component.name = "pnacl"; | |
| 340 pnacl_component.installer = const_cast<PnaclComponentInstaller*>(this); | |
| 341 SetPnaclHash(&pnacl_component); | |
| 342 | |
| 343 return pnacl_component; | |
| 344 } | |
| 345 | |
| 350 namespace { | 346 namespace { |
| 351 | 347 |
| 352 void FinishPnaclUpdateRegistration(const Version& current_version, | 348 void FinishPnaclUpdateRegistration(const Version& current_version, |
| 353 PnaclComponentInstaller* pci) { | 349 PnaclComponentInstaller* pci) { |
| 354 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 350 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 355 CrxComponent pnacl_component; | |
| 356 pnacl_component.version = current_version; | |
| 357 pnacl_component.name = "pnacl"; | |
| 358 pnacl_component.installer = pci; | |
| 359 pci->set_current_version(current_version); | 351 pci->set_current_version(current_version); |
| 360 SetPnaclHash(&pnacl_component); | 352 const CrxComponent pnacl_component = pci->GetCrxComponent(); |
| 361 | 353 |
| 362 ComponentUpdateService::Status status = | 354 ComponentUpdateService::Status status = |
| 363 pci->cus()->RegisterComponent(pnacl_component); | 355 pci->cus()->RegisterComponent(pnacl_component); |
| 364 if (status != ComponentUpdateService::kOk | 356 if (status != ComponentUpdateService::kOk |
| 365 && status != ComponentUpdateService::kReplaced) { | 357 && status != ComponentUpdateService::kReplaced) { |
| 366 NOTREACHED() << "Pnacl component registration failed."; | 358 NOTREACHED() << "Pnacl component registration failed."; |
| 367 } | 359 } |
| 368 } | 360 } |
| 369 | 361 |
| 370 // Check if there is an existing version on disk first to know when | 362 // Check if there is an existing version on disk first to know when |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 461 // Figure out profile information, before proceeding to look for files. | 453 // Figure out profile information, before proceeding to look for files. |
| 462 BrowserThread::PostTask( | 454 BrowserThread::PostTask( |
| 463 BrowserThread::UI, FROM_HERE, | 455 BrowserThread::UI, FROM_HERE, |
| 464 base::Bind(&GetProfileInformation, this)); | 456 base::Bind(&GetProfileInformation, this)); |
| 465 } | 457 } |
| 466 | 458 |
| 467 void RequestFirstInstall(ComponentUpdateService* cus, | 459 void RequestFirstInstall(ComponentUpdateService* cus, |
| 468 PnaclComponentInstaller* pci, | 460 PnaclComponentInstaller* pci, |
| 469 const base::Callback<void(bool)>& installed) { | 461 const base::Callback<void(bool)>& installed) { |
| 470 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 462 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 471 Version null_version(kNullVersion); | 463 pci->set_current_version(Version(kNullVersion)); |
| 472 CrxComponent pnacl_component; | 464 const CrxComponent pnacl_component = pci->GetCrxComponent(); |
| 473 pci->set_current_version(null_version); | |
| 474 pnacl_component.version = null_version; | |
| 475 pnacl_component.name = "pnacl"; | |
| 476 pnacl_component.installer = pci; | |
| 477 SetPnaclHash(&pnacl_component); | |
| 478 ComponentUpdateService::Status status = cus->CheckForUpdateSoon( | 465 ComponentUpdateService::Status status = cus->CheckForUpdateSoon( |
| 479 pnacl_component); | 466 pnacl_component); |
| 480 if (status != ComponentUpdateService::kOk) { | 467 if (status != ComponentUpdateService::kOk) { |
| 481 installed.Run(false); | 468 installed.Run(false); |
| 482 return; | 469 return; |
| 483 } | 470 } |
| 484 pci->AddInstallCallback(installed); | 471 pci->AddInstallCallback(installed); |
| 485 } | 472 } |
| OLD | NEW |