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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
57 | 57 |
58 // Separator of URL path components. | 58 // Separator of URL path components. |
59 const char kURLPathSeparator = '/'; | 59 const char kURLPathSeparator = '/'; |
60 | 60 |
61 // Photo ID of the Picasa Web Albums profile picture (base64 of 0). | 61 // Photo ID of the Picasa Web Albums profile picture (base64 of 0). |
62 const char kPicasaPhotoId[] = "AAAAAAAAAAA"; | 62 const char kPicasaPhotoId[] = "AAAAAAAAAAA"; |
63 | 63 |
64 // Photo version of the default PWA profile picture (base64 of 1). | 64 // Photo version of the default PWA profile picture (base64 of 1). |
65 const char kDefaultPicasaPhotoVersion[] = "AAAAAAAAAAE"; | 65 const char kDefaultPicasaPhotoVersion[] = "AAAAAAAAAAE"; |
66 | 66 |
67 // Photo ID of the Google+ profile picture (base64 of 2). | |
68 const char kGooglePlusPhotoId[] = "AAAAAAAAAAI"; | |
69 | |
70 // Photo version of the default Google+ profile picture (base64 of 0). | |
71 const char kDefaultGooglePlusPhotoVersion[] = "AAAAAAAAAAA"; | |
72 | |
73 // The minimum number of path components in profile picture URL. | 67 // The minimum number of path components in profile picture URL. |
74 const size_t kProfileImageURLPathComponentsCount = 6; | 68 const size_t kProfileImageURLPathComponentsCount = 6; |
75 | 69 |
76 // Index of path component with photo ID. | 70 // Index of path component with photo ID. |
77 const int kPhotoIdPathComponentIndex = 2; | 71 const int kPhotoIdPathComponentIndex = 2; |
78 | 72 |
79 // Index of path component with photo version. | 73 // Index of path component with photo version. |
80 const int kPhotoVersionPathComponentIndex = 3; | 74 const int kPhotoVersionPathComponentIndex = 3; |
81 | 75 |
82 // Given an image URL this function builds a new URL set to |size|. | 76 // Given an image URL this function builds a new URL set to |size|. |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
185 kURLPathSeparator, | 179 kURLPathSeparator, |
186 &path_components); | 180 &path_components); |
187 | 181 |
188 if (path_components.size() < kProfileImageURLPathComponentsCount) | 182 if (path_components.size() < kProfileImageURLPathComponentsCount) |
189 return false; | 183 return false; |
190 | 184 |
191 const std::string& photo_id = path_components[kPhotoIdPathComponentIndex]; | 185 const std::string& photo_id = path_components[kPhotoIdPathComponentIndex]; |
192 const std::string& photo_version = | 186 const std::string& photo_version = |
193 path_components[kPhotoVersionPathComponentIndex]; | 187 path_components[kPhotoVersionPathComponentIndex]; |
194 | 188 |
195 // There are at least two pairs of (ID, version) for the default photo: | 189 // There are at least two pairs of (ID, version) for the default photo: |
Ivan Korotkov
2011/12/06 08:51:12
Please fix this comment to match the code.
sail
2011/12/06 18:28:15
Done.
| |
196 // the default Google+ profile photo and the default Picasa profile photo. | 190 // the default Google+ profile photo and the default Picasa profile photo. |
197 return ((photo_id == kPicasaPhotoId && | 191 return photo_id == kPicasaPhotoId && |
198 photo_version == kDefaultPicasaPhotoVersion) || | 192 photo_version == kDefaultPicasaPhotoVersion; |
199 (photo_id == kGooglePlusPhotoId && | |
200 photo_version == kDefaultGooglePlusPhotoVersion)); | |
201 } | 193 } |
202 | 194 |
203 ProfileDownloader::ProfileDownloader(ProfileDownloaderDelegate* delegate) | 195 ProfileDownloader::ProfileDownloader(ProfileDownloaderDelegate* delegate) |
204 : delegate_(delegate), | 196 : delegate_(delegate), |
205 picture_status_(PICTURE_FAILED) { | 197 picture_status_(PICTURE_FAILED) { |
206 DCHECK(delegate_); | 198 DCHECK(delegate_); |
207 } | 199 } |
208 | 200 |
209 void ProfileDownloader::Start() { | 201 void ProfileDownloader::Start() { |
210 VLOG(1) << "Starting profile downloader..."; | 202 VLOG(1) << "Starting profile downloader..."; |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
375 void ProfileDownloader::OnGetTokenSuccess(const std::string& access_token) { | 367 void ProfileDownloader::OnGetTokenSuccess(const std::string& access_token) { |
376 auth_token_ = access_token; | 368 auth_token_ = access_token; |
377 StartFetchingImage(); | 369 StartFetchingImage(); |
378 } | 370 } |
379 | 371 |
380 // Callback for OAuth2AccessTokenFetcher on failure. | 372 // Callback for OAuth2AccessTokenFetcher on failure. |
381 void ProfileDownloader::OnGetTokenFailure(const GoogleServiceAuthError& error) { | 373 void ProfileDownloader::OnGetTokenFailure(const GoogleServiceAuthError& error) { |
382 LOG(WARNING) << "ProfileDownloader: token request using refresh token failed"; | 374 LOG(WARNING) << "ProfileDownloader: token request using refresh token failed"; |
383 delegate_->OnDownloadComplete(this, false); | 375 delegate_->OnDownloadComplete(this, false); |
384 } | 376 } |
OLD | NEW |