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 <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
14 #include "base/rand_util.h" | 14 #include "base/rand_util.h" |
15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
16 #include "base/string_number_conversions.h" | 16 #include "base/string_number_conversions.h" |
17 #include "base/string_split.h" | 17 #include "base/string_split.h" |
18 #include "chrome/browser/extensions/crx_installer.h" | 18 #include "chrome/browser/extensions/crx_installer.h" |
19 #include "chrome/browser/extensions/extension_service.h" | 19 #include "chrome/browser/extensions/extension_service.h" |
20 #include "chrome/browser/extensions/pending_extension_manager.h" | 20 #include "chrome/browser/extensions/pending_extension_manager.h" |
21 #include "chrome/browser/extensions/updater/extension_downloader.h" | 21 #include "chrome/browser/extensions/updater/extension_downloader.h" |
22 #include "chrome/browser/prefs/pref_service.h" | 22 #include "chrome/browser/prefs/pref_service.h" |
23 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/common/chrome_notification_types.h" | 24 #include "chrome/common/chrome_notification_types.h" |
25 #include "chrome/common/extensions/extension.h" | 25 #include "chrome/common/extensions/extension.h" |
26 #include "chrome/common/extensions/extension_set.h" | |
27 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
28 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
29 #include "content/public/browser/notification_details.h" | 28 #include "content/public/browser/notification_details.h" |
30 #include "content/public/browser/notification_service.h" | 29 #include "content/public/browser/notification_service.h" |
31 #include "content/public/browser/notification_source.h" | 30 #include "content/public/browser/notification_source.h" |
32 #include "crypto/sha2.h" | 31 #include "crypto/sha2.h" |
33 | 32 |
34 using base::RandDouble; | 33 using base::RandDouble; |
35 using base::RandInt; | 34 using base::RandInt; |
36 using base::Time; | 35 using base::Time; |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 bool ExtensionUpdater::WillCheckSoon() const { | 254 bool ExtensionUpdater::WillCheckSoon() const { |
256 return will_check_soon_; | 255 return will_check_soon_; |
257 } | 256 } |
258 | 257 |
259 void ExtensionUpdater::DoCheckSoon() { | 258 void ExtensionUpdater::DoCheckSoon() { |
260 DCHECK(will_check_soon_); | 259 DCHECK(will_check_soon_); |
261 CheckNow(); | 260 CheckNow(); |
262 will_check_soon_ = false; | 261 will_check_soon_ = false; |
263 } | 262 } |
264 | 263 |
| 264 void ExtensionUpdater::AddToDownloader(const ExtensionSet* extensions, |
| 265 const std::set<std::string>& pending_ids) { |
| 266 for (ExtensionSet::const_iterator iter = extensions->begin(); |
| 267 iter != extensions->end(); ++iter) { |
| 268 const Extension& extension = **iter; |
| 269 if (!Extension::IsAutoUpdateableLocation(extension.location())) { |
| 270 VLOG(2) << "Extension " << extension.id() << " is not auto updateable"; |
| 271 continue; |
| 272 } |
| 273 // An extension might be overwritten by policy, and have its update url |
| 274 // changed. Make sure existing extensions aren't fetched again, if a |
| 275 // pending fetch for an extension with the same id already exists. |
| 276 if (!ContainsKey(pending_ids, extension.id())) { |
| 277 if (downloader_->AddExtension(extension)) |
| 278 in_progress_ids_.insert(extension.id()); |
| 279 } |
| 280 } |
| 281 } |
| 282 |
265 void ExtensionUpdater::CheckNow() { | 283 void ExtensionUpdater::CheckNow() { |
266 VLOG(2) << "Starting update check"; | 284 VLOG(2) << "Starting update check"; |
267 DCHECK(alive_); | 285 DCHECK(alive_); |
268 NotifyStarted(); | 286 NotifyStarted(); |
269 | 287 |
270 if (!downloader_.get()) { | 288 if (!downloader_.get()) { |
271 downloader_.reset( | 289 downloader_.reset( |
272 new ExtensionDownloader(this, profile_->GetRequestContext())); | 290 new ExtensionDownloader(this, profile_->GetRequestContext())); |
273 } | 291 } |
274 | 292 |
(...skipping 14 matching lines...) Expand all Loading... |
289 if (!found_id) | 307 if (!found_id) |
290 continue; | 308 continue; |
291 if (!Extension::IsAutoUpdateableLocation(info.install_source())) { | 309 if (!Extension::IsAutoUpdateableLocation(info.install_source())) { |
292 VLOG(2) << "Extension " << *iter << " is not auto updateable"; | 310 VLOG(2) << "Extension " << *iter << " is not auto updateable"; |
293 continue; | 311 continue; |
294 } | 312 } |
295 if (downloader_->AddPendingExtension(*iter, info.update_url())) | 313 if (downloader_->AddPendingExtension(*iter, info.update_url())) |
296 in_progress_ids_.insert(*iter); | 314 in_progress_ids_.insert(*iter); |
297 } | 315 } |
298 | 316 |
299 // Add fetch records for extensions that are installed and have an | 317 AddToDownloader(service_->extensions(), pending_ids); |
300 // update URL. | 318 AddToDownloader(service_->disabled_extensions(), pending_ids); |
301 const ExtensionSet* extensions = service_->extensions(); | |
302 for (ExtensionSet::const_iterator iter = extensions->begin(); | |
303 iter != extensions->end(); ++iter) { | |
304 const Extension& extension = **iter; | |
305 if (!Extension::IsAutoUpdateableLocation(extension.location())) { | |
306 VLOG(2) << "Extension " << extension.id() << " is not auto updateable"; | |
307 continue; | |
308 } | |
309 // An extension might be overwritten by policy, and have its update url | |
310 // changed. Make sure existing extensions aren't fetched again, if a | |
311 // pending fetch for an extension with the same id already exists. | |
312 if (!ContainsKey(pending_ids, extension.id())) { | |
313 if (downloader_->AddExtension(extension)) | |
314 in_progress_ids_.insert(extension.id()); | |
315 } | |
316 } | |
317 | 319 |
318 // Start a fetch of the blacklist if needed. | 320 // Start a fetch of the blacklist if needed. |
319 if (blacklist_checks_enabled_) { | 321 if (blacklist_checks_enabled_) { |
320 ManifestFetchData::PingData ping_data; | 322 ManifestFetchData::PingData ping_data; |
321 ping_data.rollcall_days = | 323 ping_data.rollcall_days = |
322 CalculatePingDays(extension_prefs_->BlacklistLastPingDay()); | 324 CalculatePingDays(extension_prefs_->BlacklistLastPingDay()); |
323 downloader_->StartBlacklistUpdate( | 325 downloader_->StartBlacklistUpdate( |
324 prefs_->GetString(kExtensionBlacklistUpdateVersion), ping_data); | 326 prefs_->GetString(kExtensionBlacklistUpdateVersion), ping_data); |
325 } | 327 } |
326 | 328 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 return service_->pending_extension_manager()->IsIdPending(id); | 412 return service_->pending_extension_manager()->IsIdPending(id); |
411 } | 413 } |
412 | 414 |
413 bool ExtensionUpdater::GetExtensionExistingVersion(const std::string& id, | 415 bool ExtensionUpdater::GetExtensionExistingVersion(const std::string& id, |
414 std::string* version) { | 416 std::string* version) { |
415 DCHECK(alive_); | 417 DCHECK(alive_); |
416 if (id == ExtensionDownloader::kBlacklistAppID) { | 418 if (id == ExtensionDownloader::kBlacklistAppID) { |
417 *version = prefs_->GetString(kExtensionBlacklistUpdateVersion); | 419 *version = prefs_->GetString(kExtensionBlacklistUpdateVersion); |
418 return true; | 420 return true; |
419 } | 421 } |
420 const Extension* extension = service_->GetExtensionById(id, false); | 422 const Extension* extension = service_->GetExtensionById(id, true); |
421 if (!extension) | 423 if (!extension) |
422 return false; | 424 return false; |
423 *version = extension->version()->GetString(); | 425 *version = extension->version()->GetString(); |
424 return true; | 426 return true; |
425 } | 427 } |
426 | 428 |
427 void ExtensionUpdater::UpdatePingData(const std::string& id, | 429 void ExtensionUpdater::UpdatePingData(const std::string& id, |
428 const PingResult& ping_result) { | 430 const PingResult& ping_result) { |
429 DCHECK(alive_); | 431 DCHECK(alive_); |
430 if (ping_result.did_ping) { | 432 if (ping_result.did_ping) { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 if (in_progress_ids_.empty()) { | 498 if (in_progress_ids_.empty()) { |
497 VLOG(1) << "Sending EXTENSION_UPDATING_FINISHED"; | 499 VLOG(1) << "Sending EXTENSION_UPDATING_FINISHED"; |
498 content::NotificationService::current()->Notify( | 500 content::NotificationService::current()->Notify( |
499 chrome::NOTIFICATION_EXTENSION_UPDATING_FINISHED, | 501 chrome::NOTIFICATION_EXTENSION_UPDATING_FINISHED, |
500 content::Source<Profile>(profile_), | 502 content::Source<Profile>(profile_), |
501 content::NotificationService::NoDetails()); | 503 content::NotificationService::NoDetails()); |
502 } | 504 } |
503 } | 505 } |
504 | 506 |
505 } // namespace extensions | 507 } // namespace extensions |
OLD | NEW |