OLD | NEW |
---|---|
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" |
Mike Lerman
2015/04/20 13:25:22
I imagine these google_apis/gaia includes aren't n
anthonyvd
2015/04/29 15:15:08
gaia_constants still is but gaia_urls isn't anymor
| |
27 #include "google_apis/gaia/gaia_urls.h" | 29 #include "google_apis/gaia/gaia_urls.h" |
28 #include "net/base/load_flags.h" | 30 #include "net/base/load_flags.h" |
29 #include "net/url_request/url_fetcher.h" | 31 #include "net/url_request/url_fetcher.h" |
30 #include "net/url_request/url_request_status.h" | 32 #include "net/url_request/url_request_status.h" |
31 #include "skia/ext/image_operations.h" | 33 #include "skia/ext/image_operations.h" |
32 #include "url/gurl.h" | 34 #include "url/gurl.h" |
33 | 35 |
34 using content::BrowserThread; | 36 using content::BrowserThread; |
35 | 37 |
36 namespace { | 38 namespace { |
37 | 39 |
38 // Template for optional authorization header when using an OAuth access token. | 40 // Template for optional authorization header when using an OAuth access token. |
39 const char kAuthorizationHeader[] = | 41 const char kAuthorizationHeader[] = |
40 "Authorization: Bearer %s"; | 42 "Authorization: Bearer %s"; |
41 | 43 |
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. | 44 // Path format for specifying thumbnail's size. |
57 const char kThumbnailSizeFormat[] = "s%d-c"; | 45 const char kThumbnailSizeFormat[] = "s%d-c"; |
58 // Default thumbnail size. | 46 // Default thumbnail size. |
59 const int kDefaultThumbnailSize = 64; | 47 const int kDefaultThumbnailSize = 64; |
60 | 48 |
61 // Separator of URL path components. | 49 // Separator of URL path components. |
62 const char kURLPathSeparator = '/'; | 50 const char kURLPathSeparator = '/'; |
63 | 51 |
64 // Photo ID of the Picasa Web Albums profile picture (base64 of 0). | 52 // Photo ID of the Picasa Web Albums profile picture (base64 of 0). |
65 const char kPicasaPhotoId[] = "AAAAAAAAAAA"; | 53 const char kPicasaPhotoId[] = "AAAAAAAAAAA"; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 return new_url->is_valid(); | 107 return new_url->is_valid(); |
120 } | 108 } |
121 | 109 |
122 // We can't set the image size, just use the default size. | 110 // We can't set the image size, just use the default size. |
123 *new_url = old_url; | 111 *new_url = old_url; |
124 return true; | 112 return true; |
125 } | 113 } |
126 | 114 |
127 } // namespace | 115 } // namespace |
128 | 116 |
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 | 117 // static |
171 bool ProfileDownloader::IsDefaultProfileImageURL(const std::string& url) { | 118 bool ProfileDownloader::IsDefaultProfileImageURL(const std::string& url) { |
172 if (url.empty()) | 119 if (url.empty()) |
173 return true; | 120 return true; |
174 | 121 |
175 GURL image_url_object(url); | 122 GURL image_url_object(url); |
176 DCHECK(image_url_object.is_valid()); | 123 DCHECK(image_url_object.is_valid()); |
177 VLOG(1) << "URL to check for default image: " << image_url_object.spec(); | 124 VLOG(1) << "URL to check for default image: " << image_url_object.spec(); |
178 std::vector<std::string> path_components; | 125 std::vector<std::string> path_components; |
179 base::SplitString(image_url_object.path(), | 126 base::SplitString(image_url_object.path(), |
(...skipping 18 matching lines...) Expand all Loading... | |
198 OAuth2TokenService::Consumer("profile_downloader"), | 145 OAuth2TokenService::Consumer("profile_downloader"), |
199 delegate_(delegate), | 146 delegate_(delegate), |
200 picture_status_(PICTURE_FAILED) { | 147 picture_status_(PICTURE_FAILED) { |
201 DCHECK(delegate_); | 148 DCHECK(delegate_); |
202 } | 149 } |
203 | 150 |
204 void ProfileDownloader::Start() { | 151 void ProfileDownloader::Start() { |
205 StartForAccount(std::string()); | 152 StartForAccount(std::string()); |
206 } | 153 } |
207 | 154 |
208 void ProfileDownloader::StartForAccount(const std::string& account_id) { | 155 void ProfileDownloader::StartForAccount( |
156 const std::string& account_id, | |
157 AccountTrackerService* account_tracker_service) { | |
209 VLOG(1) << "Starting profile downloader..."; | 158 VLOG(1) << "Starting profile downloader..."; |
210 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 159 // Ensure that these methods are called on the UI thread, except for |
160 // unittests where a UI thread might not have been created. | |
161 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | |
162 !BrowserThread::IsMessageLoopValid(BrowserThread::UI)); | |
Mike Lerman
2015/04/20 13:25:23
I don't understand why you need IsMessageLoopValid
Roger Tawa OOO till Jul 10th
2015/04/21 14:00:33
Use a TestBrowserThreadBundle in the test.
anthonyvd
2015/04/29 15:15:08
Done.
| |
211 | 163 |
212 ProfileOAuth2TokenService* service = | 164 ProfileOAuth2TokenService* service = |
213 ProfileOAuth2TokenServiceFactory::GetForProfile( | 165 ProfileOAuth2TokenServiceFactory::GetForProfile( |
214 delegate_->GetBrowserProfile()); | 166 delegate_->GetBrowserProfile()); |
215 if (!service) { | 167 if (!service) { |
216 // This can happen in some test paths. | 168 // This can happen in some test paths. |
217 LOG(WARNING) << "User has no token service"; | 169 LOG(WARNING) << "User has no token service"; |
218 delegate_->OnProfileDownloadFailure( | 170 delegate_->OnProfileDownloadFailure( |
219 this, ProfileDownloaderDelegate::TOKEN_ERROR); | 171 this, ProfileDownloaderDelegate::TOKEN_ERROR); |
220 return; | 172 return; |
221 } | 173 } |
222 | 174 |
223 SigninManagerBase* signin_manager = | 175 SigninManagerBase* signin_manager = |
224 SigninManagerFactory::GetForProfile(delegate_->GetBrowserProfile()); | 176 SigninManagerFactory::GetForProfile(delegate_->GetBrowserProfile()); |
225 account_id_ = | 177 account_id_ = |
226 account_id.empty() ? | 178 account_id.empty() ? |
227 signin_manager->GetAuthenticatedAccountId() : account_id; | 179 signin_manager->GetAuthenticatedAccountId() : account_id; |
228 if (service->RefreshTokenIsAvailable(account_id_)) { | 180 if (service->RefreshTokenIsAvailable(account_id_)) { |
229 StartFetchingOAuth2AccessToken(); | 181 StartFetchingOAuth2AccessToken(); |
230 } else { | 182 } else { |
231 service->AddObserver(this); | 183 service->AddObserver(this); |
232 } | 184 } |
185 | |
186 if (account_tracker_service) | |
Mike Lerman
2015/04/20 13:25:22
Since we now have a reference to a PKS, I wonder i
Roger Tawa OOO till Jul 10th
2015/04/21 14:00:33
I think it might be worth making this a PKS, since
| |
187 account_tracker_service_ = account_tracker_service; | |
188 else | |
189 account_tracker_service_ = AccountTrackerServiceFactory::GetForProfile( | |
190 delegate_->GetBrowserProfile()); | |
233 } | 191 } |
234 | 192 |
235 base::string16 ProfileDownloader::GetProfileHostedDomain() const { | 193 base::string16 ProfileDownloader::GetProfileHostedDomain() const { |
236 return profile_hosted_domain_; | 194 return base::UTF8ToUTF16(account_info_.hosted_domain); |
Mike Lerman
2015/04/20 13:25:23
I'm not convinced we still need these methods at a
Roger Tawa OOO till Jul 10th
2015/04/21 14:00:33
Agreed we don't need these methods. As is, the co
| |
237 } | 195 } |
238 | 196 |
239 base::string16 ProfileDownloader::GetProfileFullName() const { | 197 base::string16 ProfileDownloader::GetProfileFullName() const { |
240 return profile_full_name_; | 198 return base::UTF8ToUTF16(account_info_.full_name); |
241 } | 199 } |
242 | 200 |
243 base::string16 ProfileDownloader::GetProfileGivenName() const { | 201 base::string16 ProfileDownloader::GetProfileGivenName() const { |
244 return profile_given_name_; | 202 return base::UTF8ToUTF16(account_info_.given_name); |
245 } | 203 } |
246 | 204 |
247 std::string ProfileDownloader::GetProfileLocale() const { | 205 std::string ProfileDownloader::GetProfileLocale() const { |
248 return profile_locale_; | 206 return account_info_.locale; |
249 } | 207 } |
250 | 208 |
251 SkBitmap ProfileDownloader::GetProfilePicture() const { | 209 SkBitmap ProfileDownloader::GetProfilePicture() const { |
252 return profile_picture_; | 210 return profile_picture_; |
253 } | 211 } |
254 | 212 |
255 ProfileDownloader::PictureStatus ProfileDownloader::GetProfilePictureStatus() | 213 ProfileDownloader::PictureStatus ProfileDownloader::GetProfilePictureStatus() |
256 const { | 214 const { |
257 return picture_status_; | 215 return picture_status_; |
258 } | 216 } |
259 | 217 |
260 std::string ProfileDownloader::GetProfilePictureURL() const { | 218 std::string ProfileDownloader::GetProfilePictureURL() const { |
261 return picture_url_; | 219 return account_info_.picture_url; |
Mike Lerman
2015/04/20 13:25:23
This used to be the result of GetImageURLWithSize.
anthonyvd
2015/04/29 15:15:08
You're right, fixed!
| |
220 } | |
221 | |
222 void ProfileDownloader::StartFetchingImageForTesting( | |
223 net::URLFetcher* image_fetcher) { | |
224 profile_image_fetcher_.reset(image_fetcher); | |
225 StartFetchingImage(); | |
262 } | 226 } |
263 | 227 |
264 void ProfileDownloader::StartFetchingImage() { | 228 void ProfileDownloader::StartFetchingImage() { |
265 VLOG(1) << "Fetching user entry with token: " << auth_token_; | 229 VLOG(1) << "Fetching user entry with token: " << auth_token_; |
266 gaia_client_.reset(new gaia::GaiaOAuthClient( | 230 |
Mike Lerman
2015/04/20 13:25:23
nit: Delete this empty line.
anthonyvd
2015/04/29 15:15:08
Done.
| |
267 delegate_->GetBrowserProfile()->GetRequestContext())); | 231 account_info_ = account_tracker_service_->GetAccountInfo(account_id_); |
268 gaia_client_->GetUserInfo(auth_token_, 0, this); | 232 |
233 if (account_info_.IsValid()) { | |
234 FetchImageData(account_info_.picture_url); | |
235 } else { | |
236 account_tracker_service_->AddObserver(this); | |
Mike Lerman
2015/04/20 13:25:23
I think the idea here is that the ATS is still fet
Roger Tawa OOO till Jul 10th
2015/04/21 14:00:33
Right, would be better to get pointer to ATS in ct
anthonyvd
2015/04/29 15:15:08
Makes sense, done. The new version starts observin
| |
237 } | |
269 } | 238 } |
270 | 239 |
271 void ProfileDownloader::StartFetchingOAuth2AccessToken() { | 240 void ProfileDownloader::StartFetchingOAuth2AccessToken() { |
272 Profile* profile = delegate_->GetBrowserProfile(); | 241 Profile* profile = delegate_->GetBrowserProfile(); |
273 OAuth2TokenService::ScopeSet scopes; | 242 OAuth2TokenService::ScopeSet scopes; |
274 scopes.insert(GaiaConstants::kGoogleUserInfoProfile); | 243 scopes.insert(GaiaConstants::kGoogleUserInfoProfile); |
275 // Increase scope to get hd attribute to determine if lock should be enabled. | 244 // Increase scope to get hd attribute to determine if lock should be enabled. |
276 if (switches::IsNewProfileManagement()) | 245 if (switches::IsNewProfileManagement()) |
277 scopes.insert(GaiaConstants::kGoogleUserInfoEmail); | 246 scopes.insert(GaiaConstants::kGoogleUserInfoEmail); |
278 ProfileOAuth2TokenService* token_service = | 247 ProfileOAuth2TokenService* token_service = |
279 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); | 248 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); |
280 oauth2_access_token_request_ = token_service->StartRequest( | 249 oauth2_access_token_request_ = token_service->StartRequest( |
281 account_id_, scopes, this); | 250 account_id_, scopes, this); |
282 } | 251 } |
283 | 252 |
284 ProfileDownloader::~ProfileDownloader() { | 253 ProfileDownloader::~ProfileDownloader() { |
285 // Ensures PO2TS observation is cleared when ProfileDownloader is destructed | 254 // Ensures PO2TS observation is cleared when ProfileDownloader is destructed |
286 // before refresh token is available. | 255 // before refresh token is available. |
287 ProfileOAuth2TokenService* service = | 256 ProfileOAuth2TokenService* service = |
288 ProfileOAuth2TokenServiceFactory::GetForProfile( | 257 ProfileOAuth2TokenServiceFactory::GetForProfile( |
289 delegate_->GetBrowserProfile()); | 258 delegate_->GetBrowserProfile()); |
290 if (service) | 259 if (service) |
291 service->RemoveObserver(this); | 260 service->RemoveObserver(this); |
292 } | 261 } |
293 | 262 |
294 void ProfileDownloader::OnGetUserInfoResponse( | 263 void ProfileDownloader::FetchImageData(std::string image_url) { |
Roger Tawa OOO till Jul 10th
2015/04/21 14:00:33
This should probably be a no-arg function. All ca
anthonyvd
2015/04/29 15:15:08
Done.
| |
295 scoped_ptr<base::DictionaryValue> user_info) { | 264 GURL url; |
296 std::string image_url; | 265 if (!GetImageURLWithSize(GURL(image_url), |
297 if (!ParseProfileJSON(user_info.get(), | 266 delegate_->GetDesiredImageSideLength(), |
298 &profile_full_name_, | 267 &url)) { |
299 &profile_given_name_, | |
300 &image_url, | |
301 delegate_->GetDesiredImageSideLength(), | |
302 &profile_locale_, | |
303 &profile_hosted_domain_)) { | |
304 delegate_->OnProfileDownloadFailure( | |
305 this, ProfileDownloaderDelegate::SERVICE_ERROR); | |
306 return; | 268 return; |
307 } | 269 } |
270 std::string image_url_with_size = url.spec(); | |
271 | |
308 if (!delegate_->NeedsProfilePicture()) { | 272 if (!delegate_->NeedsProfilePicture()) { |
309 VLOG(1) << "Skipping profile picture download"; | 273 VLOG(1) << "Skipping profile picture download"; |
310 delegate_->OnProfileDownloadSuccess(this); | 274 delegate_->OnProfileDownloadSuccess(this); |
311 return; | 275 return; |
312 } | 276 } |
313 if (IsDefaultProfileImageURL(image_url)) { | 277 if (IsDefaultProfileImageURL(image_url_with_size)) { |
314 VLOG(1) << "User has default profile picture"; | 278 VLOG(1) << "User has default profile picture"; |
315 picture_status_ = PICTURE_DEFAULT; | 279 picture_status_ = PICTURE_DEFAULT; |
316 delegate_->OnProfileDownloadSuccess(this); | 280 delegate_->OnProfileDownloadSuccess(this); |
317 return; | 281 return; |
318 } | 282 } |
319 if (!image_url.empty() && image_url == delegate_->GetCachedPictureURL()) { | 283 if (!image_url_with_size.empty() && |
284 image_url_with_size == delegate_->GetCachedPictureURL()) { | |
320 VLOG(1) << "Picture URL matches cached picture URL"; | 285 VLOG(1) << "Picture URL matches cached picture URL"; |
321 picture_status_ = PICTURE_CACHED; | 286 picture_status_ = PICTURE_CACHED; |
322 delegate_->OnProfileDownloadSuccess(this); | 287 delegate_->OnProfileDownloadSuccess(this); |
323 return; | 288 return; |
324 } | 289 } |
325 VLOG(1) << "Fetching profile image from " << image_url; | 290 VLOG(1) << "Fetching profile image from " << image_url_with_size; |
326 picture_url_ = image_url; | 291 |
327 profile_image_fetcher_.reset(net::URLFetcher::Create( | 292 if (!profile_image_fetcher_) { |
Mike Lerman
2015/04/20 13:25:23
Why not reset and Create a new fetcher? That way,
anthonyvd
2015/04/29 15:15:08
That makes a lot of sense. I wasn't resetting the
Mike Lerman
2015/04/30 19:09:06
commented in the header - use the TestSigninClient
anthonyvd
2015/05/01 19:16:33
See header, done!
| |
328 GURL(image_url), net::URLFetcher::GET, this)); | 293 profile_image_fetcher_.reset(net::URLFetcher::Create( |
329 profile_image_fetcher_->SetRequestContext( | 294 GURL(image_url_with_size), net::URLFetcher::GET, this)); |
330 delegate_->GetBrowserProfile()->GetRequestContext()); | 295 profile_image_fetcher_->SetRequestContext( |
331 profile_image_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 296 delegate_->GetBrowserProfile()->GetRequestContext()); |
332 net::LOAD_DO_NOT_SAVE_COOKIES); | 297 profile_image_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
298 net::LOAD_DO_NOT_SAVE_COOKIES); | |
299 } | |
300 | |
333 if (!auth_token_.empty()) { | 301 if (!auth_token_.empty()) { |
334 profile_image_fetcher_->SetExtraRequestHeaders( | 302 profile_image_fetcher_->SetExtraRequestHeaders( |
335 base::StringPrintf(kAuthorizationHeader, auth_token_.c_str())); | 303 base::StringPrintf(kAuthorizationHeader, auth_token_.c_str())); |
336 } | 304 } |
337 profile_image_fetcher_->Start(); | 305 profile_image_fetcher_->Start(); |
338 } | 306 } |
339 | 307 |
340 void ProfileDownloader::OnOAuthError() { | |
341 LOG(WARNING) << "OnOAuthError: Fetching profile data failed"; | |
342 delegate_->OnProfileDownloadFailure( | |
343 this, ProfileDownloaderDelegate::SERVICE_ERROR); | |
344 } | |
345 | |
346 void ProfileDownloader::OnNetworkError(int response_code) { | |
347 LOG(WARNING) << "OnNetworkError: Fetching profile data failed"; | |
348 DVLOG(1) << " Response code: " << response_code; | |
349 delegate_->OnProfileDownloadFailure( | |
350 this, ProfileDownloaderDelegate::NETWORK_ERROR); | |
351 } | |
352 | |
353 void ProfileDownloader::OnURLFetchComplete(const net::URLFetcher* source) { | 308 void ProfileDownloader::OnURLFetchComplete(const net::URLFetcher* source) { |
354 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 309 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
355 std::string data; | 310 std::string data; |
356 source->GetResponseAsString(&data); | 311 source->GetResponseAsString(&data); |
357 bool network_error = | 312 bool network_error = |
358 source->GetStatus().status() != net::URLRequestStatus::SUCCESS; | 313 source->GetStatus().status() != net::URLRequestStatus::SUCCESS; |
359 if (network_error || source->GetResponseCode() != 200) { | 314 if (network_error || source->GetResponseCode() != 200) { |
Mike Lerman
2015/04/20 13:25:22
We should include automatic retry with exponential
anthonyvd
2015/04/29 15:15:08
RE: automatic retry: What's the desired behavior o
Mike Lerman
2015/04/30 19:09:07
Don't call OnProfileDownloadFailure - that means a
anthonyvd
2015/05/01 19:16:33
Awesome. I suggest doing it in a follow up CL sinc
| |
360 LOG(WARNING) << "Fetching profile data failed"; | 315 LOG(WARNING) << "Fetching profile data failed"; |
361 DVLOG(1) << " Status: " << source->GetStatus().status(); | 316 DVLOG(1) << " Status: " << source->GetStatus().status(); |
362 DVLOG(1) << " Error: " << source->GetStatus().error(); | 317 DVLOG(1) << " Error: " << source->GetStatus().error(); |
363 DVLOG(1) << " Response code: " << source->GetResponseCode(); | 318 DVLOG(1) << " Response code: " << source->GetResponseCode(); |
364 DVLOG(1) << " Url: " << source->GetURL().spec(); | 319 DVLOG(1) << " Url: " << source->GetURL().spec(); |
365 delegate_->OnProfileDownloadFailure(this, network_error ? | 320 delegate_->OnProfileDownloadFailure(this, network_error ? |
366 ProfileDownloaderDelegate::NETWORK_ERROR : | 321 ProfileDownloaderDelegate::NETWORK_ERROR : |
367 ProfileDownloaderDelegate::SERVICE_ERROR); | 322 ProfileDownloaderDelegate::SERVICE_ERROR); |
368 return; | 323 } else { |
324 VLOG(1) << "Decoding the image..."; | |
325 ImageDecoder::Start(this, data); | |
369 } | 326 } |
370 | 327 profile_image_fetcher_.reset(); |
Mike Lerman
2015/04/20 13:25:23
Do we need to reset() the profile_image_fetcher_ b
anthonyvd
2015/04/29 15:15:08
Can fetchers be reused? Let's say the delegate dec
Mike Lerman
2015/04/30 19:09:07
You're now always reset()ing at line 295, so now i
anthonyvd
2015/05/01 19:16:33
Right, it was just a generally useful thing to kno
| |
371 VLOG(1) << "Decoding the image..."; | |
372 ImageDecoder::Start(this, data); | |
373 } | 328 } |
374 | 329 |
375 void ProfileDownloader::OnImageDecoded(const SkBitmap& decoded_image) { | 330 void ProfileDownloader::OnImageDecoded(const SkBitmap& decoded_image) { |
376 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 331 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
377 int image_size = delegate_->GetDesiredImageSideLength(); | 332 int image_size = delegate_->GetDesiredImageSideLength(); |
378 profile_picture_ = skia::ImageOperations::Resize( | 333 profile_picture_ = skia::ImageOperations::Resize( |
379 decoded_image, | 334 decoded_image, |
380 skia::ImageOperations::RESIZE_BEST, | 335 skia::ImageOperations::RESIZE_BEST, |
381 image_size, | 336 image_size, |
382 image_size); | 337 image_size); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
417 void ProfileDownloader::OnGetTokenFailure( | 372 void ProfileDownloader::OnGetTokenFailure( |
418 const OAuth2TokenService::Request* request, | 373 const OAuth2TokenService::Request* request, |
419 const GoogleServiceAuthError& error) { | 374 const GoogleServiceAuthError& error) { |
420 DCHECK_EQ(request, oauth2_access_token_request_.get()); | 375 DCHECK_EQ(request, oauth2_access_token_request_.get()); |
421 oauth2_access_token_request_.reset(); | 376 oauth2_access_token_request_.reset(); |
422 LOG(WARNING) << "ProfileDownloader: token request using refresh token failed:" | 377 LOG(WARNING) << "ProfileDownloader: token request using refresh token failed:" |
423 << error.ToString(); | 378 << error.ToString(); |
424 delegate_->OnProfileDownloadFailure( | 379 delegate_->OnProfileDownloadFailure( |
425 this, ProfileDownloaderDelegate::TOKEN_ERROR); | 380 this, ProfileDownloaderDelegate::TOKEN_ERROR); |
426 } | 381 } |
382 | |
383 void ProfileDownloader::OnAccountUpdated( | |
384 const AccountTrackerService::AccountInfo& info) { | |
385 if (info.account_id == account_id_ && info.IsValid()) { | |
386 account_tracker_service_->RemoveObserver(this); | |
387 account_info_ = info; | |
388 FetchImageData(account_info_.picture_url); | |
Mike Lerman
2015/04/20 13:25:23
How do we know the Access Token is valid when Fetc
Roger Tawa OOO till Jul 10th
2015/04/21 14:00:34
I think this CL needs to turn the order of operati
anthonyvd
2015/04/29 15:15:08
The last part of that comment seems to have been c
| |
389 } | |
390 } | |
391 | |
392 void ProfileDownloader::OnAccountUpdateFailed(const std::string& account_id) { | |
393 if (account_id == account_id_) { | |
394 account_tracker_service_->RemoveObserver(this); | |
395 delegate_->OnProfileDownloadFailure( | |
396 this, ProfileDownloaderDelegate::SERVICE_ERROR); | |
397 } | |
398 } | |
OLD | NEW |