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/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.