OLD | NEW |
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/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/chrome_notification_types.h" | 21 #include "chrome/common/chrome_notification_types.h" |
22 #include "chrome/common/net/gaia/gaia_constants.h" | 22 #include "chrome/common/net/gaia/gaia_constants.h" |
23 #include "chrome/common/net/gaia/gaia_urls.h" | 23 #include "chrome/common/net/gaia/gaia_urls.h" |
24 #include "chrome/common/net/gaia/oauth2_access_token_fetcher.h" | 24 #include "chrome/common/net/gaia/oauth2_access_token_fetcher.h" |
25 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
26 #include "content/public/browser/notification_details.h" | 26 #include "content/public/browser/notification_details.h" |
27 #include "content/public/browser/notification_observer.h" | 27 #include "content/public/browser/notification_observer.h" |
28 #include "content/public/browser/notification_registrar.h" | 28 #include "content/public/browser/notification_registrar.h" |
29 #include "content/public/browser/notification_source.h" | 29 #include "content/public/browser/notification_source.h" |
30 #include "content/public/browser/notification_types.h" | 30 #include "content/public/browser/notification_types.h" |
31 #include "content/public/common/url_fetcher.h" | |
32 #include "googleurl/src/gurl.h" | 31 #include "googleurl/src/gurl.h" |
33 #include "net/base/load_flags.h" | 32 #include "net/base/load_flags.h" |
| 33 #include "net/url_request/url_fetcher.h" |
34 #include "skia/ext/image_operations.h" | 34 #include "skia/ext/image_operations.h" |
35 | 35 |
36 using content::BrowserThread; | 36 using content::BrowserThread; |
37 | 37 |
38 namespace { | 38 namespace { |
39 | 39 |
40 // Template for optional authorization header when using an OAuth access token. | 40 // Template for optional authorization header when using an OAuth access token. |
41 const char kAuthorizationHeader[] = | 41 const char kAuthorizationHeader[] = |
42 "Authorization: Bearer %s"; | 42 "Authorization: Bearer %s"; |
43 | 43 |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 const { | 237 const { |
238 return picture_status_; | 238 return picture_status_; |
239 } | 239 } |
240 | 240 |
241 std::string ProfileDownloader::GetProfilePictureURL() const { | 241 std::string ProfileDownloader::GetProfilePictureURL() const { |
242 return picture_url_; | 242 return picture_url_; |
243 } | 243 } |
244 | 244 |
245 void ProfileDownloader::StartFetchingImage() { | 245 void ProfileDownloader::StartFetchingImage() { |
246 VLOG(1) << "Fetching user entry with token: " << auth_token_; | 246 VLOG(1) << "Fetching user entry with token: " << auth_token_; |
247 user_entry_fetcher_.reset(content::URLFetcher::Create( | 247 user_entry_fetcher_.reset(net::URLFetcher::Create( |
248 GURL(kUserEntryURL), net::URLFetcher::GET, this)); | 248 GURL(kUserEntryURL), net::URLFetcher::GET, this)); |
249 user_entry_fetcher_->SetRequestContext( | 249 user_entry_fetcher_->SetRequestContext( |
250 delegate_->GetBrowserProfile()->GetRequestContext()); | 250 delegate_->GetBrowserProfile()->GetRequestContext()); |
251 user_entry_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 251 user_entry_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
252 net::LOAD_DO_NOT_SAVE_COOKIES); | 252 net::LOAD_DO_NOT_SAVE_COOKIES); |
253 if (!auth_token_.empty()) { | 253 if (!auth_token_.empty()) { |
254 user_entry_fetcher_->SetExtraRequestHeaders( | 254 user_entry_fetcher_->SetExtraRequestHeaders( |
255 base::StringPrintf(kAuthorizationHeader, auth_token_.c_str())); | 255 base::StringPrintf(kAuthorizationHeader, auth_token_.c_str())); |
256 } | 256 } |
257 user_entry_fetcher_->Start(); | 257 user_entry_fetcher_->Start(); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 return; | 301 return; |
302 } | 302 } |
303 if (!image_url.empty() && image_url == delegate_->GetCachedPictureURL()) { | 303 if (!image_url.empty() && image_url == delegate_->GetCachedPictureURL()) { |
304 VLOG(1) << "Picture URL matches cached picture URL"; | 304 VLOG(1) << "Picture URL matches cached picture URL"; |
305 picture_status_ = PICTURE_CACHED; | 305 picture_status_ = PICTURE_CACHED; |
306 delegate_->OnDownloadComplete(this, true); | 306 delegate_->OnDownloadComplete(this, true); |
307 return; | 307 return; |
308 } | 308 } |
309 VLOG(1) << "Fetching profile image from " << image_url; | 309 VLOG(1) << "Fetching profile image from " << image_url; |
310 picture_url_ = image_url; | 310 picture_url_ = image_url; |
311 profile_image_fetcher_.reset(content::URLFetcher::Create( | 311 profile_image_fetcher_.reset(net::URLFetcher::Create( |
312 GURL(image_url), net::URLFetcher::GET, this)); | 312 GURL(image_url), net::URLFetcher::GET, this)); |
313 profile_image_fetcher_->SetRequestContext( | 313 profile_image_fetcher_->SetRequestContext( |
314 delegate_->GetBrowserProfile()->GetRequestContext()); | 314 delegate_->GetBrowserProfile()->GetRequestContext()); |
315 profile_image_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 315 profile_image_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
316 net::LOAD_DO_NOT_SAVE_COOKIES); | 316 net::LOAD_DO_NOT_SAVE_COOKIES); |
317 if (!auth_token_.empty()) { | 317 if (!auth_token_.empty()) { |
318 profile_image_fetcher_->SetExtraRequestHeaders( | 318 profile_image_fetcher_->SetExtraRequestHeaders( |
319 base::StringPrintf(kAuthorizationHeader, auth_token_.c_str())); | 319 base::StringPrintf(kAuthorizationHeader, auth_token_.c_str())); |
320 } | 320 } |
321 profile_image_fetcher_->Start(); | 321 profile_image_fetcher_->Start(); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 void ProfileDownloader::OnGetTokenSuccess(const std::string& access_token) { | 375 void ProfileDownloader::OnGetTokenSuccess(const std::string& access_token) { |
376 auth_token_ = access_token; | 376 auth_token_ = access_token; |
377 StartFetchingImage(); | 377 StartFetchingImage(); |
378 } | 378 } |
379 | 379 |
380 // Callback for OAuth2AccessTokenFetcher on failure. | 380 // Callback for OAuth2AccessTokenFetcher on failure. |
381 void ProfileDownloader::OnGetTokenFailure(const GoogleServiceAuthError& error) { | 381 void ProfileDownloader::OnGetTokenFailure(const GoogleServiceAuthError& error) { |
382 LOG(WARNING) << "ProfileDownloader: token request using refresh token failed"; | 382 LOG(WARNING) << "ProfileDownloader: token request using refresh token failed"; |
383 delegate_->OnDownloadComplete(this, false); | 383 delegate_->OnDownloadComplete(this, false); |
384 } | 384 } |
OLD | NEW |