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

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

Issue 8801023: Fix detection of default G+ profile picture (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 9 years 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/profiles/profile_downloader_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 // Check that the ID and version match the default Picasa profile photo.
196 // the default Google+ profile photo and the default Picasa profile photo. 190 return photo_id == kPicasaPhotoId &&
197 return ((photo_id == kPicasaPhotoId && 191 photo_version == kDefaultPicasaPhotoVersion;
198 photo_version == kDefaultPicasaPhotoVersion) ||
199 (photo_id == kGooglePlusPhotoId &&
200 photo_version == kDefaultGooglePlusPhotoVersion));
201 } 192 }
202 193
203 ProfileDownloader::ProfileDownloader(ProfileDownloaderDelegate* delegate) 194 ProfileDownloader::ProfileDownloader(ProfileDownloaderDelegate* delegate)
204 : delegate_(delegate), 195 : delegate_(delegate),
205 picture_status_(PICTURE_FAILED) { 196 picture_status_(PICTURE_FAILED) {
206 DCHECK(delegate_); 197 DCHECK(delegate_);
207 } 198 }
208 199
209 void ProfileDownloader::Start() { 200 void ProfileDownloader::Start() {
210 VLOG(1) << "Starting profile downloader..."; 201 VLOG(1) << "Starting profile downloader...";
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 void ProfileDownloader::OnGetTokenSuccess(const std::string& access_token) { 366 void ProfileDownloader::OnGetTokenSuccess(const std::string& access_token) {
376 auth_token_ = access_token; 367 auth_token_ = access_token;
377 StartFetchingImage(); 368 StartFetchingImage();
378 } 369 }
379 370
380 // Callback for OAuth2AccessTokenFetcher on failure. 371 // Callback for OAuth2AccessTokenFetcher on failure.
381 void ProfileDownloader::OnGetTokenFailure(const GoogleServiceAuthError& error) { 372 void ProfileDownloader::OnGetTokenFailure(const GoogleServiceAuthError& error) {
382 LOG(WARNING) << "ProfileDownloader: token request using refresh token failed"; 373 LOG(WARNING) << "ProfileDownloader: token request using refresh token failed";
383 delegate_->OnDownloadComplete(this, false); 374 delegate_->OnDownloadComplete(this, false);
384 } 375 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/profiles/profile_downloader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698