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