ExtensionUpdater: Abstract ExtensionDownloader creation
ExtensionUpdater likes to create and destroy ExtensionDownloader
instances as needed. This is fine, but it means duplicating efforts
any time new dependencies need to be injected into ExtensionDownloader,
because then they also need to be injected into ExtensionUpdater.
This CL adds a factory callback to ExtensionUpdater's constructor
so that ExtensionUpdater creators can opaquely inform the instance
about how it should construct new ExtensionDownloaders.
This also reverts the change to ExtensionDownloader's constructor
which took an (optionally NULL) IdentityProvider; this can now
instead be attached to new ExtensionDownloader instances by the
factory responsible for their construction via the
SetWebstoreIdentityProvider method. ExtensionService
provides an example of this.
BUG=398671
Review URL: https://codereview.chromium.org/456063002
Cr-Commit-Position: refs/heads/master@{#288964}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@288964 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/chromeos/extensions/external_cache.cc b/chrome/browser/chromeos/extensions/external_cache.cc
index 22d8806..14ec0a4 100644
--- a/chrome/browser/chromeos/extensions/external_cache.cc
+++ b/chrome/browser/chromeos/extensions/external_cache.cc
@@ -210,7 +210,7 @@
// If request_context_ is missing we can't download anything.
if (!downloader_ && request_context_) {
downloader_.reset(
- new extensions::ExtensionDownloader(this, request_context_, NULL));
+ new extensions::ExtensionDownloader(this, request_context_));
}
cached_extensions_->Clear();
diff --git a/chrome/browser/extensions/extension_service.cc b/chrome/browser/extensions/extension_service.cc
index 68ae582..dee4596 100644
--- a/chrome/browser/extensions/extension_service.cc
+++ b/chrome/browser/extensions/extension_service.cc
@@ -38,6 +38,7 @@
#include "chrome/browser/extensions/shared_module_service.h"
#include "chrome/browser/extensions/unpacked_installer.h"
#include "chrome/browser/extensions/updater/extension_cache.h"
+#include "chrome/browser/extensions/updater/extension_downloader.h"
#include "chrome/browser/extensions/updater/extension_updater.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/profile_identity_provider.h"
@@ -91,6 +92,8 @@
using content::DevToolsAgentHost;
using extensions::CrxInstaller;
using extensions::Extension;
+using extensions::ExtensionDownloader;
+using extensions::ExtensionDownloaderDelegate;
using extensions::ExtensionIdSet;
using extensions::ExtensionInfo;
using extensions::ExtensionRegistry;
@@ -321,7 +324,8 @@
profile,
update_frequency,
extensions::ExtensionCache::GetInstance(),
- CreateWebstoreIdentityProvider(profile_)));
+ base::Bind(&ExtensionService::CreateExtensionDownloader,
+ base::Unretained(this))));
}
component_loader_.reset(
@@ -582,6 +586,20 @@
return true;
}
+scoped_ptr<ExtensionDownloader> ExtensionService::CreateExtensionDownloader(
+ ExtensionDownloaderDelegate* delegate) {
+ scoped_ptr<ExtensionDownloader> downloader;
+#if defined(ENABLE_EXTENSIONS)
+ scoped_ptr<IdentityProvider> identity_provider =
+ CreateWebstoreIdentityProvider(profile_);
+ downloader.reset(new ExtensionDownloader(
+ delegate,
+ profile_->GetRequestContext()));
+ downloader->SetWebstoreIdentityProvider(identity_provider.Pass());
+#endif
+ return downloader.Pass();
+}
+
void ExtensionService::ReloadExtensionImpl(
// "transient" because the process of reloading may cause the reference
// to become invalid. Instead, use |extension_id|, a copy.
diff --git a/chrome/browser/extensions/extension_service.h b/chrome/browser/extensions/extension_service.h
index 6e442930..30e041e 100644
--- a/chrome/browser/extensions/extension_service.h
+++ b/chrome/browser/extensions/extension_service.h
@@ -49,6 +49,8 @@
class ComponentLoader;
class CrxInstaller;
class ExtensionActionStorageManager;
+class ExtensionDownloader;
+class ExtensionDownloaderDelegate;
class ExtensionErrorController;
class ExtensionRegistry;
class ExtensionSystem;
@@ -456,6 +458,10 @@
private:
+ // Creates an ExtensionDownloader for use by the updater.
+ scoped_ptr<extensions::ExtensionDownloader> CreateExtensionDownloader(
+ extensions::ExtensionDownloaderDelegate* delegate);
+
// Reloads the specified extension, sending the onLaunched() event to it if it
// currently has any window showing. |be_noisy| determines whether noisy
// failures are allowed for unpacked extension installs.
diff --git a/chrome/browser/extensions/updater/extension_downloader.cc b/chrome/browser/extensions/updater/extension_downloader.cc
index 47c02bd7..5846380 100644
--- a/chrome/browser/extensions/updater/extension_downloader.cc
+++ b/chrome/browser/extensions/updater/extension_downloader.cc
@@ -176,8 +176,7 @@
ExtensionDownloader::ExtensionDownloader(
ExtensionDownloaderDelegate* delegate,
- net::URLRequestContextGetter* request_context,
- IdentityProvider* webstore_identity_provider)
+ net::URLRequestContextGetter* request_context)
: OAuth2TokenService::Consumer(kTokenServiceConsumerId),
delegate_(delegate),
request_context_(request_context),
@@ -188,8 +187,7 @@
extensions_queue_(&kDefaultBackoffPolicy,
base::Bind(&ExtensionDownloader::CreateExtensionFetcher,
base::Unretained(this))),
- extension_cache_(NULL),
- identity_provider_(webstore_identity_provider) {
+ extension_cache_(NULL) {
DCHECK(delegate_);
DCHECK(request_context_);
}
@@ -279,6 +277,11 @@
StartUpdateCheck(blacklist_fetch.Pass());
}
+void ExtensionDownloader::SetWebstoreIdentityProvider(
+ scoped_ptr<IdentityProvider> identity_provider) {
+ identity_provider_.swap(identity_provider);
+}
+
bool ExtensionDownloader::AddExtensionData(const std::string& id,
const Version& version,
Manifest::Type extension_type,
@@ -746,7 +749,7 @@
// We should try OAuth2, but we have no token cached. This
// ExtensionFetcher will be started once the token fetch is complete,
// in either OnTokenFetchSuccess or OnTokenFetchFailure.
- DCHECK(identity_provider_);
+ DCHECK(identity_provider_.get());
OAuth2TokenService::ScopeSet webstore_scopes;
webstore_scopes.insert(kWebstoreOAuth2Scope);
access_token_request_ =
@@ -871,7 +874,7 @@
// should invalidate the token and try again.
if (response_code == net::HTTP_UNAUTHORIZED &&
fetch->oauth2_attempt_count <= kMaxOAuth2Attempts) {
- DCHECK(identity_provider_ != NULL);
+ DCHECK(identity_provider_.get());
OAuth2TokenService::ScopeSet webstore_scopes;
webstore_scopes.insert(kWebstoreOAuth2Scope);
identity_provider_->GetTokenService()->InvalidateToken(
diff --git a/chrome/browser/extensions/updater/extension_downloader.h b/chrome/browser/extensions/updater/extension_downloader.h
index d8704ffc..a040986 100644
--- a/chrome/browser/extensions/updater/extension_downloader.h
+++ b/chrome/browser/extensions/updater/extension_downloader.h
@@ -47,7 +47,6 @@
class ExtensionCache;
class ExtensionUpdaterTest;
-class WebstoreOAuth2TokenProvider;
// A class that checks for updates of a given list of extensions, and downloads
// the crx file when updates are found. It uses a |ExtensionDownloaderDelegate|
@@ -57,13 +56,16 @@
: public net::URLFetcherDelegate,
public OAuth2TokenService::Consumer {
public:
+ // A closure which constructs a new ExtensionDownloader to be owned by the
+ // caller.
+ typedef base::Callback<
+ scoped_ptr<ExtensionDownloader>(ExtensionDownloaderDelegate* delegate)>
+ Factory;
+
// |delegate| is stored as a raw pointer and must outlive the
- // ExtensionDownloader. |webstore_identity_provider| may be NULL if this
- // ExtensionDownloader does not need OAuth2 support; if not NULL, the
- // given IdentityProvider must outlive this ExtensionDownloader.
+ // ExtensionDownloader.
ExtensionDownloader(ExtensionDownloaderDelegate* delegate,
- net::URLRequestContextGetter* request_context,
- IdentityProvider* webstore_identity_provider);
+ net::URLRequestContextGetter* request_context);
virtual ~ExtensionDownloader();
// Adds |extension| to the list of extensions to check for updates.
@@ -93,6 +95,11 @@
const ManifestFetchData::PingData& ping_data,
int request_id);
+ // Sets an IdentityProvider to be used for OAuth2 authentication on protected
+ // Webstore downloads.
+ void SetWebstoreIdentityProvider(
+ scoped_ptr<IdentityProvider> identity_provider);
+
// These are needed for unit testing, to help identify the correct mock
// URLFetcher objects.
static const int kManifestFetcherId = 1;
@@ -275,7 +282,7 @@
// An IdentityProvider which may be used for authentication on protected
// download requests. May be NULL.
- IdentityProvider* identity_provider_;
+ scoped_ptr<IdentityProvider> identity_provider_;
// A Webstore download-scoped access token for the |identity_provider_|'s
// active account, if any.
diff --git a/chrome/browser/extensions/updater/extension_updater.cc b/chrome/browser/extensions/updater/extension_updater.cc
index e4843d1..1c64bc9 100644
--- a/chrome/browser/extensions/updater/extension_updater.cc
+++ b/chrome/browser/extensions/updater/extension_updater.cc
@@ -20,7 +20,6 @@
#include "chrome/browser/extensions/crx_installer.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/pending_extension_manager.h"
-#include "chrome/browser/extensions/updater/extension_downloader.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/pref_names.h"
#include "content/public/browser/browser_thread.h"
@@ -136,10 +135,11 @@
Profile* profile,
int frequency_seconds,
ExtensionCache* cache,
- scoped_ptr<IdentityProvider> webstore_identity_provider)
+ const ExtensionDownloader::Factory& downloader_factory)
: alive_(false),
weak_ptr_factory_(this),
service_(service),
+ downloader_factory_(downloader_factory),
frequency_seconds_(frequency_seconds),
will_check_soon_(false),
extension_prefs_(extension_prefs),
@@ -148,8 +148,7 @@
next_request_id_(0),
extension_registry_observer_(this),
crx_install_is_running_(false),
- extension_cache_(cache),
- webstore_identity_provider_(webstore_identity_provider.release()) {
+ extension_cache_(cache) {
DCHECK_GE(frequency_seconds_, 5);
DCHECK_LE(frequency_seconds_, kMaxUpdateFrequencySeconds);
#if defined(NDEBUG)
@@ -165,6 +164,12 @@
Stop();
}
+void ExtensionUpdater::EnsureDownloaderCreated() {
+ if (!downloader_.get()) {
+ downloader_ = downloader_factory_.Run(this);
+ }
+}
+
// The overall goal here is to balance keeping clients up to date while
// avoiding a thundering herd against update servers.
TimeDelta ExtensionUpdater::DetermineFirstCheckDelay() {
@@ -342,12 +347,7 @@
request.callback = params.callback;
request.install_immediately = params.install_immediately;
- if (!downloader_.get()) {
- downloader_.reset(
- new ExtensionDownloader(this,
- profile_->GetRequestContext(),
- webstore_identity_provider_.get()));
- }
+ EnsureDownloaderCreated();
// Add fetch records for extensions that should be fetched by an update URL.
// These extensions are not yet installed. They come from group policy
diff --git a/chrome/browser/extensions/updater/extension_updater.h b/chrome/browser/extensions/updater/extension_updater.h
index 4f887b9..29faf71 100644
--- a/chrome/browser/extensions/updater/extension_updater.h
+++ b/chrome/browser/extensions/updater/extension_updater.h
@@ -20,12 +20,12 @@
#include "base/scoped_observer.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
+#include "chrome/browser/extensions/updater/extension_downloader.h"
#include "chrome/browser/extensions/updater/extension_downloader_delegate.h"
#include "chrome/browser/extensions/updater/manifest_fetch_data.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "extensions/browser/extension_registry_observer.h"
-#include "google_apis/gaia/identity_provider.h"
#include "url/gurl.h"
class ExtensionServiceInterface;
@@ -39,7 +39,6 @@
namespace extensions {
class ExtensionCache;
-class ExtensionDownloader;
class ExtensionPrefs;
class ExtensionRegistry;
class ExtensionSet;
@@ -51,7 +50,8 @@
// extension_prefs,
// pref_service,
// profile,
-// update_frequency_secs);
+// update_frequency_secs,
+// downloader_factory);
// updater->Start();
// ....
// updater->Stop();
@@ -89,7 +89,7 @@
Profile* profile,
int frequency_seconds,
ExtensionCache* cache,
- scoped_ptr<IdentityProvider> identity_provider);
+ const ExtensionDownloader::Factory& downloader_factory);
virtual ~ExtensionUpdater();
@@ -157,6 +157,10 @@
struct ThrottleInfo;
+ // Ensure that we have a valid ExtensionDownloader instance referenced by
+ // |downloader|.
+ void EnsureDownloaderCreated();
+
// Computes when to schedule the first update check.
base::TimeDelta DetermineFirstCheckDelay();
@@ -240,6 +244,10 @@
// Pointer back to the service that owns this ExtensionUpdater.
ExtensionServiceInterface* service_;
+ // A closure passed into the ExtensionUpdater to teach it how to construct
+ // new ExtensionDownloader instances.
+ const ExtensionDownloader::Factory downloader_factory_;
+
// Fetches the crx files for the extensions that have an available update.
scoped_ptr<ExtensionDownloader> downloader_;
@@ -272,9 +280,6 @@
ExtensionCache* extension_cache_;
- // Provided to the ExtensionDownloader to enable OAuth2 support.
- scoped_ptr<IdentityProvider> webstore_identity_provider_;
-
// Keeps track of when an extension tried to update itself, so we can throttle
// checks to prevent too many requests from being made.
std::map<std::string, ThrottleInfo> throttle_info_;
diff --git a/chrome/browser/extensions/updater/extension_updater_unittest.cc b/chrome/browser/extensions/updater/extension_updater_unittest.cc
index ad8ef32a..874dca1 100644
--- a/chrome/browser/extensions/updater/extension_updater_unittest.cc
+++ b/chrome/browser/extensions/updater/extension_updater_unittest.cc
@@ -127,6 +127,10 @@
int kExpectedLoadFlagsForDownloadWithCookies = net::LOAD_DISABLE_CACHE;
+// Fake authentication constants
+const char kFakeAccountId[] = "[email protected]";
+const char kFakeOAuth2Token[] = "ce n'est pas un jeton";
+
const ManifestFetchData::PingData kNeverPingedData(
ManifestFetchData::kNeverPinged, ManifestFetchData::kNeverPinged, true);
@@ -280,7 +284,10 @@
class MockService : public TestExtensionService {
public:
explicit MockService(TestExtensionPrefs* prefs)
- : prefs_(prefs), pending_extension_manager_(&profile_) {}
+ : prefs_(prefs),
+ pending_extension_manager_(&profile_),
+ downloader_delegate_override_(NULL) {
+ }
virtual ~MockService() {}
@@ -300,6 +307,10 @@
PrefService* pref_service() { return prefs_->pref_service(); }
+ FakeOAuth2TokenService* fake_token_service() {
+ return fake_token_service_.get();
+ }
+
// Creates test extensions and inserts them into list. The name and
// version are all based on their index. If |update_url| is non-null, it
// will be used as the update_url for each extension.
@@ -323,12 +334,54 @@
}
}
+ ExtensionDownloader::Factory GetDownloaderFactory() {
+ return base::Bind(&MockService::CreateExtensionDownloader,
+ base::Unretained(this));
+ }
+
+ ExtensionDownloader::Factory GetAuthenticatedDownloaderFactory() {
+ return base::Bind(&MockService::CreateExtensionDownloaderWithIdentity,
+ base::Unretained(this));
+ }
+
+ void OverrideDownloaderDelegate(ExtensionDownloaderDelegate* delegate) {
+ downloader_delegate_override_ = delegate;
+ }
+
protected:
TestExtensionPrefs* const prefs_;
TestingProfile profile_;
PendingExtensionManager pending_extension_manager_;
private:
+ scoped_ptr<ExtensionDownloader> CreateExtensionDownloader(
+ ExtensionDownloaderDelegate* delegate) {
+ return make_scoped_ptr(new ExtensionDownloader(
+ downloader_delegate_override_ ? downloader_delegate_override_
+ : delegate,
+ request_context()));
+ }
+
+ scoped_ptr<ExtensionDownloader> CreateExtensionDownloaderWithIdentity(
+ ExtensionDownloaderDelegate* delegate) {
+ scoped_ptr<FakeIdentityProvider> fake_identity_provider;
+ fake_token_service_.reset(new FakeOAuth2TokenService());
+ fake_identity_provider.reset(new FakeIdentityProvider(
+ fake_token_service_.get()));
+ fake_identity_provider->LogIn(kFakeAccountId);
+ fake_token_service_->AddAccount(kFakeAccountId);
+
+ scoped_ptr<ExtensionDownloader> downloader(
+ CreateExtensionDownloader(delegate));
+ downloader->SetWebstoreIdentityProvider(
+ fake_identity_provider.PassAs<IdentityProvider>());
+ return downloader.Pass();
+ }
+
+ scoped_ptr<FakeOAuth2TokenService> fake_token_service_;
+
+ ExtensionDownloaderDelegate* downloader_delegate_override_;
+
DISALLOW_COPY_AND_ASSIGN(MockService);
};
@@ -377,7 +430,9 @@
class ServiceForManifestTests : public MockService {
public:
explicit ServiceForManifestTests(TestExtensionPrefs* prefs)
- : MockService(prefs), registry_(ExtensionRegistry::Get(profile())) {}
+ : MockService(prefs),
+ registry_(ExtensionRegistry::Get(profile())) {
+ }
virtual ~ServiceForManifestTests() {}
@@ -571,12 +626,6 @@
results->list.push_back(result);
}
- void ResetDownloader(ExtensionUpdater* updater,
- ExtensionDownloader* downloader) {
- EXPECT_FALSE(updater->downloader_.get());
- updater->downloader_.reset(downloader);
- }
-
void StartUpdateCheck(ExtensionDownloader* downloader,
ManifestFetchData* fetch_data) {
downloader->StartUpdateCheck(scoped_ptr<ManifestFetchData>(fetch_data));
@@ -612,7 +661,7 @@
service.profile(),
60 * 60 * 24,
NULL,
- make_scoped_ptr<IdentityProvider>(NULL));
+ service.GetDownloaderFactory());
updater.Start();
// Tell the update that it's time to do update checks.
@@ -699,7 +748,7 @@
MockService service(prefs_.get());
MockExtensionDownloaderDelegate delegate;
- ExtensionDownloader downloader(&delegate, service.request_context(), NULL);
+ ExtensionDownloader downloader(&delegate, service.request_context());
ExtensionList extensions;
std::string url(gallery_url);
@@ -741,8 +790,7 @@
void TestDetermineUpdates() {
TestingProfile profile;
MockExtensionDownloaderDelegate delegate;
- ExtensionDownloader downloader(
- &delegate, profile.GetRequestContext(), NULL);
+ ExtensionDownloader downloader(&delegate, profile.GetRequestContext());
// Check passing an empty list of parse results to DetermineUpdates
ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0);
@@ -785,8 +833,7 @@
TestingProfile profile;
MockExtensionDownloaderDelegate delegate;
- ExtensionDownloader downloader(
- &delegate, profile.GetRequestContext(), NULL);
+ ExtensionDownloader downloader(&delegate, profile.GetRequestContext());
ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0);
UpdateManifest::Results updates;
@@ -825,7 +872,7 @@
net::TestURLFetcher* fetcher = NULL;
MockService service(prefs_.get());
MockExtensionDownloaderDelegate delegate;
- ExtensionDownloader downloader(&delegate, service.request_context(), NULL);
+ ExtensionDownloader downloader(&delegate, service.request_context());
downloader.manifests_queue_.set_backoff_policy(&kNoBackoffPolicy);
GURL kUpdateUrl("http://localhost/manifest1");
@@ -965,7 +1012,7 @@
NotificationsObserver observer;
MockService service(prefs_.get());
MockExtensionDownloaderDelegate delegate;
- ExtensionDownloader downloader(&delegate, service.request_context(), NULL);
+ ExtensionDownloader downloader(&delegate, service.request_context());
downloader.manifests_queue_.set_backoff_policy(&kNoBackoffPolicy);
GURL kUpdateUrl("http://localhost/manifest1");
@@ -1044,13 +1091,12 @@
service->profile(),
kUpdateFrequencySecs,
NULL,
- make_scoped_ptr<IdentityProvider>(NULL));
- updater.Start();
+ service->GetDownloaderFactory());
MockExtensionDownloaderDelegate delegate;
delegate.DelegateTo(&updater);
- ResetDownloader(
- &updater,
- new ExtensionDownloader(&delegate, service->request_context(), NULL));
+ service->OverrideDownloaderDelegate(&delegate);
+ updater.Start();
+ updater.EnsureDownloaderCreated();
updater.downloader_->extensions_queue_.set_backoff_policy(
&kNoBackoffPolicy);
@@ -1146,44 +1192,30 @@
bool succeed_with_oauth2,
int valid_authuser,
int max_authuser) {
- const char kFakeAccountId[] = "[email protected]";
- const char kFakeOAuth2Token[] = "ce n'est pas un jeton";
-
net::TestURLFetcherFactory factory;
net::TestURLFetcher* fetcher = NULL;
scoped_ptr<ServiceForDownloadTests> service(
new ServiceForDownloadTests(prefs_.get()));
- ExtensionUpdater updater(service.get(),
- service->extension_prefs(),
- service->pref_service(),
- service->profile(),
- kUpdateFrequencySecs,
- NULL,
- make_scoped_ptr<IdentityProvider>(NULL));
+ const ExtensionDownloader::Factory& downloader_factory =
+ enable_oauth2 ? service->GetAuthenticatedDownloaderFactory()
+ : service->GetDownloaderFactory();
+ ExtensionUpdater updater(
+ service.get(),
+ service->extension_prefs(),
+ service->pref_service(),
+ service->profile(),
+ kUpdateFrequencySecs,
+ NULL,
+ downloader_factory);
updater.Start();
-
- scoped_ptr<FakeOAuth2TokenService> fake_token_service;
- scoped_ptr<FakeIdentityProvider> fake_identity_provider;
- if (enable_oauth2) {
- fake_token_service.reset(new FakeOAuth2TokenService());
- fake_identity_provider.reset(new FakeIdentityProvider(
- fake_token_service.get()));
- fake_identity_provider->LogIn(kFakeAccountId);
- fake_token_service->AddAccount(kFakeAccountId);
- }
-
- ResetDownloader(
- &updater,
- new ExtensionDownloader(&updater,
- service->request_context(),
- fake_identity_provider.get()));
+ updater.EnsureDownloaderCreated();
updater.downloader_->extensions_queue_.set_backoff_policy(
&kNoBackoffPolicy);
GURL test_url(base::StringPrintf("%s/extension.crx", url_prefix.c_str()));
std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
std::string hash;
- Version version("0.0.1");
+ Version version("0.0.1");
std::set<int> requests;
requests.insert(0);
scoped_ptr<ExtensionDownloader::ExtensionFetch> fetch(
@@ -1200,8 +1232,9 @@
fetcher->set_status(net::URLRequestStatus());
fetcher->set_response_code(403);
fetcher->delegate()->OnURLFetchComplete(fetcher);
- if (fake_token_service) {
- fake_token_service->IssueAllTokensForAccount(
+
+ if (service->fake_token_service()) {
+ service->fake_token_service()->IssueAllTokensForAccount(
kFakeAccountId, kFakeOAuth2Token, base::Time::Now());
}
RunUntilIdle();
@@ -1353,11 +1386,9 @@
service.profile(),
kUpdateFrequencySecs,
NULL,
- make_scoped_ptr<IdentityProvider>(NULL));
+ service.GetDownloaderFactory());
updater.Start();
- ResetDownloader(
- &updater,
- new ExtensionDownloader(&updater, service.request_context(), NULL));
+ updater.EnsureDownloaderCreated();
updater.downloader_->extensions_queue_.set_backoff_policy(
&kNoBackoffPolicy);
@@ -1568,7 +1599,7 @@
service.profile(),
kUpdateFrequencySecs,
NULL,
- make_scoped_ptr<IdentityProvider>(NULL));
+ service.GetDownloaderFactory());
ExtensionUpdater::CheckParams params;
updater.Start();
updater.CheckNow(params);
@@ -1665,11 +1696,9 @@
service.profile(),
kUpdateFrequencySecs,
NULL,
- make_scoped_ptr<IdentityProvider>(NULL));
+ service.GetDownloaderFactory());
updater.Start();
- ResetDownloader(
- &updater,
- new ExtensionDownloader(&updater, service.request_context(), NULL));
+ updater.EnsureDownloaderCreated();
ManifestFetchData fetch_data(update_url, 0);
const Extension* extension = tmp[0].get();
@@ -1853,13 +1882,9 @@
service.profile(),
kUpdateFrequencySecs,
NULL,
- make_scoped_ptr<IdentityProvider>(NULL));
+ service.GetDownloaderFactory());
MockExtensionDownloaderDelegate delegate;
- // Set the downloader directly, so that all its events end up in the mock
- // |delegate|.
- ExtensionDownloader* downloader =
- new ExtensionDownloader(&delegate, service.request_context(), NULL);
- ResetDownloader(&updater, downloader);
+ service.OverrideDownloaderDelegate(&delegate);
// Non-internal non-external extensions should be rejected.
ExtensionList extensions;
@@ -1871,7 +1896,8 @@
// These expectations fail if the delegate's methods are invoked for the
// first extension, which has a non-matching id.
- EXPECT_CALL(delegate, GetUpdateUrlData(updateable_id)).WillOnce(Return(""));
+ EXPECT_CALL(delegate,
+ GetUpdateUrlData(updateable_id)).WillOnce(Return(""));
EXPECT_CALL(delegate, GetPingDataForExtension(updateable_id, _));
service.set_extensions(extensions, ExtensionList());
@@ -1889,13 +1915,9 @@
service.profile(),
kUpdateFrequencySecs,
NULL,
- make_scoped_ptr<IdentityProvider>(NULL));
+ service.GetDownloaderFactory());
MockExtensionDownloaderDelegate delegate;
- // Set the downloader directly, so that all its events end up in the mock
- // |delegate|.
- ExtensionDownloader* downloader =
- new ExtensionDownloader(&delegate, service.request_context(), NULL);
- ResetDownloader(&updater, downloader);
+ service.OverrideDownloaderDelegate(&delegate);
// Non-internal non-external extensions should be rejected.
ExtensionList enabled_extensions;
@@ -1912,7 +1934,8 @@
// We expect that both enabled and disabled extensions are auto-updated.
EXPECT_CALL(delegate, GetUpdateUrlData(enabled_id)).WillOnce(Return(""));
EXPECT_CALL(delegate, GetPingDataForExtension(enabled_id, _));
- EXPECT_CALL(delegate, GetUpdateUrlData(disabled_id)).WillOnce(Return(""));
+ EXPECT_CALL(delegate,
+ GetUpdateUrlData(disabled_id)).WillOnce(Return(""));
EXPECT_CALL(delegate, GetPingDataForExtension(disabled_id, _));
service.set_extensions(enabled_extensions, disabled_extensions);
@@ -1926,7 +1949,7 @@
MockService service(prefs_.get());
MockExtensionDownloaderDelegate delegate;
scoped_ptr<ExtensionDownloader> downloader(
- new ExtensionDownloader(&delegate, service.request_context(), NULL));
+ new ExtensionDownloader(&delegate, service.request_context()));
EXPECT_EQ(0u, ManifestFetchersCount(downloader.get()));
// First, verify that adding valid extensions does invoke the callbacks on
@@ -1957,7 +1980,7 @@
// Reset the ExtensionDownloader so that it drops the current fetcher.
downloader.reset(
- new ExtensionDownloader(&delegate, service.request_context(), NULL));
+ new ExtensionDownloader(&delegate, service.request_context()));
EXPECT_EQ(0u, ManifestFetchersCount(downloader.get()));
// Extensions with empty update URLs should have a default one
@@ -1978,7 +2001,7 @@
net::TestURLFetcherFactory factory;
MockService service(prefs_.get());
MockExtensionDownloaderDelegate delegate;
- ExtensionDownloader downloader(&delegate, service.request_context(), NULL);
+ ExtensionDownloader downloader(&delegate, service.request_context());
StartUpdateCheck(&downloader, new ManifestFetchData(GURL(), 0));
// This should delete the newly-created ManifestFetchData.
@@ -1998,7 +2021,7 @@
service.profile(),
kUpdateFrequencySecs,
NULL,
- make_scoped_ptr<IdentityProvider>(NULL));
+ service.GetDownloaderFactory());
EXPECT_FALSE(updater.WillCheckSoon());
updater.Start();
EXPECT_FALSE(updater.WillCheckSoon());