Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(250)

Side by Side Diff: chrome/browser/extensions/updater/extension_downloader.cc

Issue 456063002: ExtensionUpdater: Abstract ExtensionDownloader creation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments and some cleanup Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 version(version), 169 version(version),
170 request_ids(request_ids), 170 request_ids(request_ids),
171 credentials(CREDENTIALS_NONE), 171 credentials(CREDENTIALS_NONE),
172 oauth2_attempt_count(0) { 172 oauth2_attempt_count(0) {
173 } 173 }
174 174
175 ExtensionDownloader::ExtensionFetch::~ExtensionFetch() {} 175 ExtensionDownloader::ExtensionFetch::~ExtensionFetch() {}
176 176
177 ExtensionDownloader::ExtensionDownloader( 177 ExtensionDownloader::ExtensionDownloader(
178 ExtensionDownloaderDelegate* delegate, 178 ExtensionDownloaderDelegate* delegate,
179 net::URLRequestContextGetter* request_context, 179 net::URLRequestContextGetter* request_context)
180 IdentityProvider* webstore_identity_provider)
181 : OAuth2TokenService::Consumer(kTokenServiceConsumerId), 180 : OAuth2TokenService::Consumer(kTokenServiceConsumerId),
182 delegate_(delegate), 181 delegate_(delegate),
183 request_context_(request_context), 182 request_context_(request_context),
184 weak_ptr_factory_(this), 183 weak_ptr_factory_(this),
185 manifests_queue_(&kDefaultBackoffPolicy, 184 manifests_queue_(&kDefaultBackoffPolicy,
186 base::Bind(&ExtensionDownloader::CreateManifestFetcher, 185 base::Bind(&ExtensionDownloader::CreateManifestFetcher,
187 base::Unretained(this))), 186 base::Unretained(this))),
188 extensions_queue_(&kDefaultBackoffPolicy, 187 extensions_queue_(&kDefaultBackoffPolicy,
189 base::Bind(&ExtensionDownloader::CreateExtensionFetcher, 188 base::Bind(&ExtensionDownloader::CreateExtensionFetcher,
190 base::Unretained(this))), 189 base::Unretained(this))),
191 extension_cache_(NULL), 190 extension_cache_(NULL) {
192 identity_provider_(webstore_identity_provider) {
193 DCHECK(delegate_); 191 DCHECK(delegate_);
194 DCHECK(request_context_); 192 DCHECK(request_context_);
195 } 193 }
196 194
197 ExtensionDownloader::~ExtensionDownloader() {} 195 ExtensionDownloader::~ExtensionDownloader() {}
198 196
199 bool ExtensionDownloader::AddExtension(const Extension& extension, 197 bool ExtensionDownloader::AddExtension(const Extension& extension,
200 int request_id) { 198 int request_id) {
201 // Skip extensions with empty update URLs converted from user 199 // Skip extensions with empty update URLs converted from user
202 // scripts. 200 // scripts.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 request_id)); 270 request_id));
273 DCHECK(blacklist_fetch->base_url().SchemeIsSecure()); 271 DCHECK(blacklist_fetch->base_url().SchemeIsSecure());
274 blacklist_fetch->AddExtension(kBlacklistAppID, 272 blacklist_fetch->AddExtension(kBlacklistAppID,
275 version, 273 version,
276 &ping_data, 274 &ping_data,
277 std::string(), 275 std::string(),
278 kDefaultInstallSource); 276 kDefaultInstallSource);
279 StartUpdateCheck(blacklist_fetch.Pass()); 277 StartUpdateCheck(blacklist_fetch.Pass());
280 } 278 }
281 279
280 void ExtensionDownloader::SetWebstoreIdentityProvider(
281 scoped_ptr<IdentityProvider> identity_provider) {
282 identity_provider_.swap(identity_provider);
283 }
284
282 bool ExtensionDownloader::AddExtensionData(const std::string& id, 285 bool ExtensionDownloader::AddExtensionData(const std::string& id,
283 const Version& version, 286 const Version& version,
284 Manifest::Type extension_type, 287 Manifest::Type extension_type,
285 const GURL& extension_update_url, 288 const GURL& extension_update_url,
286 const std::string& update_url_data, 289 const std::string& update_url_data,
287 int request_id) { 290 int request_id) {
288 GURL update_url(extension_update_url); 291 GURL update_url(extension_update_url);
289 // Skip extensions with non-empty invalid update URLs. 292 // Skip extensions with non-empty invalid update URLs.
290 if (!update_url.is_empty() && !update_url.is_valid()) { 293 if (!update_url.is_empty() && !update_url.is_valid()) {
291 LOG(WARNING) << "Extension " << id << " has invalid update url " 294 LOG(WARNING) << "Extension " << id << " has invalid update url "
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 extension_fetcher_->SaveResponseToTemporaryFile( 742 extension_fetcher_->SaveResponseToTemporaryFile(
740 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); 743 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE));
741 } 744 }
742 745
743 if (fetch->credentials == ExtensionFetch::CREDENTIALS_OAUTH2_TOKEN && 746 if (fetch->credentials == ExtensionFetch::CREDENTIALS_OAUTH2_TOKEN &&
744 is_secure) { 747 is_secure) {
745 if (access_token_.empty()) { 748 if (access_token_.empty()) {
746 // We should try OAuth2, but we have no token cached. This 749 // We should try OAuth2, but we have no token cached. This
747 // ExtensionFetcher will be started once the token fetch is complete, 750 // ExtensionFetcher will be started once the token fetch is complete,
748 // in either OnTokenFetchSuccess or OnTokenFetchFailure. 751 // in either OnTokenFetchSuccess or OnTokenFetchFailure.
749 DCHECK(identity_provider_); 752 DCHECK(identity_provider_.get());
750 OAuth2TokenService::ScopeSet webstore_scopes; 753 OAuth2TokenService::ScopeSet webstore_scopes;
751 webstore_scopes.insert(kWebstoreOAuth2Scope); 754 webstore_scopes.insert(kWebstoreOAuth2Scope);
752 access_token_request_ = 755 access_token_request_ =
753 identity_provider_->GetTokenService()->StartRequest( 756 identity_provider_->GetTokenService()->StartRequest(
754 identity_provider_->GetActiveAccountId(), 757 identity_provider_->GetActiveAccountId(),
755 webstore_scopes, 758 webstore_scopes,
756 this); 759 this);
757 return; 760 return;
758 } 761 }
759 extension_fetcher_->AddExtraRequestHeader( 762 extension_fetcher_->AddExtraRequestHeader(
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 } else { 867 } else {
865 fetch->credentials = ExtensionFetch::CREDENTIALS_COOKIES; 868 fetch->credentials = ExtensionFetch::CREDENTIALS_COOKIES;
866 } 869 }
867 return true; 870 return true;
868 case ExtensionFetch::CREDENTIALS_OAUTH2_TOKEN: 871 case ExtensionFetch::CREDENTIALS_OAUTH2_TOKEN:
869 fetch->oauth2_attempt_count++; 872 fetch->oauth2_attempt_count++;
870 // OAuth2 may fail due to an expired access token, in which case we 873 // OAuth2 may fail due to an expired access token, in which case we
871 // should invalidate the token and try again. 874 // should invalidate the token and try again.
872 if (response_code == net::HTTP_UNAUTHORIZED && 875 if (response_code == net::HTTP_UNAUTHORIZED &&
873 fetch->oauth2_attempt_count <= kMaxOAuth2Attempts) { 876 fetch->oauth2_attempt_count <= kMaxOAuth2Attempts) {
874 DCHECK(identity_provider_ != NULL); 877 DCHECK(identity_provider_.get());
875 OAuth2TokenService::ScopeSet webstore_scopes; 878 OAuth2TokenService::ScopeSet webstore_scopes;
876 webstore_scopes.insert(kWebstoreOAuth2Scope); 879 webstore_scopes.insert(kWebstoreOAuth2Scope);
877 identity_provider_->GetTokenService()->InvalidateToken( 880 identity_provider_->GetTokenService()->InvalidateToken(
878 identity_provider_->GetActiveAccountId(), 881 identity_provider_->GetActiveAccountId(),
879 webstore_scopes, 882 webstore_scopes,
880 access_token_); 883 access_token_);
881 access_token_.clear(); 884 access_token_.clear();
882 return true; 885 return true;
883 } 886 }
884 // Either there is no Gaia identity available, the active identity 887 // Either there is no Gaia identity available, the active identity
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
919 922
920 void ExtensionDownloader::OnGetTokenFailure( 923 void ExtensionDownloader::OnGetTokenFailure(
921 const OAuth2TokenService::Request* request, 924 const OAuth2TokenService::Request* request,
922 const GoogleServiceAuthError& error) { 925 const GoogleServiceAuthError& error) {
923 // If we fail to get an access token, kick the pending fetch and let it fall 926 // If we fail to get an access token, kick the pending fetch and let it fall
924 // back on cookies. 927 // back on cookies.
925 extension_fetcher_->Start(); 928 extension_fetcher_->Start();
926 } 929 }
927 930
928 } // namespace extensions 931 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/updater/extension_downloader.h ('k') | chrome/browser/extensions/updater/extension_updater.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698