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

Side by Side Diff: chrome/browser/chromeos/login/profile_image_downloader.cc

Issue 8399005: [cros] Don't succeed if user has default profile picturewq (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed stats for change picture options Created 9 years, 1 month 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
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/chromeos/login/profile_image_downloader.h" 5 #include "chrome/browser/chromeos/login/profile_image_downloader.h"
6 6
7 #include <string>
7 #include <vector> 8 #include <vector>
8 9
9 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
10 #include "base/logging.h" 11 #include "base/logging.h"
11 #include "base/message_loop.h" 12 #include "base/message_loop.h"
13 #include "base/string_split.h"
12 #include "base/string_util.h" 14 #include "base/string_util.h"
13 #include "base/stringprintf.h" 15 #include "base/stringprintf.h"
14 #include "chrome/browser/chromeos/login/helper.h" 16 #include "chrome/browser/chromeos/login/helper.h"
15 #include "chrome/browser/chromeos/login/user_manager.h" 17 #include "chrome/browser/chromeos/login/user_manager.h"
16 #include "chrome/browser/net/gaia/token_service.h" 18 #include "chrome/browser/net/gaia/token_service.h"
17 #include "chrome/browser/profiles/profile_manager.h" 19 #include "chrome/browser/profiles/profile_manager.h"
18 #include "chrome/common/chrome_notification_types.h" 20 #include "chrome/common/chrome_notification_types.h"
19 #include "chrome/common/net/gaia/gaia_constants.h" 21 #include "chrome/common/net/gaia/gaia_constants.h"
20 #include "content/browser/browser_thread.h" 22 #include "content/browser/browser_thread.h"
21 #include "content/public/browser/notification_details.h" 23 #include "content/public/browser/notification_details.h"
(...skipping 15 matching lines...) Expand all
37 // URL requesting Picasa API for user info. 39 // URL requesting Picasa API for user info.
38 const char kUserEntryURL[] = 40 const char kUserEntryURL[] =
39 "http://picasaweb.google.com/data/entry/api/user/default?alt=json"; 41 "http://picasaweb.google.com/data/entry/api/user/default?alt=json";
40 // Path in JSON dictionary to user's photo thumbnail URL. 42 // Path in JSON dictionary to user's photo thumbnail URL.
41 const char kPhotoThumbnailURLPath[] = "entry.gphoto$thumbnail.$t"; 43 const char kPhotoThumbnailURLPath[] = "entry.gphoto$thumbnail.$t";
42 // Path format for specifying thumbnail's size. 44 // Path format for specifying thumbnail's size.
43 const char kThumbnailSizeFormat[] = "s%d-c"; 45 const char kThumbnailSizeFormat[] = "s%d-c";
44 // Default Picasa thumbnail size. 46 // Default Picasa thumbnail size.
45 const int kDefaultThumbnailSize = 64; 47 const int kDefaultThumbnailSize = 64;
46 48
49 // Separator of URL path components.
50 const char kURLPathSeparator = '/';
51
52 // Photo ID of old low-res default profile picture (base64 of 0).
53 const char kOldDefaultPhotoId[] = "AAAAAAAAAAA";
54
55 // Current photo ID of the current profile picture (base64 of 2).
56 const char kDefaultPhotoId[] = "AAAAAAAAAAI";
57
58 // Photo version of the current profile picture (base64 of 0).
59 const char kDefaultPhotoVersion[] = "AAAAAAAAAAA";
60
61 // Number of path components in profile picture URL.
62 const size_t kProfileImageURLPathComponentsCount = 7;
63
64 // Index of path component with photo ID.
65 const int kPhotoIdPathComponentIndex = 2;
66
67 // Index of path component with photo version.
68 const int kPhotoVersionPathComponentIndex = 3;
69
47 } // namespace 70 } // namespace
48 71
49 std::string ProfileImageDownloader::GetProfileImageURL( 72 std::string ProfileImageDownloader::GetProfileImageURL(
50 const std::string& data) const { 73 const std::string& data) const {
51 int error_code = -1; 74 int error_code = -1;
52 std::string error_message; 75 std::string error_message;
53 scoped_ptr<base::Value> root_value(base::JSONReader::ReadAndReturnError( 76 scoped_ptr<base::Value> root_value(base::JSONReader::ReadAndReturnError(
54 data, false, &error_code, &error_message)); 77 data, false, &error_code, &error_message));
55 if (!root_value.get()) { 78 if (!root_value.get()) {
56 LOG(ERROR) << "Error while parsing Picasa user entry response: " 79 LOG(ERROR) << "Error while parsing Picasa user entry response: "
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 } 121 }
99 122
100 GURL thumbnail_url(thumbnail_url_string); 123 GURL thumbnail_url(thumbnail_url_string);
101 if (!thumbnail_url.is_valid()) { 124 if (!thumbnail_url.is_valid()) {
102 LOG(ERROR) << "Thumbnail URL is not valid: " << thumbnail_url_string; 125 LOG(ERROR) << "Thumbnail URL is not valid: " << thumbnail_url_string;
103 return std::string(); 126 return std::string();
104 } 127 }
105 return thumbnail_url.spec(); 128 return thumbnail_url.spec();
106 } 129 }
107 130
131 bool ProfileImageDownloader::IsDefaultProfileImageURL(
132 const std::string& url) const {
133
134 GURL image_url_object(url);
135 DCHECK(image_url_object.is_valid());
136 VLOG(1) << "URL to check for default image: " << image_url_object.spec();
137 std::vector<std::string> path_components;
138 base::SplitString(image_url_object.path(),
139 kURLPathSeparator,
140 &path_components);
141
142 if (path_components.size() != kProfileImageURLPathComponentsCount)
143 return false;
144
145 const std::string& photo_id = path_components[kPhotoIdPathComponentIndex];
146 const std::string& photo_version =
147 path_components[kPhotoVersionPathComponentIndex];
148 return (photo_id == kOldDefaultPhotoId) ||
149 (photo_id == kDefaultPhotoId &&
150 photo_version == kDefaultPhotoVersion);
151 }
152
108 ProfileImageDownloader::ProfileImageDownloader(Delegate* delegate) 153 ProfileImageDownloader::ProfileImageDownloader(Delegate* delegate)
109 : delegate_(delegate) { 154 : delegate_(delegate) {
110 } 155 }
111 156
112 void ProfileImageDownloader::Start() { 157 void ProfileImageDownloader::Start() {
113 VLOG(1) << "Starting profile image downloader..."; 158 VLOG(1) << "Starting profile image downloader...";
114 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 159 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
115 160
116 TokenService* service = 161 TokenService* service =
117 ProfileManager::GetDefaultProfile()->GetTokenService(); 162 ProfileManager::GetDefaultProfile()->GetTokenService();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 return; 213 return;
169 } 214 }
170 215
171 if (source == user_entry_fetcher_.get()) { 216 if (source == user_entry_fetcher_.get()) {
172 std::string image_url = GetProfileImageURL(data); 217 std::string image_url = GetProfileImageURL(data);
173 if (image_url.empty()) { 218 if (image_url.empty()) {
174 if (delegate_) 219 if (delegate_)
175 delegate_->OnDownloadFailure(); 220 delegate_->OnDownloadFailure();
176 return; 221 return;
177 } 222 }
223 if (IsDefaultProfileImageURL(image_url)) {
224 if (delegate_)
225 delegate_->OnDownloadDefaultImage();
226 return;
227 }
178 VLOG(1) << "Fetching profile image from " << image_url; 228 VLOG(1) << "Fetching profile image from " << image_url;
179 profile_image_fetcher_.reset(content::URLFetcher::Create( 229 profile_image_fetcher_.reset(content::URLFetcher::Create(
180 GURL(image_url), content::URLFetcher::GET, this)); 230 GURL(image_url), content::URLFetcher::GET, this));
181 profile_image_fetcher_->SetRequestContext( 231 profile_image_fetcher_->SetRequestContext(
182 ProfileManager::GetDefaultProfile()->GetRequestContext()); 232 ProfileManager::GetDefaultProfile()->GetRequestContext());
183 if (!auth_token_.empty()) { 233 if (!auth_token_.empty()) {
184 profile_image_fetcher_->SetExtraRequestHeaders( 234 profile_image_fetcher_->SetExtraRequestHeaders(
185 base::StringPrintf(kAuthorizationHeader, auth_token_.c_str())); 235 base::StringPrintf(kAuthorizationHeader, auth_token_.c_str()));
186 } 236 }
187 profile_image_fetcher_->Start(); 237 profile_image_fetcher_->Start();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 } else { 279 } else {
230 if (token_details->service() == GaiaConstants::kPicasaService) { 280 if (token_details->service() == GaiaConstants::kPicasaService) {
231 LOG(WARNING) << "ProfileImageDownloader: token request failed"; 281 LOG(WARNING) << "ProfileImageDownloader: token request failed";
232 if (delegate_) 282 if (delegate_)
233 delegate_->OnDownloadFailure(); 283 delegate_->OnDownloadFailure();
234 } 284 }
235 } 285 }
236 } 286 }
237 287
238 } // namespace chromeos 288 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/profile_image_downloader.h ('k') | chrome/browser/chromeos/login/user_image_screen.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698