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

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

Issue 18006003: Consistently use notifications from component updater w/ on-demand PNaCl. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more cleanup Created 7 years, 4 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/callback.h" 9 #include "base/callback.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 // Read the component's manifest.json. 130 // Read the component's manifest.json.
131 base::DictionaryValue* ReadComponentManifest( 131 base::DictionaryValue* ReadComponentManifest(
132 const base::FilePath& unpack_path) { 132 const base::FilePath& unpack_path) {
133 base::FilePath manifest_path = unpack_path.Append( 133 base::FilePath manifest_path = unpack_path.Append(
134 FILE_PATH_LITERAL("manifest.json")); 134 FILE_PATH_LITERAL("manifest.json"));
135 if (!base::PathExists(manifest_path)) 135 if (!base::PathExists(manifest_path))
136 return NULL; 136 return NULL;
137 return ReadJSONManifest(manifest_path); 137 return ReadJSONManifest(manifest_path);
138 } 138 }
139 139
140 } // namespace
141
142 // Check that the component's manifest is for PNaCl, and check the 140 // Check that the component's manifest is for PNaCl, and check the
143 // PNaCl manifest indicates this is the correct arch-specific package. 141 // PNaCl manifest indicates this is the correct arch-specific package.
144 bool CheckPnaclComponentManifest(const base::DictionaryValue& manifest, 142 bool CheckPnaclComponentManifest(const base::DictionaryValue& manifest,
145 const base::DictionaryValue& pnacl_manifest, 143 const base::DictionaryValue& pnacl_manifest,
146 Version* version_out) { 144 Version* version_out) {
147 // Make sure we have the right |manifest| file. 145 // Make sure we have the right |manifest| file.
148 std::string name; 146 std::string name;
149 if (!manifest.GetStringASCII("name", &name)) { 147 if (!manifest.GetStringASCII("name", &name)) {
150 LOG(WARNING) << "'name' field is missing from manifest!"; 148 LOG(WARNING) << "'name' field is missing from manifest!";
151 return false; 149 return false;
(...skipping 29 matching lines...) Expand all
181 if (arch.compare(OmahaQueryParams::getNaclArch()) != 0) { 179 if (arch.compare(OmahaQueryParams::getNaclArch()) != 0) {
182 LOG(WARNING) << "'pnacl-arch' field in manifest is invalid (" 180 LOG(WARNING) << "'pnacl-arch' field in manifest is invalid ("
183 << arch << " vs " << OmahaQueryParams::getNaclArch() << ")"; 181 << arch << " vs " << OmahaQueryParams::getNaclArch() << ")";
184 return false; 182 return false;
185 } 183 }
186 184
187 *version_out = version; 185 *version_out = version;
188 return true; 186 return true;
189 } 187 }
190 188
189 } // namespace
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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 bool PnaclComponentInstaller::GetInstalledFile( 291 bool PnaclComponentInstaller::GetInstalledFile(
293 const std::string& file, base::FilePath* installed_file) { 292 const std::string& file, base::FilePath* installed_file) {
294 if (current_version().Equals(Version(kNullVersion))) 293 if (current_version().Equals(Version(kNullVersion)))
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(
303 const InstallCallback& cb) {
304 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
305 int num = ++callback_nums_;
306 install_callbacks_.push_back(std::make_pair(cb, num));
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 }
321
322 void PnaclComponentInstaller::NotifyAllWithResult(bool status) {
323 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
324 while (!install_callbacks_.empty()) {
325 install_callbacks_.front().first.Run(status);
326 install_callbacks_.pop_front();
327 }
328 }
329
330 void PnaclComponentInstaller::NotifyInstallError() { 301 void PnaclComponentInstaller::NotifyInstallError() {
331 if (!install_callbacks_.empty()) { 302 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
332 BrowserThread::PostTask( 303 BrowserThread::PostTask(
333 BrowserThread::UI, FROM_HERE, 304 BrowserThread::UI, FROM_HERE,
334 base::Bind(&PnaclComponentInstaller::NotifyAllWithResult, 305 base::Bind(&PnaclComponentInstaller::NotifyInstallError,
335 // Unretained because installer lives until process shutdown. 306 // Unretained because installer lives until process shutdown.
336 base::Unretained(this), false)); 307 base::Unretained(this)));
308 return;
309 }
310 if (!install_callback_.is_null()) {
311 install_callback_.Run(false);
312 install_callback_.Reset();
313 updater_observer_->StopObserving();
337 } 314 }
338 } 315 }
339 316
340 void PnaclComponentInstaller::NotifyInstallSuccess() { 317 void PnaclComponentInstaller::NotifyInstallSuccess() {
341 if (!install_callbacks_.empty()) { 318 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
342 BrowserThread::PostTask( 319 BrowserThread::PostTask(
343 BrowserThread::UI, FROM_HERE, 320 BrowserThread::UI, FROM_HERE,
344 base::Bind(&PnaclComponentInstaller::NotifyAllWithResult, 321 base::Bind(&PnaclComponentInstaller::NotifyInstallSuccess,
345 // Unretained because installer lives until process shutdown. 322 // Unretained because installer lives until process shutdown.
346 base::Unretained(this), true)); 323 base::Unretained(this)));
324 return;
347 } 325 }
326 if (!install_callback_.is_null()) {
327 install_callback_.Run(true);
328 install_callback_.Reset();
329 updater_observer_->StopObserving();
330 }
331 }
332
333 CrxComponent PnaclComponentInstaller::GetCrxComponent() {
334 CrxComponent pnacl_component;
335 pnacl_component.version = current_version();
336 pnacl_component.name = "pnacl";
337 pnacl_component.installer = this;
338 pnacl_component.observer = updater_observer_.get();
339 SetPnaclHash(&pnacl_component);
340
341 return pnacl_component;
348 } 342 }
349 343
350 namespace { 344 namespace {
351 345
352 void FinishPnaclUpdateRegistration(const Version& current_version, 346 void FinishPnaclUpdateRegistration(const Version& current_version,
353 PnaclComponentInstaller* pci) { 347 PnaclComponentInstaller* pci) {
354 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 348 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); 349 pci->set_current_version(current_version);
360 SetPnaclHash(&pnacl_component); 350 CrxComponent pnacl_component = pci->GetCrxComponent();
361 351
362 ComponentUpdateService::Status status = 352 ComponentUpdateService::Status status =
363 pci->cus()->RegisterComponent(pnacl_component); 353 pci->cus()->RegisterComponent(pnacl_component);
364 if (status != ComponentUpdateService::kOk 354 if (status != ComponentUpdateService::kOk
365 && status != ComponentUpdateService::kReplaced) { 355 && status != ComponentUpdateService::kReplaced) {
366 NOTREACHED() << "Pnacl component registration failed."; 356 NOTREACHED() << "Pnacl component registration failed.";
367 } 357 }
368 } 358 }
369 359
370 // Check if there is an existing version on disk first to know when 360 // Check if there is an existing version on disk first to know when
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 } 464 }
475 465
476 void PnaclComponentInstaller::ReRegisterPnacl() { 466 void PnaclComponentInstaller::ReRegisterPnacl() {
477 DCHECK(per_user_); 467 DCHECK(per_user_);
478 // Figure out profile information, before proceeding to look for files. 468 // Figure out profile information, before proceeding to look for files.
479 BrowserThread::PostTask( 469 BrowserThread::PostTask(
480 BrowserThread::UI, FROM_HERE, 470 BrowserThread::UI, FROM_HERE,
481 base::Bind(&GetProfileInformation, this)); 471 base::Bind(&GetProfileInformation, this));
482 } 472 }
483 473
484 void RequestFirstInstall(ComponentUpdateService* cus, 474 void PnaclComponentInstaller::RequestFirstInstall(
Sorin Jianu 2013/08/05 19:24:58 does the argument fit on the line above?
jvoung (off chromium) 2013/08/05 20:36:03 Done.
485 PnaclComponentInstaller* pci, 475 const InstallCallback& cb) {
486 const base::Callback<void(bool)>& installed) {
487 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 476 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
488 Version null_version(kNullVersion); 477 // Only one request can happen at once.
489 CrxComponent pnacl_component; 478 if (!install_callback_.is_null()) {
490 pci->set_current_version(null_version); 479 cb.Run(false);
491 pnacl_component.version = null_version; 480 return;
492 pnacl_component.name = "pnacl"; 481 }
493 pnacl_component.installer = pci; 482 set_current_version(Version(kNullVersion));
494 SetPnaclHash(&pnacl_component); 483 CrxComponent pnacl_component = GetCrxComponent();
495 ComponentUpdateService::Status status = cus->CheckForUpdateSoon( 484 ComponentUpdateService::Status status = cus_->CheckForUpdateSoon(
496 pnacl_component); 485 pnacl_component);
497 if (status != ComponentUpdateService::kOk) { 486 if (status != ComponentUpdateService::kOk) {
498 installed.Run(false); 487 cb.Run(false);
499 return; 488 return;
500 } 489 }
501 pci->AddInstallCallback(installed); 490 install_callback_ = cb;
491 updater_observer_->EnsureObserving();
502 } 492 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698