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_downloader.h" | 5 #include "chrome/browser/extensions/updater/extension_downloader.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/location.h" | 12 #include "base/location.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
15 #include "base/metrics/sparse_histogram.h" | 15 #include "base/metrics/sparse_histogram.h" |
16 #include "base/profiler/scoped_profile.h" | 16 #include "base/profiler/scoped_profile.h" |
17 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
19 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
20 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
21 #include "base/time/time.h" | 21 #include "base/time/time.h" |
22 #include "base/version.h" | 22 #include "base/version.h" |
23 #include "chrome/browser/chrome_notification_types.h" | |
24 #include "chrome/common/chrome_switches.h" | |
25 #include "chrome/common/chrome_version_info.h" | |
26 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
27 #include "content/public/browser/notification_details.h" | 24 #include "content/public/browser/notification_details.h" |
28 #include "content/public/browser/notification_service.h" | 25 #include "content/public/browser/notification_service.h" |
| 26 #include "extensions/browser/extensions_browser_client.h" |
| 27 #include "extensions/browser/notification_types.h" |
29 #include "extensions/browser/updater/extension_cache.h" | 28 #include "extensions/browser/updater/extension_cache.h" |
30 #include "extensions/browser/updater/request_queue_impl.h" | 29 #include "extensions/browser/updater/request_queue_impl.h" |
31 #include "extensions/browser/updater/safe_manifest_parser.h" | 30 #include "extensions/browser/updater/safe_manifest_parser.h" |
32 #include "extensions/common/extension_urls.h" | 31 #include "extensions/common/extension_urls.h" |
33 #include "extensions/common/manifest_url_handlers.h" | 32 #include "extensions/common/manifest_url_handlers.h" |
34 #include "google_apis/gaia/identity_provider.h" | 33 #include "google_apis/gaia/identity_provider.h" |
35 #include "net/base/backoff_entry.h" | 34 #include "net/base/backoff_entry.h" |
36 #include "net/base/load_flags.h" | 35 #include "net/base/load_flags.h" |
37 #include "net/base/net_errors.h" | 36 #include "net/base/net_errors.h" |
38 #include "net/http/http_request_headers.h" | 37 #include "net/http/http_request_headers.h" |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateCheckOtherUrl", | 424 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateCheckOtherUrl", |
426 url_stats_.other_url_count); | 425 url_stats_.other_url_count); |
427 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateCheckNoUrl", | 426 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateCheckNoUrl", |
428 url_stats_.no_url_count); | 427 url_stats_.no_url_count); |
429 } | 428 } |
430 | 429 |
431 void ExtensionDownloader::StartUpdateCheck( | 430 void ExtensionDownloader::StartUpdateCheck( |
432 scoped_ptr<ManifestFetchData> fetch_data) { | 431 scoped_ptr<ManifestFetchData> fetch_data) { |
433 const std::set<std::string>& id_set(fetch_data->extension_ids()); | 432 const std::set<std::string>& id_set(fetch_data->extension_ids()); |
434 | 433 |
435 if (CommandLine::ForCurrentProcess()->HasSwitch( | 434 if (!ExtensionsBrowserClient::Get()->IsBackgroundUpdateAllowed()) { |
436 switches::kDisableBackgroundNetworking)) { | |
437 NotifyExtensionsDownloadFailed(id_set, | 435 NotifyExtensionsDownloadFailed(id_set, |
438 fetch_data->request_ids(), | 436 fetch_data->request_ids(), |
439 ExtensionDownloaderDelegate::DISABLED); | 437 ExtensionDownloaderDelegate::DISABLED); |
440 return; | |
441 } | 438 } |
442 | 439 |
443 RequestQueue<ManifestFetchData>::iterator i; | 440 RequestQueue<ManifestFetchData>::iterator i; |
444 for (i = manifests_queue_.begin(); i != manifests_queue_.end(); ++i) { | 441 for (i = manifests_queue_.begin(); i != manifests_queue_.end(); ++i) { |
445 if (fetch_data->full_url() == i->full_url()) { | 442 if (fetch_data->full_url() == i->full_url()) { |
446 // This url is already scheduled to be fetched. | 443 // This url is already scheduled to be fetched. |
447 i->Merge(*fetch_data); | 444 i->Merge(*fetch_data); |
448 return; | 445 return; |
449 } | 446 } |
450 } | 447 } |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 NotifyExtensionsDownloadFailed( | 619 NotifyExtensionsDownloadFailed( |
623 not_updated, | 620 not_updated, |
624 fetch_data.request_ids(), | 621 fetch_data.request_ids(), |
625 ExtensionDownloaderDelegate::NO_UPDATE_AVAILABLE); | 622 ExtensionDownloaderDelegate::NO_UPDATE_AVAILABLE); |
626 } | 623 } |
627 | 624 |
628 void ExtensionDownloader::DetermineUpdates( | 625 void ExtensionDownloader::DetermineUpdates( |
629 const ManifestFetchData& fetch_data, | 626 const ManifestFetchData& fetch_data, |
630 const UpdateManifest::Results& possible_updates, | 627 const UpdateManifest::Results& possible_updates, |
631 std::vector<int>* result) { | 628 std::vector<int>* result) { |
632 // This will only be valid if one of possible_updates specifies | |
633 // browser_min_version. | |
634 Version browser_version; | |
635 | |
636 for (size_t i = 0; i < possible_updates.list.size(); i++) { | 629 for (size_t i = 0; i < possible_updates.list.size(); i++) { |
637 const UpdateManifest::Result* update = &possible_updates.list[i]; | 630 const UpdateManifest::Result* update = &possible_updates.list[i]; |
638 const std::string& id = update->extension_id; | 631 const std::string& id = update->extension_id; |
639 | 632 |
640 if (!fetch_data.Includes(id)) { | 633 if (!fetch_data.Includes(id)) { |
641 VLOG(2) << "Ignoring " << id << " from this manifest"; | 634 VLOG(2) << "Ignoring " << id << " from this manifest"; |
642 continue; | 635 continue; |
643 } | 636 } |
644 | 637 |
645 if (VLOG_IS_ON(2)) { | 638 if (VLOG_IS_ON(2)) { |
(...skipping 21 matching lines...) Expand all Loading... |
667 Version existing_version(version); | 660 Version existing_version(version); |
668 Version update_version(update->version); | 661 Version update_version(update->version); |
669 if (!update_version.IsValid() || | 662 if (!update_version.IsValid() || |
670 update_version.CompareTo(existing_version) <= 0) { | 663 update_version.CompareTo(existing_version) <= 0) { |
671 continue; | 664 continue; |
672 } | 665 } |
673 } | 666 } |
674 } | 667 } |
675 | 668 |
676 // If the update specifies a browser minimum version, do we qualify? | 669 // If the update specifies a browser minimum version, do we qualify? |
677 if (update->browser_min_version.length() > 0) { | 670 if (update->browser_min_version.length() > 0 && |
678 // First determine the browser version if we haven't already. | 671 !ExtensionsBrowserClient::Get()->IsMinBrowserVersionSupported( |
679 if (!browser_version.IsValid()) { | 672 update->browser_min_version)) { |
680 chrome::VersionInfo version_info; | 673 // TODO(asargent) - We may want this to show up in the extensions UI |
681 browser_version = Version(version_info.Version()); | 674 // eventually. (http://crbug.com/12547). |
682 } | 675 LOG(WARNING) << "Updated version of extension " << id |
683 Version browser_min_version(update->browser_min_version); | 676 << " available, but requires chrome version " |
684 if (browser_version.IsValid() && browser_min_version.IsValid() && | 677 << update->browser_min_version; |
685 browser_min_version.CompareTo(browser_version) > 0) { | 678 continue; |
686 // TODO(asargent) - We may want this to show up in the extensions UI | |
687 // eventually. (http://crbug.com/12547). | |
688 LOG(WARNING) << "Updated version of extension " << id | |
689 << " available, but requires chrome version " | |
690 << update->browser_min_version; | |
691 continue; | |
692 } | |
693 } | 679 } |
694 VLOG(2) << "will try to update " << id; | 680 VLOG(2) << "will try to update " << id; |
695 result->push_back(i); | 681 result->push_back(i); |
696 } | 682 } |
697 } | 683 } |
698 | 684 |
699 // Begins (or queues up) download of an updated extension. | 685 // Begins (or queues up) download of an updated extension. |
700 void ExtensionDownloader::FetchUpdatedExtension( | 686 void ExtensionDownloader::FetchUpdatedExtension( |
701 scoped_ptr<ExtensionFetch> fetch_data) { | 687 scoped_ptr<ExtensionFetch> fetch_data) { |
702 if (!fetch_data->url.is_valid()) { | 688 if (!fetch_data->url.is_valid()) { |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
961 ping_mode = ManifestFetchData::PING_WITH_METRICS; | 947 ping_mode = ManifestFetchData::PING_WITH_METRICS; |
962 } else { | 948 } else { |
963 ping_mode = ManifestFetchData::PING; | 949 ping_mode = ManifestFetchData::PING; |
964 } | 950 } |
965 } | 951 } |
966 return new ManifestFetchData( | 952 return new ManifestFetchData( |
967 update_url, request_id, brand_code_, manifest_query_params_, ping_mode); | 953 update_url, request_id, brand_code_, manifest_query_params_, ping_mode); |
968 } | 954 } |
969 | 955 |
970 } // namespace extensions | 956 } // namespace extensions |
OLD | NEW |