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 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
13 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.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/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
17 #include "base/strings/string_split.h" | 17 #include "base/strings/string_split.h" |
18 #include "chrome/browser/chrome_notification_types.h" | 18 #include "chrome/browser/chrome_notification_types.h" |
19 #include "chrome/browser/extensions/api/module/module.h" | 19 #include "chrome/browser/extensions/api/module/module.h" |
20 #include "chrome/browser/extensions/crx_installer.h" | 20 #include "chrome/browser/extensions/crx_installer.h" |
21 #include "chrome/browser/extensions/extension_service.h" | 21 #include "chrome/browser/extensions/extension_service.h" |
22 #include "chrome/browser/extensions/pending_extension_manager.h" | 22 #include "chrome/browser/extensions/pending_extension_manager.h" |
23 #include "chrome/browser/extensions/updater/extension_downloader.h" | |
24 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
25 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
26 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
27 #include "content/public/browser/notification_details.h" | 26 #include "content/public/browser/notification_details.h" |
28 #include "content/public/browser/notification_service.h" | 27 #include "content/public/browser/notification_service.h" |
29 #include "content/public/browser/notification_source.h" | 28 #include "content/public/browser/notification_source.h" |
30 #include "crypto/sha2.h" | 29 #include "crypto/sha2.h" |
31 #include "extensions/browser/extension_prefs.h" | 30 #include "extensions/browser/extension_prefs.h" |
32 #include "extensions/browser/extension_registry.h" | 31 #include "extensions/browser/extension_registry.h" |
33 #include "extensions/browser/pref_names.h" | 32 #include "extensions/browser/pref_names.h" |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 Time check_start; | 128 Time check_start; |
130 }; | 129 }; |
131 | 130 |
132 ExtensionUpdater::ExtensionUpdater( | 131 ExtensionUpdater::ExtensionUpdater( |
133 ExtensionServiceInterface* service, | 132 ExtensionServiceInterface* service, |
134 ExtensionPrefs* extension_prefs, | 133 ExtensionPrefs* extension_prefs, |
135 PrefService* prefs, | 134 PrefService* prefs, |
136 Profile* profile, | 135 Profile* profile, |
137 int frequency_seconds, | 136 int frequency_seconds, |
138 ExtensionCache* cache, | 137 ExtensionCache* cache, |
139 scoped_ptr<IdentityProvider> webstore_identity_provider) | 138 const ExtensionDownloader::Factory& downloader_factory) |
140 : alive_(false), | 139 : alive_(false), |
141 weak_ptr_factory_(this), | 140 weak_ptr_factory_(this), |
142 service_(service), | 141 service_(service), |
| 142 downloader_factory_(downloader_factory), |
143 frequency_seconds_(frequency_seconds), | 143 frequency_seconds_(frequency_seconds), |
144 will_check_soon_(false), | 144 will_check_soon_(false), |
145 extension_prefs_(extension_prefs), | 145 extension_prefs_(extension_prefs), |
146 prefs_(prefs), | 146 prefs_(prefs), |
147 profile_(profile), | 147 profile_(profile), |
148 next_request_id_(0), | 148 next_request_id_(0), |
149 extension_registry_observer_(this), | 149 extension_registry_observer_(this), |
150 crx_install_is_running_(false), | 150 crx_install_is_running_(false), |
151 extension_cache_(cache), | 151 extension_cache_(cache) { |
152 webstore_identity_provider_(webstore_identity_provider.release()) { | |
153 DCHECK_GE(frequency_seconds_, 5); | 152 DCHECK_GE(frequency_seconds_, 5); |
154 DCHECK_LE(frequency_seconds_, kMaxUpdateFrequencySeconds); | 153 DCHECK_LE(frequency_seconds_, kMaxUpdateFrequencySeconds); |
155 #if defined(NDEBUG) | 154 #if defined(NDEBUG) |
156 // In Release mode we enforce that update checks don't happen too often. | 155 // In Release mode we enforce that update checks don't happen too often. |
157 frequency_seconds_ = std::max(frequency_seconds_, kMinUpdateFrequencySeconds); | 156 frequency_seconds_ = std::max(frequency_seconds_, kMinUpdateFrequencySeconds); |
158 #endif | 157 #endif |
159 frequency_seconds_ = std::min(frequency_seconds_, kMaxUpdateFrequencySeconds); | 158 frequency_seconds_ = std::min(frequency_seconds_, kMaxUpdateFrequencySeconds); |
160 | 159 |
161 extension_registry_observer_.Add(ExtensionRegistry::Get(profile)); | 160 extension_registry_observer_.Add(ExtensionRegistry::Get(profile)); |
162 } | 161 } |
163 | 162 |
164 ExtensionUpdater::~ExtensionUpdater() { | 163 ExtensionUpdater::~ExtensionUpdater() { |
165 Stop(); | 164 Stop(); |
166 } | 165 } |
167 | 166 |
| 167 void ExtensionUpdater::EnsureDownloaderCreated() { |
| 168 if (!downloader_.get()) { |
| 169 downloader_ = downloader_factory_.Run(this); |
| 170 } |
| 171 } |
| 172 |
168 // The overall goal here is to balance keeping clients up to date while | 173 // The overall goal here is to balance keeping clients up to date while |
169 // avoiding a thundering herd against update servers. | 174 // avoiding a thundering herd against update servers. |
170 TimeDelta ExtensionUpdater::DetermineFirstCheckDelay() { | 175 TimeDelta ExtensionUpdater::DetermineFirstCheckDelay() { |
171 DCHECK(alive_); | 176 DCHECK(alive_); |
172 // If someone's testing with a quick frequency, just allow it. | 177 // If someone's testing with a quick frequency, just allow it. |
173 if (frequency_seconds_ < kStartupWaitSeconds) | 178 if (frequency_seconds_ < kStartupWaitSeconds) |
174 return TimeDelta::FromSeconds(frequency_seconds_); | 179 return TimeDelta::FromSeconds(frequency_seconds_); |
175 | 180 |
176 // If we've never scheduled a check before, start at frequency_seconds_. | 181 // If we've never scheduled a check before, start at frequency_seconds_. |
177 if (!prefs_->HasPrefPath(pref_names::kNextUpdateCheck)) | 182 if (!prefs_->HasPrefPath(pref_names::kNextUpdateCheck)) |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 VLOG(2) << "Starting update check " << request_id; | 340 VLOG(2) << "Starting update check " << request_id; |
336 if (params.ids.empty()) | 341 if (params.ids.empty()) |
337 NotifyStarted(); | 342 NotifyStarted(); |
338 | 343 |
339 DCHECK(alive_); | 344 DCHECK(alive_); |
340 | 345 |
341 InProgressCheck& request = requests_in_progress_[request_id]; | 346 InProgressCheck& request = requests_in_progress_[request_id]; |
342 request.callback = params.callback; | 347 request.callback = params.callback; |
343 request.install_immediately = params.install_immediately; | 348 request.install_immediately = params.install_immediately; |
344 | 349 |
345 if (!downloader_.get()) { | 350 EnsureDownloaderCreated(); |
346 downloader_.reset( | |
347 new ExtensionDownloader(this, | |
348 profile_->GetRequestContext(), | |
349 webstore_identity_provider_.get())); | |
350 } | |
351 | 351 |
352 // Add fetch records for extensions that should be fetched by an update URL. | 352 // Add fetch records for extensions that should be fetched by an update URL. |
353 // These extensions are not yet installed. They come from group policy | 353 // These extensions are not yet installed. They come from group policy |
354 // and external install sources. | 354 // and external install sources. |
355 const PendingExtensionManager* pending_extension_manager = | 355 const PendingExtensionManager* pending_extension_manager = |
356 service_->pending_extension_manager(); | 356 service_->pending_extension_manager(); |
357 | 357 |
358 std::list<std::string> pending_ids; | 358 std::list<std::string> pending_ids; |
359 | 359 |
360 if (params.ids.empty()) { | 360 if (params.ids.empty()) { |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 const InProgressCheck& request = requests_in_progress_[request_id]; | 642 const InProgressCheck& request = requests_in_progress_[request_id]; |
643 if (request.in_progress_ids_.empty()) { | 643 if (request.in_progress_ids_.empty()) { |
644 VLOG(2) << "Finished update check " << request_id; | 644 VLOG(2) << "Finished update check " << request_id; |
645 if (!request.callback.is_null()) | 645 if (!request.callback.is_null()) |
646 request.callback.Run(); | 646 request.callback.Run(); |
647 requests_in_progress_.erase(request_id); | 647 requests_in_progress_.erase(request_id); |
648 } | 648 } |
649 } | 649 } |
650 | 650 |
651 } // namespace extensions | 651 } // namespace extensions |
OLD | NEW |