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/extensions/updater/extension_updater.h" | 5 #include "chrome/browser/extensions/updater/extension_updater.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <set> | 10 #include <set> |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 if (last_active_ping_day.is_null()) | 90 if (last_active_ping_day.is_null()) |
91 return extensions::ManifestFetchData::kNeverPinged; | 91 return extensions::ManifestFetchData::kNeverPinged; |
92 return SanitizeDays((Time::Now() - last_active_ping_day).InDays()); | 92 return SanitizeDays((Time::Now() - last_active_ping_day).InDays()); |
93 } | 93 } |
94 | 94 |
95 } // namespace | 95 } // namespace |
96 | 96 |
97 namespace extensions { | 97 namespace extensions { |
98 | 98 |
99 ExtensionUpdater::CheckParams::CheckParams() | 99 ExtensionUpdater::CheckParams::CheckParams() |
100 : install_immediately(false) {} | 100 : install_immediately(false), |
| 101 fetch_priority(ManifestFetchData::FetchPriority::BACKGROUND) {} |
101 | 102 |
102 ExtensionUpdater::CheckParams::~CheckParams() {} | 103 ExtensionUpdater::CheckParams::~CheckParams() {} |
103 | 104 |
104 ExtensionUpdater::FetchedCRXFile::FetchedCRXFile( | 105 ExtensionUpdater::FetchedCRXFile::FetchedCRXFile( |
105 const CRXFileInfo& file, | 106 const CRXFileInfo& file, |
106 bool file_ownership_passed, | 107 bool file_ownership_passed, |
107 const std::set<int>& request_ids, | 108 const std::set<int>& request_ids, |
108 const InstallCallback& callback) | 109 const InstallCallback& callback) |
109 : info(file), | 110 : info(file), |
110 file_ownership_passed(file_ownership_passed), | 111 file_ownership_passed(file_ownership_passed), |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 | 300 |
300 void ExtensionUpdater::DoCheckSoon() { | 301 void ExtensionUpdater::DoCheckSoon() { |
301 DCHECK(will_check_soon_); | 302 DCHECK(will_check_soon_); |
302 CheckNow(CheckParams()); | 303 CheckNow(CheckParams()); |
303 will_check_soon_ = false; | 304 will_check_soon_ = false; |
304 } | 305 } |
305 | 306 |
306 void ExtensionUpdater::AddToDownloader( | 307 void ExtensionUpdater::AddToDownloader( |
307 const ExtensionSet* extensions, | 308 const ExtensionSet* extensions, |
308 const std::list<std::string>& pending_ids, | 309 const std::list<std::string>& pending_ids, |
309 int request_id) { | 310 int request_id, |
| 311 ManifestFetchData::FetchPriority fetch_priority) { |
310 InProgressCheck& request = requests_in_progress_[request_id]; | 312 InProgressCheck& request = requests_in_progress_[request_id]; |
311 for (ExtensionSet::const_iterator extension_iter = extensions->begin(); | 313 for (ExtensionSet::const_iterator extension_iter = extensions->begin(); |
312 extension_iter != extensions->end(); ++extension_iter) { | 314 extension_iter != extensions->end(); ++extension_iter) { |
313 const Extension& extension = **extension_iter; | 315 const Extension& extension = **extension_iter; |
314 if (!Manifest::IsAutoUpdateableLocation(extension.location())) { | 316 if (!Manifest::IsAutoUpdateableLocation(extension.location())) { |
315 VLOG(2) << "Extension " << extension.id() << " is not auto updateable"; | 317 VLOG(2) << "Extension " << extension.id() << " is not auto updateable"; |
316 continue; | 318 continue; |
317 } | 319 } |
318 // An extension might be overwritten by policy, and have its update url | 320 // An extension might be overwritten by policy, and have its update url |
319 // changed. Make sure existing extensions aren't fetched again, if a | 321 // changed. Make sure existing extensions aren't fetched again, if a |
320 // pending fetch for an extension with the same id already exists. | 322 // pending fetch for an extension with the same id already exists. |
321 std::list<std::string>::const_iterator pending_id_iter = std::find( | 323 std::list<std::string>::const_iterator pending_id_iter = std::find( |
322 pending_ids.begin(), pending_ids.end(), extension.id()); | 324 pending_ids.begin(), pending_ids.end(), extension.id()); |
323 if (pending_id_iter == pending_ids.end()) { | 325 if (pending_id_iter == pending_ids.end()) { |
324 if (downloader_->AddExtension(extension, request_id)) | 326 if (downloader_->AddExtension(extension, request_id, fetch_priority)) |
325 request.in_progress_ids_.push_back(extension.id()); | 327 request.in_progress_ids_.push_back(extension.id()); |
326 } | 328 } |
327 } | 329 } |
328 } | 330 } |
329 | 331 |
330 void ExtensionUpdater::CheckNow(const CheckParams& params) { | 332 void ExtensionUpdater::CheckNow(const CheckParams& params) { |
331 int request_id = next_request_id_++; | 333 int request_id = next_request_id_++; |
332 | 334 |
333 VLOG(2) << "Starting update check " << request_id; | 335 VLOG(2) << "Starting update check " << request_id; |
334 if (params.ids.empty()) | 336 if (params.ids.empty()) |
(...skipping 24 matching lines...) Expand all Loading... |
359 const PendingExtensionInfo* info = pending_extension_manager->GetById( | 361 const PendingExtensionInfo* info = pending_extension_manager->GetById( |
360 *iter); | 362 *iter); |
361 if (!Manifest::IsAutoUpdateableLocation(info->install_source())) { | 363 if (!Manifest::IsAutoUpdateableLocation(info->install_source())) { |
362 VLOG(2) << "Extension " << *iter << " is not auto updateable"; | 364 VLOG(2) << "Extension " << *iter << " is not auto updateable"; |
363 continue; | 365 continue; |
364 } | 366 } |
365 if (downloader_->AddPendingExtension( | 367 if (downloader_->AddPendingExtension( |
366 *iter, info->update_url(), | 368 *iter, info->update_url(), |
367 pending_extension_manager->IsPolicyReinstallForCorruptionExpected( | 369 pending_extension_manager->IsPolicyReinstallForCorruptionExpected( |
368 *iter), | 370 *iter), |
369 request_id)) | 371 request_id, params.fetch_priority)) |
370 request.in_progress_ids_.push_back(*iter); | 372 request.in_progress_ids_.push_back(*iter); |
371 } | 373 } |
372 | 374 |
373 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_); | 375 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_); |
374 AddToDownloader(®istry->enabled_extensions(), pending_ids, request_id); | 376 AddToDownloader(®istry->enabled_extensions(), pending_ids, request_id, |
375 AddToDownloader(®istry->disabled_extensions(), pending_ids, request_id); | 377 params.fetch_priority); |
| 378 AddToDownloader(®istry->disabled_extensions(), pending_ids, request_id, |
| 379 params.fetch_priority); |
376 } else { | 380 } else { |
377 for (std::list<std::string>::const_iterator it = params.ids.begin(); | 381 for (std::list<std::string>::const_iterator it = params.ids.begin(); |
378 it != params.ids.end(); ++it) { | 382 it != params.ids.end(); ++it) { |
379 const Extension* extension = service_->GetExtensionById(*it, true); | 383 const Extension* extension = service_->GetExtensionById(*it, true); |
380 if (extension && downloader_->AddExtension(*extension, request_id)) | 384 if (extension && downloader_->AddExtension(*extension, request_id, |
| 385 params.fetch_priority)) |
381 request.in_progress_ids_.push_back(extension->id()); | 386 request.in_progress_ids_.push_back(extension->id()); |
382 } | 387 } |
383 } | 388 } |
384 | 389 |
385 // StartAllPending() might call OnExtensionDownloadFailed/Finished before | 390 // StartAllPending() might call OnExtensionDownloadFailed/Finished before |
386 // it returns, which would cause NotifyIfFinished to incorrectly try to | 391 // it returns, which would cause NotifyIfFinished to incorrectly try to |
387 // send out a notification. So check before we call StartAllPending if any | 392 // send out a notification. So check before we call StartAllPending if any |
388 // extensions are going to be updated, and use that to figure out if | 393 // extensions are going to be updated, and use that to figure out if |
389 // NotifyIfFinished should be called. | 394 // NotifyIfFinished should be called. |
390 bool noChecks = request.in_progress_ids_.empty(); | 395 bool noChecks = request.in_progress_ids_.empty(); |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 const InProgressCheck& request = requests_in_progress_[request_id]; | 607 const InProgressCheck& request = requests_in_progress_[request_id]; |
603 if (request.in_progress_ids_.empty()) { | 608 if (request.in_progress_ids_.empty()) { |
604 VLOG(2) << "Finished update check " << request_id; | 609 VLOG(2) << "Finished update check " << request_id; |
605 if (!request.callback.is_null()) | 610 if (!request.callback.is_null()) |
606 request.callback.Run(); | 611 request.callback.Run(); |
607 requests_in_progress_.erase(request_id); | 612 requests_in_progress_.erase(request_id); |
608 } | 613 } |
609 } | 614 } |
610 | 615 |
611 } // namespace extensions | 616 } // namespace extensions |
OLD | NEW |