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

Side by Side Diff: chrome/browser/extensions/updater/extension_updater.cc

Issue 9595001: Apps on NTP should be in order of installation (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: A few fixes per comments made Created 8 years, 8 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
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/extensions/updater/extension_updater.h" 5 #include "chrome/browser/extensions/updater/extension_updater.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 return will_check_soon_; 256 return will_check_soon_;
257 } 257 }
258 258
259 void ExtensionUpdater::DoCheckSoon() { 259 void ExtensionUpdater::DoCheckSoon() {
260 DCHECK(will_check_soon_); 260 DCHECK(will_check_soon_);
261 CheckNow(); 261 CheckNow();
262 will_check_soon_ = false; 262 will_check_soon_ = false;
263 } 263 }
264 264
265 void ExtensionUpdater::AddToDownloader(const ExtensionSet* extensions, 265 void ExtensionUpdater::AddToDownloader(const ExtensionSet* extensions,
266 const std::set<std::string>& pending_ids) { 266 const std::list<std::string>& pending_ids) {
267 for (ExtensionSet::const_iterator iter = extensions->begin(); 267 for (ExtensionSet::const_iterator iter = extensions->begin();
Aaron Boodman 2012/04/09 17:02:14 Name this iterator extension_iter and the one belo
mitchellwrosen 2012/04/13 22:20:18 Done.
268 iter != extensions->end(); ++iter) { 268 iter != extensions->end(); ++iter) {
269 const Extension& extension = **iter; 269 const Extension& extension = **iter;
270 if (!Extension::IsAutoUpdateableLocation(extension.location())) { 270 if (!Extension::IsAutoUpdateableLocation(extension.location())) {
271 VLOG(2) << "Extension " << extension.id() << " is not auto updateable"; 271 VLOG(2) << "Extension " << extension.id() << " is not auto updateable";
272 continue; 272 continue;
273 } 273 }
274 // An extension might be overwritten by policy, and have its update url 274 // An extension might be overwritten by policy, and have its update url
275 // changed. Make sure existing extensions aren't fetched again, if a 275 // changed. Make sure existing extensions aren't fetched again, if a
276 // pending fetch for an extension with the same id already exists. 276 // pending fetch for an extension with the same id already exists.
277 if (!ContainsKey(pending_ids, extension.id())) { 277 std::list<std::string>::const_iterator iter2 = std::find(
278 pending_ids.begin(),
279 pending_ids.end(),
280 extension.id());
281 if (iter2 == pending_ids.end()) {
278 if (downloader_->AddExtension(extension)) 282 if (downloader_->AddExtension(extension))
279 in_progress_ids_.insert(extension.id()); 283 in_progress_ids_.push_back(extension.id());
280 } 284 }
281 } 285 }
282 } 286 }
283 287
284 void ExtensionUpdater::CheckNow() { 288 void ExtensionUpdater::CheckNow() {
285 VLOG(2) << "Starting update check"; 289 VLOG(2) << "Starting update check";
286 DCHECK(alive_); 290 DCHECK(alive_);
287 NotifyStarted(); 291 NotifyStarted();
288 292
289 if (!downloader_.get()) { 293 if (!downloader_.get()) {
290 downloader_.reset( 294 downloader_.reset(
291 new ExtensionDownloader(this, profile_->GetRequestContext())); 295 new ExtensionDownloader(this, profile_->GetRequestContext()));
292 } 296 }
293 297
294 // Add fetch records for extensions that should be fetched by an update URL. 298 // Add fetch records for extensions that should be fetched by an update URL.
295 // These extensions are not yet installed. They come from group policy 299 // These extensions are not yet installed. They come from group policy
296 // and external install sources. 300 // and external install sources.
297 const PendingExtensionManager* pending_extension_manager = 301 const PendingExtensionManager* pending_extension_manager =
298 service_->pending_extension_manager(); 302 service_->pending_extension_manager();
299 303
300 std::set<std::string> pending_ids; 304 std::list<std::string> pending_ids;
301 pending_extension_manager->GetPendingIdsForUpdateCheck(&pending_ids); 305 pending_extension_manager->GetPendingIdsForUpdateCheck(&pending_ids);
302 306
303 std::set<std::string>::const_iterator iter; 307 std::list<std::string>::const_iterator iter;
304 for (iter = pending_ids.begin(); iter != pending_ids.end(); ++iter) { 308 for (iter = pending_ids.begin(); iter != pending_ids.end(); ++iter) {
305 PendingExtensionInfo info; 309 const PendingExtensionInfo* info = pending_extension_manager->GetById(
306 bool found_id = pending_extension_manager->GetById(*iter, &info); 310 *iter);
307 DCHECK(found_id); 311 DCHECK(pending_extension_manager);
Aaron Boodman 2012/04/09 17:02:14 I think you meant to DCHECK(info) here. Same with
mitchellwrosen 2012/04/13 22:20:18 Done.
308 if (!found_id) 312 if (!pending_extension_manager)
309 continue; 313 continue;
310 if (!Extension::IsAutoUpdateableLocation(info.install_source())) { 314 if (!Extension::IsAutoUpdateableLocation(info->install_source())) {
311 VLOG(2) << "Extension " << *iter << " is not auto updateable"; 315 VLOG(2) << "Extension " << *iter << " is not auto updateable";
312 continue; 316 continue;
313 } 317 }
314 if (downloader_->AddPendingExtension(*iter, info.update_url())) 318 if (downloader_->AddPendingExtension(*iter, info->update_url()))
315 in_progress_ids_.insert(*iter); 319 in_progress_ids_.push_back(*iter);
316 } 320 }
317 321
318 AddToDownloader(service_->extensions(), pending_ids); 322 AddToDownloader(service_->extensions(), pending_ids);
319 AddToDownloader(service_->disabled_extensions(), pending_ids); 323 AddToDownloader(service_->disabled_extensions(), pending_ids);
320 324
321 // Start a fetch of the blacklist if needed. 325 // Start a fetch of the blacklist if needed.
322 if (blacklist_checks_enabled_) { 326 if (blacklist_checks_enabled_) {
323 ManifestFetchData::PingData ping_data; 327 ManifestFetchData::PingData ping_data;
324 ping_data.rollcall_days = 328 ping_data.rollcall_days =
325 CalculatePingDays(extension_prefs_->BlacklistLastPingDay()); 329 CalculatePingDays(extension_prefs_->BlacklistLastPingDay());
326 downloader_->StartBlacklistUpdate( 330 downloader_->StartBlacklistUpdate(
327 prefs_->GetString(kExtensionBlacklistUpdateVersion), ping_data); 331 prefs_->GetString(kExtensionBlacklistUpdateVersion), ping_data);
328 } 332 }
329 333
330 // StartAllPending() will call OnExtensionUpdateCheckStarted() for each 334 // StartAllPending() will call OnExtensionUpdateCheckStarted() for each
331 // extension that is going to be checked. 335 // extension that is going to be checked.
332 downloader_->StartAllPending(); 336 downloader_->StartAllPending();
333 337
334 NotifyIfFinished(); 338 NotifyIfFinished();
335 } 339 }
336 340
337 void ExtensionUpdater::OnExtensionDownloadFailed(const std::string& id, 341 void ExtensionUpdater::OnExtensionDownloadFailed(const std::string& id,
338 Error error, 342 Error error,
339 const PingResult& ping) { 343 const PingResult& ping) {
340 DCHECK(alive_); 344 DCHECK(alive_);
341 UpdatePingData(id, ping); 345 UpdatePingData(id, ping);
342 in_progress_ids_.erase(id); 346 in_progress_ids_.remove(id);
343 NotifyIfFinished(); 347 NotifyIfFinished();
344 } 348 }
345 349
346 void ExtensionUpdater::OnExtensionDownloadFinished(const std::string& id, 350 void ExtensionUpdater::OnExtensionDownloadFinished(const std::string& id,
347 const FilePath& path, 351 const FilePath& path,
348 const GURL& download_url, 352 const GURL& download_url,
349 const std::string& version, 353 const std::string& version,
350 const PingResult& ping) { 354 const PingResult& ping) {
351 DCHECK(alive_); 355 DCHECK(alive_);
352 UpdatePingData(id, ping); 356 UpdatePingData(id, ping);
353 357
354 VLOG(2) << download_url << " written to " << path.value(); 358 VLOG(2) << download_url << " written to " << path.value();
355 359
356 FetchedCRXFile fetched(id, path, download_url); 360 FetchedCRXFile fetched(id, path, download_url);
357 fetched_crx_files_.push(fetched); 361 fetched_crx_files_.push(fetched);
358 362
359 // MaybeInstallCRXFile() removes extensions from |in_progress_ids_| after 363 // MaybeInstallCRXFile() removes extensions from |in_progress_ids_| after
360 // starting the crx installer. 364 // starting the crx installer.
361 MaybeInstallCRXFile(); 365 MaybeInstallCRXFile();
362 } 366 }
363 367
364 void ExtensionUpdater::OnBlacklistDownloadFinished( 368 void ExtensionUpdater::OnBlacklistDownloadFinished(
365 const std::string& data, 369 const std::string& data,
366 const std::string& package_hash, 370 const std::string& package_hash,
367 const std::string& version, 371 const std::string& version,
368 const PingResult& ping) { 372 const PingResult& ping) {
369 DCHECK(alive_); 373 DCHECK(alive_);
370 UpdatePingData(ExtensionDownloader::kBlacklistAppID, ping); 374 UpdatePingData(ExtensionDownloader::kBlacklistAppID, ping);
371 in_progress_ids_.erase(ExtensionDownloader::kBlacklistAppID); 375 in_progress_ids_.remove(ExtensionDownloader::kBlacklistAppID);
372 NotifyIfFinished(); 376 NotifyIfFinished();
373 377
374 // Verify sha256 hash value. 378 // Verify sha256 hash value.
375 char sha256_hash_value[crypto::kSHA256Length]; 379 char sha256_hash_value[crypto::kSHA256Length];
376 crypto::SHA256HashString(data, sha256_hash_value, crypto::kSHA256Length); 380 crypto::SHA256HashString(data, sha256_hash_value, crypto::kSHA256Length);
377 std::string hash_in_hex = base::HexEncode(sha256_hash_value, 381 std::string hash_in_hex = base::HexEncode(sha256_hash_value,
378 crypto::kSHA256Length); 382 crypto::kSHA256Length);
379 383
380 if (package_hash != hash_in_hex) { 384 if (package_hash != hash_in_hex) {
381 NOTREACHED() << "Fetched blacklist checksum is not as expected. " 385 NOTREACHED() << "Fetched blacklist checksum is not as expected. "
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 crx_file.download_url, 465 crx_file.download_url,
462 &installer)) { 466 &installer)) {
463 crx_install_is_running_ = true; 467 crx_install_is_running_ = true;
464 468
465 // Source parameter ensures that we only see the completion event for the 469 // Source parameter ensures that we only see the completion event for the
466 // the installer we started. 470 // the installer we started.
467 registrar_.Add(this, 471 registrar_.Add(this,
468 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 472 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
469 content::Source<CrxInstaller>(installer)); 473 content::Source<CrxInstaller>(installer));
470 } 474 }
471 in_progress_ids_.erase(crx_file.id); 475 in_progress_ids_.remove(crx_file.id);
472 fetched_crx_files_.pop(); 476 fetched_crx_files_.pop();
473 } 477 }
474 478
475 NotifyIfFinished(); 479 NotifyIfFinished();
476 } 480 }
477 481
478 void ExtensionUpdater::Observe(int type, 482 void ExtensionUpdater::Observe(int type,
479 const content::NotificationSource& source, 483 const content::NotificationSource& source,
480 const content::NotificationDetails& details) { 484 const content::NotificationDetails& details) {
481 DCHECK(type == chrome::NOTIFICATION_CRX_INSTALLER_DONE); 485 DCHECK(type == chrome::NOTIFICATION_CRX_INSTALLER_DONE);
(...skipping 18 matching lines...) Expand all
500 if (in_progress_ids_.empty()) { 504 if (in_progress_ids_.empty()) {
501 VLOG(1) << "Sending EXTENSION_UPDATING_FINISHED"; 505 VLOG(1) << "Sending EXTENSION_UPDATING_FINISHED";
502 content::NotificationService::current()->Notify( 506 content::NotificationService::current()->Notify(
503 chrome::NOTIFICATION_EXTENSION_UPDATING_FINISHED, 507 chrome::NOTIFICATION_EXTENSION_UPDATING_FINISHED,
504 content::Source<Profile>(profile_), 508 content::Source<Profile>(profile_),
505 content::NotificationService::NoDetails()); 509 content::NotificationService::NoDetails());
506 } 510 }
507 } 511 }
508 512
509 } // namespace extensions 513 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698