#include "chrome/browser/extensions/updater/extension_downloader_delegate.h"
#include "chrome/browser/extensions/updater/manifest_fetch_data.h"
#include "chrome/browser/extensions/updater/request_queue.h"
-#include "chrome/common/extensions/update_manifest.h"
#include "extensions/common/extension.h"
+#include "extensions/common/update_manifest.h"
+#include "google_apis/gaia/oauth2_token_service.h"
#include "net/url_request/url_fetcher_delegate.h"
#include "url/gurl.h"
+class IdentityProvider;
+
namespace net {
class URLFetcher;
class URLRequestContextGetter;
// the crx file when updates are found. It uses a |ExtensionDownloaderDelegate|
// that takes ownership of the downloaded crx files, and handles events during
// the update check.
-class ExtensionDownloader : public net::URLFetcherDelegate {
+class ExtensionDownloader
+ : 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.
ExtensionDownloader(ExtensionDownloaderDelegate* delegate,
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;
std::string version;
std::set<int> request_ids;
- // Indicates whether or not the fetch is known to require credentials.
- bool is_protected;
+ enum CredentialsMode {
+ CREDENTIALS_NONE = 0,
+ CREDENTIALS_OAUTH2_TOKEN,
+ CREDENTIALS_COOKIES,
+ };
+
+ // Indicates the type of credentials to include with this fetch.
+ CredentialsMode credentials;
+
+ // Counts the number of times OAuth2 authentication has been attempted for
+ // this fetch.
+ int oauth2_attempt_count;
};
// Helper for AddExtension() and AddPendingExtension().
const base::FilePath& crx_path,
bool file_ownership_passed);
+ // Potentially updates an ExtensionFetch's authentication state and returns
+ // |true| if the fetch should be retried. Returns |false| if the failure was
+ // not related to authentication, leaving the ExtensionFetch data unmodified.
+ bool IterateFetchCredentialsAfterFailure(ExtensionFetch* fetch,
+ const net::URLRequestStatus& status,
+ int response_code);
+
+ // OAuth2TokenService::Consumer implementation.
+ virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
+ const std::string& access_token,
+ const base::Time& expiration_time) OVERRIDE;
+ virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request,
+ const GoogleServiceAuthError& error) OVERRIDE;
+
// The delegate that receives the crx files downloaded by the
// ExtensionDownloader, and that fills in optional ping and update url data.
ExtensionDownloaderDelegate* delegate_;
// Cache for .crx files.
ExtensionCache* extension_cache_;
+ // An IdentityProvider which may be used for authentication on protected
+ // download requests. May be NULL.
+ scoped_ptr<IdentityProvider> identity_provider_;
+
+ // A Webstore download-scoped access token for the |identity_provider_|'s
+ // active account, if any.
+ std::string access_token_;
+
+ // A pending token fetch request.
+ scoped_ptr<OAuth2TokenService::Request> access_token_request_;
+
DISALLOW_COPY_AND_ASSIGN(ExtensionDownloader);
};