OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/profiles/profile_downloader.h" | 5 #include "chrome/browser/profiles/profile_downloader.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "chrome/common/net/gaia/gaia_urls.h" | 21 #include "chrome/common/net/gaia/gaia_urls.h" |
22 #include "chrome/common/net/gaia/oauth2_access_token_fetcher.h" | 22 #include "chrome/common/net/gaia/oauth2_access_token_fetcher.h" |
23 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
24 #include "content/public/browser/notification_details.h" | 24 #include "content/public/browser/notification_details.h" |
25 #include "content/public/browser/notification_observer.h" | 25 #include "content/public/browser/notification_observer.h" |
26 #include "content/public/browser/notification_registrar.h" | 26 #include "content/public/browser/notification_registrar.h" |
27 #include "content/public/browser/notification_source.h" | 27 #include "content/public/browser/notification_source.h" |
28 #include "content/public/browser/notification_types.h" | 28 #include "content/public/browser/notification_types.h" |
29 #include "content/public/common/url_fetcher.h" | 29 #include "content/public/common/url_fetcher.h" |
30 #include "googleurl/src/gurl.h" | 30 #include "googleurl/src/gurl.h" |
| 31 #include "net/base/load_flags.h" |
31 #include "skia/ext/image_operations.h" | 32 #include "skia/ext/image_operations.h" |
32 | 33 |
33 using content::BrowserThread; | 34 using content::BrowserThread; |
34 | 35 |
35 namespace { | 36 namespace { |
36 | 37 |
37 // Template for optional authorization header when using an OAuth access token. | 38 // Template for optional authorization header when using an OAuth access token. |
38 const char kAuthorizationHeader[] = | 39 const char kAuthorizationHeader[] = |
39 "Authorization: Bearer %s"; | 40 "Authorization: Bearer %s"; |
40 | 41 |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 std::string ProfileDownloader::GetProfilePictureURL() const { | 238 std::string ProfileDownloader::GetProfilePictureURL() const { |
238 return picture_url_; | 239 return picture_url_; |
239 } | 240 } |
240 | 241 |
241 void ProfileDownloader::StartFetchingImage() { | 242 void ProfileDownloader::StartFetchingImage() { |
242 VLOG(1) << "Fetching user entry with token: " << auth_token_; | 243 VLOG(1) << "Fetching user entry with token: " << auth_token_; |
243 user_entry_fetcher_.reset(content::URLFetcher::Create( | 244 user_entry_fetcher_.reset(content::URLFetcher::Create( |
244 GURL(kUserEntryURL), content::URLFetcher::GET, this)); | 245 GURL(kUserEntryURL), content::URLFetcher::GET, this)); |
245 user_entry_fetcher_->SetRequestContext( | 246 user_entry_fetcher_->SetRequestContext( |
246 delegate_->GetBrowserProfile()->GetRequestContext()); | 247 delegate_->GetBrowserProfile()->GetRequestContext()); |
| 248 user_entry_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES); |
247 if (!auth_token_.empty()) { | 249 if (!auth_token_.empty()) { |
248 user_entry_fetcher_->SetExtraRequestHeaders( | 250 user_entry_fetcher_->SetExtraRequestHeaders( |
249 base::StringPrintf(kAuthorizationHeader, auth_token_.c_str())); | 251 base::StringPrintf(kAuthorizationHeader, auth_token_.c_str())); |
250 } | 252 } |
251 user_entry_fetcher_->Start(); | 253 user_entry_fetcher_->Start(); |
252 } | 254 } |
253 | 255 |
254 void ProfileDownloader::StartFetchingOAuth2AccessToken() { | 256 void ProfileDownloader::StartFetchingOAuth2AccessToken() { |
255 TokenService* service = delegate_->GetBrowserProfile()->GetTokenService(); | 257 TokenService* service = delegate_->GetBrowserProfile()->GetTokenService(); |
256 DCHECK(!service->GetOAuth2LoginRefreshToken().empty()); | 258 DCHECK(!service->GetOAuth2LoginRefreshToken().empty()); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 picture_status_ = PICTURE_CACHED; | 300 picture_status_ = PICTURE_CACHED; |
299 delegate_->OnDownloadComplete(this, true); | 301 delegate_->OnDownloadComplete(this, true); |
300 return; | 302 return; |
301 } | 303 } |
302 VLOG(1) << "Fetching profile image from " << image_url; | 304 VLOG(1) << "Fetching profile image from " << image_url; |
303 picture_url_ = image_url; | 305 picture_url_ = image_url; |
304 profile_image_fetcher_.reset(content::URLFetcher::Create( | 306 profile_image_fetcher_.reset(content::URLFetcher::Create( |
305 GURL(image_url), content::URLFetcher::GET, this)); | 307 GURL(image_url), content::URLFetcher::GET, this)); |
306 profile_image_fetcher_->SetRequestContext( | 308 profile_image_fetcher_->SetRequestContext( |
307 delegate_->GetBrowserProfile()->GetRequestContext()); | 309 delegate_->GetBrowserProfile()->GetRequestContext()); |
| 310 profile_image_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES); |
308 if (!auth_token_.empty()) { | 311 if (!auth_token_.empty()) { |
309 profile_image_fetcher_->SetExtraRequestHeaders( | 312 profile_image_fetcher_->SetExtraRequestHeaders( |
310 base::StringPrintf(kAuthorizationHeader, auth_token_.c_str())); | 313 base::StringPrintf(kAuthorizationHeader, auth_token_.c_str())); |
311 } | 314 } |
312 profile_image_fetcher_->Start(); | 315 profile_image_fetcher_->Start(); |
313 } else if (source == profile_image_fetcher_.get()) { | 316 } else if (source == profile_image_fetcher_.get()) { |
314 VLOG(1) << "Decoding the image..."; | 317 VLOG(1) << "Decoding the image..."; |
315 scoped_refptr<ImageDecoder> image_decoder = new ImageDecoder( | 318 scoped_refptr<ImageDecoder> image_decoder = new ImageDecoder( |
316 this, data); | 319 this, data); |
317 image_decoder->Start(); | 320 image_decoder->Start(); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 void ProfileDownloader::OnGetTokenSuccess(const std::string& access_token) { | 369 void ProfileDownloader::OnGetTokenSuccess(const std::string& access_token) { |
367 auth_token_ = access_token; | 370 auth_token_ = access_token; |
368 StartFetchingImage(); | 371 StartFetchingImage(); |
369 } | 372 } |
370 | 373 |
371 // Callback for OAuth2AccessTokenFetcher on failure. | 374 // Callback for OAuth2AccessTokenFetcher on failure. |
372 void ProfileDownloader::OnGetTokenFailure(const GoogleServiceAuthError& error) { | 375 void ProfileDownloader::OnGetTokenFailure(const GoogleServiceAuthError& error) { |
373 LOG(WARNING) << "ProfileDownloader: token request using refresh token failed"; | 376 LOG(WARNING) << "ProfileDownloader: token request using refresh token failed"; |
374 delegate_->OnDownloadComplete(this, false); | 377 delegate_->OnDownloadComplete(this, false); |
375 } | 378 } |
OLD | NEW |