| 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/chromeos/login/profile_image_downloader.h" | 5 #include "chrome/browser/chromeos/login/profile_image_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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 // Path in JSON dictionary to user's photo thumbnail URL. | 44 // Path in JSON dictionary to user's photo thumbnail URL. |
| 45 const char kPhotoThumbnailURLPath[] = "entry.gphoto$thumbnail.$t"; | 45 const char kPhotoThumbnailURLPath[] = "entry.gphoto$thumbnail.$t"; |
| 46 // Path format for specifying thumbnail's size. | 46 // Path format for specifying thumbnail's size. |
| 47 const char kThumbnailSizeFormat[] = "s%d-c"; | 47 const char kThumbnailSizeFormat[] = "s%d-c"; |
| 48 // Default Picasa thumbnail size. | 48 // Default Picasa thumbnail size. |
| 49 const int kDefaultThumbnailSize = 64; | 49 const int kDefaultThumbnailSize = 64; |
| 50 | 50 |
| 51 // Separator of URL path components. | 51 // Separator of URL path components. |
| 52 const char kURLPathSeparator = '/'; | 52 const char kURLPathSeparator = '/'; |
| 53 | 53 |
| 54 // Photo ID of old low-res default profile picture (base64 of 0). | 54 // Photo ID of the Picasa Web Albums profile picture (base64 of 0). |
| 55 const char kOldDefaultPhotoId[] = "AAAAAAAAAAA"; | 55 const char kPicasaPhotoId[] = "AAAAAAAAAAA"; |
| 56 | 56 |
| 57 // Current photo ID of the current profile picture (base64 of 2). | 57 // Photo version of the default PWA profile picture (base64 of 1). |
| 58 const char kDefaultPhotoId[] = "AAAAAAAAAAI"; | 58 const char kDefaultPicasaPhotoVersion[] = "AAAAAAAAAAE"; |
| 59 | 59 |
| 60 // Photo version of the current profile picture (base64 of 0). | 60 // Photo ID of the Google+ profile picture (base64 of 2). |
| 61 const char kDefaultPhotoVersion[] = "AAAAAAAAAAA"; | 61 const char kGooglePlusPhotoId[] = "AAAAAAAAAAI"; |
| 62 |
| 63 // Photo version of the default Google+ profile picture (base64 of 0). |
| 64 const char kDefaultGooglePlusPhotoVersion[] = "AAAAAAAAAAA"; |
| 62 | 65 |
| 63 // Number of path components in profile picture URL. | 66 // Number of path components in profile picture URL. |
| 64 const size_t kProfileImageURLPathComponentsCount = 7; | 67 const size_t kProfileImageURLPathComponentsCount = 7; |
| 65 | 68 |
| 66 // Index of path component with photo ID. | 69 // Index of path component with photo ID. |
| 67 const int kPhotoIdPathComponentIndex = 2; | 70 const int kPhotoIdPathComponentIndex = 2; |
| 68 | 71 |
| 69 // Index of path component with photo version. | 72 // Index of path component with photo version. |
| 70 const int kPhotoVersionPathComponentIndex = 3; | 73 const int kPhotoVersionPathComponentIndex = 3; |
| 71 | 74 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 base::SplitString(image_url_object.path(), | 143 base::SplitString(image_url_object.path(), |
| 141 kURLPathSeparator, | 144 kURLPathSeparator, |
| 142 &path_components); | 145 &path_components); |
| 143 | 146 |
| 144 if (path_components.size() != kProfileImageURLPathComponentsCount) | 147 if (path_components.size() != kProfileImageURLPathComponentsCount) |
| 145 return false; | 148 return false; |
| 146 | 149 |
| 147 const std::string& photo_id = path_components[kPhotoIdPathComponentIndex]; | 150 const std::string& photo_id = path_components[kPhotoIdPathComponentIndex]; |
| 148 const std::string& photo_version = | 151 const std::string& photo_version = |
| 149 path_components[kPhotoVersionPathComponentIndex]; | 152 path_components[kPhotoVersionPathComponentIndex]; |
| 150 return (photo_id == kOldDefaultPhotoId) || | 153 |
| 151 (photo_id == kDefaultPhotoId && | 154 // There are at least two pairs of (ID, version) for the default photo: |
| 152 photo_version == kDefaultPhotoVersion); | 155 // the default Google+ profile photo and the default Picasa profile photo. |
| 156 return ((photo_id == kPicasaPhotoId && |
| 157 photo_version == kDefaultPicasaPhotoVersion) || |
| 158 (photo_id == kGooglePlusPhotoId && |
| 159 photo_version == kDefaultGooglePlusPhotoVersion)); |
| 153 } | 160 } |
| 154 | 161 |
| 155 ProfileImageDownloader::ProfileImageDownloader(Delegate* delegate) | 162 ProfileImageDownloader::ProfileImageDownloader(Delegate* delegate) |
| 156 : delegate_(delegate) { | 163 : delegate_(delegate) { |
| 157 } | 164 } |
| 158 | 165 |
| 159 void ProfileImageDownloader::Start() { | 166 void ProfileImageDownloader::Start() { |
| 160 VLOG(1) << "Starting profile image downloader..."; | 167 VLOG(1) << "Starting profile image downloader..."; |
| 161 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 168 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 162 | 169 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 } else { | 288 } else { |
| 282 if (token_details->service() == GaiaConstants::kPicasaService) { | 289 if (token_details->service() == GaiaConstants::kPicasaService) { |
| 283 LOG(WARNING) << "ProfileImageDownloader: token request failed"; | 290 LOG(WARNING) << "ProfileImageDownloader: token request failed"; |
| 284 if (delegate_) | 291 if (delegate_) |
| 285 delegate_->OnDownloadFailure(); | 292 delegate_->OnDownloadFailure(); |
| 286 } | 293 } |
| 287 } | 294 } |
| 288 } | 295 } |
| 289 | 296 |
| 290 } // namespace chromeos | 297 } // namespace chromeos |
| OLD | NEW |