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

Side by Side Diff: chrome/browser/profiles/profile_downloader.cc

Issue 1091363002: Change ProfileDownloader to use AccountTrackerService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review feedback. Created 5 years, 7 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/strings/string_split.h" 13 #include "base/strings/string_split.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "base/strings/utf_string_conversions.h"
16 #include "base/values.h" 17 #include "base/values.h"
17 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/profiles/profile_downloader_delegate.h" 19 #include "chrome/browser/profiles/profile_downloader_delegate.h"
19 #include "chrome/browser/profiles/profile_manager.h" 20 #include "chrome/browser/profiles/profile_manager.h"
21 #include "chrome/browser/signin/account_tracker_service_factory.h"
20 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 22 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
21 #include "chrome/browser/signin/signin_manager_factory.h" 23 #include "chrome/browser/signin/signin_manager_factory.h"
22 #include "components/signin/core/browser/profile_oauth2_token_service.h" 24 #include "components/signin/core/browser/profile_oauth2_token_service.h"
23 #include "components/signin/core/browser/signin_manager.h" 25 #include "components/signin/core/browser/signin_manager.h"
24 #include "components/signin/core/common/profile_management_switches.h" 26 #include "components/signin/core/common/profile_management_switches.h"
25 #include "content/public/browser/browser_thread.h" 27 #include "content/public/browser/browser_thread.h"
26 #include "google_apis/gaia/gaia_constants.h" 28 #include "google_apis/gaia/gaia_constants.h"
27 #include "google_apis/gaia/gaia_urls.h"
28 #include "net/base/load_flags.h" 29 #include "net/base/load_flags.h"
29 #include "net/url_request/url_fetcher.h" 30 #include "net/url_request/url_fetcher.h"
30 #include "net/url_request/url_request_status.h" 31 #include "net/url_request/url_request_status.h"
31 #include "skia/ext/image_operations.h" 32 #include "skia/ext/image_operations.h"
32 #include "url/gurl.h" 33 #include "url/gurl.h"
33 34
34 using content::BrowserThread; 35 using content::BrowserThread;
35 36
36 namespace { 37 namespace {
37 38
38 // Template for optional authorization header when using an OAuth access token. 39 // Template for optional authorization header when using an OAuth access token.
39 const char kAuthorizationHeader[] = 40 const char kAuthorizationHeader[] =
40 "Authorization: Bearer %s"; 41 "Authorization: Bearer %s";
41 42
42 // Path in JSON dictionary to user's photo thumbnail URL.
43 const char kPhotoThumbnailURLPath[] = "picture";
44
45 // Path in JSON dictionary to user's hosted domain.
46 const char kHostedDomainPath[] = "hd";
47
48 // From the user info API, this field corresponds to the full name of the user.
49 const char kFullNamePath[] = "name";
50
51 const char kGivenNamePath[] = "given_name";
52
53 // Path in JSON dictionary to user's preferred locale.
54 const char kLocalePath[] = "locale";
55
56 // Path format for specifying thumbnail's size. 43 // Path format for specifying thumbnail's size.
57 const char kThumbnailSizeFormat[] = "s%d-c"; 44 const char kThumbnailSizeFormat[] = "s%d-c";
58 // Default thumbnail size. 45 // Default thumbnail size.
59 const int kDefaultThumbnailSize = 64; 46 const int kDefaultThumbnailSize = 64;
60 47
61 // Separator of URL path components. 48 // Separator of URL path components.
62 const char kURLPathSeparator = '/'; 49 const char kURLPathSeparator = '/';
63 50
64 // Photo ID of the Picasa Web Albums profile picture (base64 of 0). 51 // Photo ID of the Picasa Web Albums profile picture (base64 of 0).
65 const char kPicasaPhotoId[] = "AAAAAAAAAAA"; 52 const char kPicasaPhotoId[] = "AAAAAAAAAAA";
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 return new_url->is_valid(); 106 return new_url->is_valid();
120 } 107 }
121 108
122 // We can't set the image size, just use the default size. 109 // We can't set the image size, just use the default size.
123 *new_url = old_url; 110 *new_url = old_url;
124 return true; 111 return true;
125 } 112 }
126 113
127 } // namespace 114 } // namespace
128 115
129 // Parses the entry response and gets the name and profile image URL.
130 // |data| should be the JSON formatted data return by the response.
131 // Returns false to indicate a parsing error.
132 bool ProfileDownloader::ParseProfileJSON(base::DictionaryValue* root_dictionary,
133 base::string16* full_name,
134 base::string16* given_name,
135 std::string* url,
136 int image_size,
137 std::string* profile_locale,
138 base::string16* hosted_domain) {
139 DCHECK(full_name);
140 DCHECK(given_name);
141 DCHECK(url);
142 DCHECK(profile_locale);
143 DCHECK(hosted_domain);
144
145 *full_name = base::string16();
146 *given_name = base::string16();
147 *url = std::string();
148 *profile_locale = std::string();
149 *hosted_domain = base::string16();
150
151 root_dictionary->GetString(kFullNamePath, full_name);
152 root_dictionary->GetString(kGivenNamePath, given_name);
153 root_dictionary->GetString(kLocalePath, profile_locale);
154 root_dictionary->GetString(kHostedDomainPath, hosted_domain);
155
156 std::string url_string;
157 if (root_dictionary->GetString(kPhotoThumbnailURLPath, &url_string)) {
158 GURL new_url;
159 if (!GetImageURLWithSize(GURL(url_string), image_size, &new_url)) {
160 LOG(ERROR) << "GetImageURLWithSize failed for url: " << url_string;
161 return false;
162 }
163 *url = new_url.spec();
164 }
165
166 // The profile data is considered valid as long as it has a name or a picture.
167 return !full_name->empty() || !url->empty();
168 }
169
170 // static 116 // static
171 bool ProfileDownloader::IsDefaultProfileImageURL(const std::string& url) { 117 bool ProfileDownloader::IsDefaultProfileImageURL(const std::string& url) {
172 if (url.empty()) 118 if (url.empty())
173 return true; 119 return true;
174 120
175 GURL image_url_object(url); 121 GURL image_url_object(url);
176 DCHECK(image_url_object.is_valid()); 122 DCHECK(image_url_object.is_valid());
177 VLOG(1) << "URL to check for default image: " << image_url_object.spec(); 123 VLOG(1) << "URL to check for default image: " << image_url_object.spec();
178 std::vector<std::string> path_components; 124 std::vector<std::string> path_components;
179 base::SplitString(image_url_object.path(), 125 base::SplitString(image_url_object.path(),
180 kURLPathSeparator, 126 kURLPathSeparator,
181 &path_components); 127 &path_components);
182 128
183 if (path_components.size() < kProfileImageURLPathComponentsCount) 129 if (path_components.size() < kProfileImageURLPathComponentsCount)
184 return false; 130 return false;
185 131
186 const std::string& photo_id = path_components[kPhotoIdPathComponentIndex]; 132 const std::string& photo_id = path_components[kPhotoIdPathComponentIndex];
187 const std::string& photo_version = 133 const std::string& photo_version =
188 path_components[kPhotoVersionPathComponentIndex]; 134 path_components[kPhotoVersionPathComponentIndex];
189 135
190 // Check that the ID and version match the default Picasa profile photo. 136 // Check that the ID and version match the default Picasa profile photo.
191 return photo_id == kPicasaPhotoId && 137 return photo_id == kPicasaPhotoId &&
192 photo_version == kDefaultPicasaPhotoVersion; 138 photo_version == kDefaultPicasaPhotoVersion;
193 } 139 }
194 140
195 ProfileDownloader::ProfileDownloader(ProfileDownloaderDelegate* delegate) 141 ProfileDownloader::ProfileDownloader(ProfileDownloaderDelegate* delegate)
196 : OAuth2TokenService::Consumer("profile_downloader"), 142 : OAuth2TokenService::Consumer("profile_downloader"),
197 delegate_(delegate), 143 delegate_(delegate),
198 picture_status_(PICTURE_FAILED) { 144 picture_status_(PICTURE_FAILED),
145 account_tracker_service_(
146 AccountTrackerServiceFactory::GetForProfile(
147 delegate_->GetBrowserProfile())),
148 waiting_for_account_info_(false),
149 test_url_fetcher_provider_(nullptr) {
199 DCHECK(delegate_); 150 DCHECK(delegate_);
151 account_tracker_service_->AddObserver(this);
200 } 152 }
201 153
202 void ProfileDownloader::Start() { 154 void ProfileDownloader::Start() {
203 StartForAccount(std::string()); 155 StartForAccount(std::string());
204 } 156 }
205 157
206 void ProfileDownloader::StartForAccount(const std::string& account_id) { 158 void ProfileDownloader::StartForAccount(const std::string& account_id) {
207 VLOG(1) << "Starting profile downloader..."; 159 VLOG(1) << "Starting profile downloader...";
208 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 160 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
Mike Lerman 2015/04/30 19:09:07 Can we add a DCHECK that account_id_.empty()?
Roger Tawa OOO till Jul 10th 2015/05/01 15:51:26 Why? An empty value means use primary account. A n
anthonyvd 2015/05/01 19:16:34 Acknowledged.
209 161
210 ProfileOAuth2TokenService* service = 162 ProfileOAuth2TokenService* service =
211 ProfileOAuth2TokenServiceFactory::GetForProfile( 163 ProfileOAuth2TokenServiceFactory::GetForProfile(
212 delegate_->GetBrowserProfile()); 164 delegate_->GetBrowserProfile());
213 if (!service) { 165 if (!service) {
214 // This can happen in some test paths. 166 // This can happen in some test paths.
215 LOG(WARNING) << "User has no token service"; 167 LOG(WARNING) << "User has no token service";
216 delegate_->OnProfileDownloadFailure( 168 delegate_->OnProfileDownloadFailure(
217 this, ProfileDownloaderDelegate::TOKEN_ERROR); 169 this, ProfileDownloaderDelegate::TOKEN_ERROR);
218 return; 170 return;
219 } 171 }
220 172
221 SigninManagerBase* signin_manager = 173 SigninManagerBase* signin_manager =
222 SigninManagerFactory::GetForProfile(delegate_->GetBrowserProfile()); 174 SigninManagerFactory::GetForProfile(delegate_->GetBrowserProfile());
223 account_id_ = 175 account_id_ =
224 account_id.empty() ? 176 account_id.empty() ?
225 signin_manager->GetAuthenticatedAccountId() : account_id; 177 signin_manager->GetAuthenticatedAccountId() : account_id;
226 if (service->RefreshTokenIsAvailable(account_id_)) { 178 if (service->RefreshTokenIsAvailable(account_id_)) {
Mike Lerman 2015/04/30 19:09:07 nit: 1-line condition and statements mean we don't
anthonyvd 2015/05/01 19:16:34 Done.
227 StartFetchingOAuth2AccessToken(); 179 StartFetchingOAuth2AccessToken();
228 } else { 180 } else {
229 service->AddObserver(this); 181 service->AddObserver(this);
230 } 182 }
231 } 183 }
232 184
233 base::string16 ProfileDownloader::GetProfileHostedDomain() const { 185 base::string16 ProfileDownloader::GetProfileHostedDomain() const {
234 return profile_hosted_domain_; 186 return base::UTF8ToUTF16(account_info_.hosted_domain);
235 } 187 }
236 188
237 base::string16 ProfileDownloader::GetProfileFullName() const { 189 base::string16 ProfileDownloader::GetProfileFullName() const {
238 return profile_full_name_; 190 return base::UTF8ToUTF16(account_info_.full_name);
239 } 191 }
240 192
241 base::string16 ProfileDownloader::GetProfileGivenName() const { 193 base::string16 ProfileDownloader::GetProfileGivenName() const {
242 return profile_given_name_; 194 return base::UTF8ToUTF16(account_info_.given_name);
243 } 195 }
244 196
245 std::string ProfileDownloader::GetProfileLocale() const { 197 std::string ProfileDownloader::GetProfileLocale() const {
246 return profile_locale_; 198 return account_info_.locale;
247 } 199 }
248 200
249 SkBitmap ProfileDownloader::GetProfilePicture() const { 201 SkBitmap ProfileDownloader::GetProfilePicture() const {
250 return profile_picture_; 202 return profile_picture_;
251 } 203 }
252 204
253 ProfileDownloader::PictureStatus ProfileDownloader::GetProfilePictureStatus() 205 ProfileDownloader::PictureStatus ProfileDownloader::GetProfilePictureStatus()
254 const { 206 const {
255 return picture_status_; 207 return picture_status_;
256 } 208 }
257 209
258 std::string ProfileDownloader::GetProfilePictureURL() const { 210 std::string ProfileDownloader::GetProfilePictureURL() const {
259 return picture_url_; 211 GURL url;
212 if (!GetImageURLWithSize(GURL(account_info_.picture_url),
Roger Tawa OOO till Jul 10th 2015/05/01 15:51:26 Should there be a ! here?
anthonyvd 2015/05/01 19:16:34 Nope, good catch. Thanks!
213 delegate_->GetDesiredImageSideLength(),
214 &url)) {
215 return url.spec();
216 }
217 return account_info_.picture_url;
218 }
219
220 void ProfileDownloader::SetTestURLFetcherProvider(
221 TestURLFetcherProvider* provider) {
222 test_url_fetcher_provider_ = provider;
260 } 223 }
261 224
262 void ProfileDownloader::StartFetchingImage() { 225 void ProfileDownloader::StartFetchingImage() {
263 VLOG(1) << "Fetching user entry with token: " << auth_token_; 226 VLOG(1) << "Fetching user entry with token: " << auth_token_;
264 gaia_client_.reset(new gaia::GaiaOAuthClient( 227 account_info_ = account_tracker_service_->GetAccountInfo(account_id_);
265 delegate_->GetBrowserProfile()->GetRequestContext())); 228
266 gaia_client_->GetUserInfo(auth_token_, 0, this); 229 if (account_info_.IsValid()) {
Mike Lerman 2015/04/30 19:09:07 nit: don't need braces for the if/else when each s
Roger Tawa OOO till Jul 10th 2015/05/01 15:51:26 I believe you do if there is an else clause.
anthonyvd 2015/05/01 19:16:33 Done.
anthonyvd 2015/05/01 19:16:34 The style guide only says: "In general, curly brac
230 FetchImageData();
231 } else {
232 waiting_for_account_info_ = true;
233 }
267 } 234 }
268 235
269 void ProfileDownloader::StartFetchingOAuth2AccessToken() { 236 void ProfileDownloader::StartFetchingOAuth2AccessToken() {
270 Profile* profile = delegate_->GetBrowserProfile(); 237 Profile* profile = delegate_->GetBrowserProfile();
271 OAuth2TokenService::ScopeSet scopes; 238 OAuth2TokenService::ScopeSet scopes;
272 scopes.insert(GaiaConstants::kGoogleUserInfoProfile); 239 scopes.insert(GaiaConstants::kGoogleUserInfoProfile);
273 // Increase scope to get hd attribute to determine if lock should be enabled. 240 // Increase scope to get hd attribute to determine if lock should be enabled.
274 if (switches::IsNewProfileManagement()) 241 if (switches::IsNewProfileManagement())
275 scopes.insert(GaiaConstants::kGoogleUserInfoEmail); 242 scopes.insert(GaiaConstants::kGoogleUserInfoEmail);
276 ProfileOAuth2TokenService* token_service = 243 ProfileOAuth2TokenService* token_service =
277 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); 244 ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
278 oauth2_access_token_request_ = token_service->StartRequest( 245 oauth2_access_token_request_ = token_service->StartRequest(
279 account_id_, scopes, this); 246 account_id_, scopes, this);
280 } 247 }
281 248
282 ProfileDownloader::~ProfileDownloader() { 249 ProfileDownloader::~ProfileDownloader() {
283 // Ensures PO2TS observation is cleared when ProfileDownloader is destructed 250 // Ensures PO2TS observation is cleared when ProfileDownloader is destructed
284 // before refresh token is available. 251 // before refresh token is available.
285 ProfileOAuth2TokenService* service = 252 ProfileOAuth2TokenService* service =
286 ProfileOAuth2TokenServiceFactory::GetForProfile( 253 ProfileOAuth2TokenServiceFactory::GetForProfile(
287 delegate_->GetBrowserProfile()); 254 delegate_->GetBrowserProfile());
288 if (service) 255 if (service)
289 service->RemoveObserver(this); 256 service->RemoveObserver(this);
257
258 account_tracker_service_->RemoveObserver(this);
290 } 259 }
291 260
292 void ProfileDownloader::OnGetUserInfoResponse( 261 void ProfileDownloader::FetchImageData() {
293 scoped_ptr<base::DictionaryValue> user_info) { 262 GURL url;
Mike Lerman 2015/04/30 19:09:07 Can you DCHECK(account_info_.IsValid())?
anthonyvd 2015/05/01 19:16:34 Done.
294 std::string image_url; 263 if (!GetImageURLWithSize(GURL(account_info_.picture_url),
295 if (!ParseProfileJSON(user_info.get(), 264 delegate_->GetDesiredImageSideLength(),
296 &profile_full_name_, 265 &url)) {
Roger Tawa OOO till Jul 10th 2015/05/01 15:51:26 Can we call GetProfilePictureURL() here? Maybe on
anthonyvd 2015/05/01 19:16:34 Makes sense, done!
297 &profile_given_name_,
298 &image_url,
299 delegate_->GetDesiredImageSideLength(),
300 &profile_locale_,
301 &profile_hosted_domain_)) {
302 delegate_->OnProfileDownloadFailure(
303 this, ProfileDownloaderDelegate::SERVICE_ERROR);
304 return; 266 return;
305 } 267 }
268 std::string image_url_with_size = url.spec();
269
306 if (!delegate_->NeedsProfilePicture()) { 270 if (!delegate_->NeedsProfilePicture()) {
307 VLOG(1) << "Skipping profile picture download"; 271 VLOG(1) << "Skipping profile picture download";
308 delegate_->OnProfileDownloadSuccess(this); 272 delegate_->OnProfileDownloadSuccess(this);
309 return; 273 return;
310 } 274 }
311 if (IsDefaultProfileImageURL(image_url)) { 275 if (IsDefaultProfileImageURL(image_url_with_size)) {
312 VLOG(1) << "User has default profile picture"; 276 VLOG(1) << "User has default profile picture";
313 picture_status_ = PICTURE_DEFAULT; 277 picture_status_ = PICTURE_DEFAULT;
314 delegate_->OnProfileDownloadSuccess(this); 278 delegate_->OnProfileDownloadSuccess(this);
315 return; 279 return;
316 } 280 }
317 if (!image_url.empty() && image_url == delegate_->GetCachedPictureURL()) { 281 if (!image_url_with_size.empty() &&
282 image_url_with_size == delegate_->GetCachedPictureURL()) {
318 VLOG(1) << "Picture URL matches cached picture URL"; 283 VLOG(1) << "Picture URL matches cached picture URL";
319 picture_status_ = PICTURE_CACHED; 284 picture_status_ = PICTURE_CACHED;
320 delegate_->OnProfileDownloadSuccess(this); 285 delegate_->OnProfileDownloadSuccess(this);
321 return; 286 return;
322 } 287 }
323 VLOG(1) << "Fetching profile image from " << image_url; 288 VLOG(1) << "Fetching profile image from " << image_url_with_size;
324 picture_url_ = image_url; 289
325 profile_image_fetcher_.reset(net::URLFetcher::Create( 290 net::URLFetcher* new_fetcher = test_url_fetcher_provider_ ?
326 GURL(image_url), net::URLFetcher::GET, this)); 291 test_url_fetcher_provider_->test_url_fetcher() :
292 net::URLFetcher::Create(
293 GURL(image_url_with_size), net::URLFetcher::GET, this);
294
295 profile_image_fetcher_.reset(new_fetcher);
327 profile_image_fetcher_->SetRequestContext( 296 profile_image_fetcher_->SetRequestContext(
328 delegate_->GetBrowserProfile()->GetRequestContext()); 297 delegate_->GetBrowserProfile()->GetRequestContext());
329 profile_image_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | 298 profile_image_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
330 net::LOAD_DO_NOT_SAVE_COOKIES); 299 net::LOAD_DO_NOT_SAVE_COOKIES);
300
331 if (!auth_token_.empty()) { 301 if (!auth_token_.empty()) {
332 profile_image_fetcher_->SetExtraRequestHeaders( 302 profile_image_fetcher_->SetExtraRequestHeaders(
333 base::StringPrintf(kAuthorizationHeader, auth_token_.c_str())); 303 base::StringPrintf(kAuthorizationHeader, auth_token_.c_str()));
334 } 304 }
335 profile_image_fetcher_->Start(); 305 profile_image_fetcher_->Start();
336 } 306 }
337 307
338 void ProfileDownloader::OnOAuthError() {
339 LOG(WARNING) << "OnOAuthError: Fetching profile data failed";
340 delegate_->OnProfileDownloadFailure(
341 this, ProfileDownloaderDelegate::SERVICE_ERROR);
342 }
343
344 void ProfileDownloader::OnNetworkError(int response_code) {
345 LOG(WARNING) << "OnNetworkError: Fetching profile data failed";
346 DVLOG(1) << " Response code: " << response_code;
347 delegate_->OnProfileDownloadFailure(
348 this, ProfileDownloaderDelegate::NETWORK_ERROR);
349 }
350
351 void ProfileDownloader::OnURLFetchComplete(const net::URLFetcher* source) { 308 void ProfileDownloader::OnURLFetchComplete(const net::URLFetcher* source) {
352 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 309 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
353 std::string data; 310 std::string data;
354 source->GetResponseAsString(&data); 311 source->GetResponseAsString(&data);
355 bool network_error = 312 bool network_error =
356 source->GetStatus().status() != net::URLRequestStatus::SUCCESS; 313 source->GetStatus().status() != net::URLRequestStatus::SUCCESS;
357 if (network_error || source->GetResponseCode() != 200) { 314 if (network_error || source->GetResponseCode() != 200) {
358 LOG(WARNING) << "Fetching profile data failed"; 315 LOG(WARNING) << "Fetching profile data failed";
359 DVLOG(1) << " Status: " << source->GetStatus().status(); 316 DVLOG(1) << " Status: " << source->GetStatus().status();
360 DVLOG(1) << " Error: " << source->GetStatus().error(); 317 DVLOG(1) << " Error: " << source->GetStatus().error();
361 DVLOG(1) << " Response code: " << source->GetResponseCode(); 318 DVLOG(1) << " Response code: " << source->GetResponseCode();
362 DVLOG(1) << " Url: " << source->GetURL().spec(); 319 DVLOG(1) << " Url: " << source->GetURL().spec();
320 profile_image_fetcher_.reset();
363 delegate_->OnProfileDownloadFailure(this, network_error ? 321 delegate_->OnProfileDownloadFailure(this, network_error ?
364 ProfileDownloaderDelegate::NETWORK_ERROR : 322 ProfileDownloaderDelegate::NETWORK_ERROR :
365 ProfileDownloaderDelegate::SERVICE_ERROR); 323 ProfileDownloaderDelegate::SERVICE_ERROR);
366 return; 324 } else {
325 profile_image_fetcher_.reset();
326 VLOG(1) << "Decoding the image...";
327 ImageDecoder::Start(this, data);
367 } 328 }
368
369 VLOG(1) << "Decoding the image...";
370 ImageDecoder::Start(this, data);
371 } 329 }
372 330
373 void ProfileDownloader::OnImageDecoded(const SkBitmap& decoded_image) { 331 void ProfileDownloader::OnImageDecoded(const SkBitmap& decoded_image) {
374 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 332 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
375 int image_size = delegate_->GetDesiredImageSideLength(); 333 int image_size = delegate_->GetDesiredImageSideLength();
376 profile_picture_ = skia::ImageOperations::Resize( 334 profile_picture_ = skia::ImageOperations::Resize(
377 decoded_image, 335 decoded_image,
378 skia::ImageOperations::RESIZE_BEST, 336 skia::ImageOperations::RESIZE_BEST,
379 image_size, 337 image_size,
380 image_size); 338 image_size);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 void ProfileDownloader::OnGetTokenFailure( 373 void ProfileDownloader::OnGetTokenFailure(
416 const OAuth2TokenService::Request* request, 374 const OAuth2TokenService::Request* request,
417 const GoogleServiceAuthError& error) { 375 const GoogleServiceAuthError& error) {
418 DCHECK_EQ(request, oauth2_access_token_request_.get()); 376 DCHECK_EQ(request, oauth2_access_token_request_.get());
419 oauth2_access_token_request_.reset(); 377 oauth2_access_token_request_.reset();
420 LOG(WARNING) << "ProfileDownloader: token request using refresh token failed:" 378 LOG(WARNING) << "ProfileDownloader: token request using refresh token failed:"
421 << error.ToString(); 379 << error.ToString();
422 delegate_->OnProfileDownloadFailure( 380 delegate_->OnProfileDownloadFailure(
423 this, ProfileDownloaderDelegate::TOKEN_ERROR); 381 this, ProfileDownloaderDelegate::TOKEN_ERROR);
424 } 382 }
383
384 void ProfileDownloader::OnAccountUpdated(
385 const AccountTrackerService::AccountInfo& info) {
386 if (info.account_id == account_id_ && info.IsValid()) {
387 account_info_ = info;
388
389 // If the StartFetchingImage was called before we had valid info, the
390 // downloader has been waiting so we need to fetch the image data now.
391 if (waiting_for_account_info_) {
392 FetchImageData();
393 waiting_for_account_info_ = false;
394 }
395 }
396 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698