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

Unified Diff: chrome/browser/chromeos/login/profile_image_downloader.cc

Issue 8497006: Merge 107584 - [cros] Don't succeed if user has default profile picture. Merge 108860 - [cros] Fi... (Closed) Base URL: svn://svn.chromium.org/chrome/branches/912/src/
Patch Set: '' 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/login/profile_image_downloader.cc
===================================================================
--- chrome/browser/chromeos/login/profile_image_downloader.cc (revision 108979)
+++ chrome/browser/chromeos/login/profile_image_downloader.cc (working copy)
@@ -4,11 +4,13 @@
#include "chrome/browser/chromeos/login/profile_image_downloader.h"
+#include <string>
#include <vector>
#include "base/json/json_reader.h"
#include "base/logging.h"
#include "base/message_loop.h"
+#include "base/string_split.h"
#include "base/string_util.h"
#include "base/stringprintf.h"
#include "chrome/browser/chromeos/login/helper.h"
@@ -43,6 +45,30 @@
// Default Picasa thumbnail size.
const int kDefaultThumbnailSize = 64;
+// Separator of URL path components.
+const char kURLPathSeparator = '/';
+
+// Photo ID of the Picasa Web Albums profile picture (base64 of 0).
+const char kPicasaPhotoId[] = "AAAAAAAAAAA";
+
+// Photo version of the default PWA profile picture (base64 of 1).
+const char kDefaultPicasaPhotoVersion[] = "AAAAAAAAAAE";
+
+// Photo ID of the Google+ profile picture (base64 of 2).
+const char kGooglePlusPhotoId[] = "AAAAAAAAAAI";
+
+// Photo version of the default Google+ profile picture (base64 of 0).
+const char kDefaultGooglePlusPhotoVersion[] = "AAAAAAAAAAA";
+
+// Number of path components in profile picture URL.
+const size_t kProfileImageURLPathComponentsCount = 7;
+
+// Index of path component with photo ID.
+const int kPhotoIdPathComponentIndex = 2;
+
+// Index of path component with photo version.
+const int kPhotoVersionPathComponentIndex = 3;
+
} // namespace
std::string ProfileImageDownloader::GetProfileImageURL(
@@ -104,6 +130,32 @@
return thumbnail_url.spec();
}
+bool ProfileImageDownloader::IsDefaultProfileImageURL(
+ const std::string& url) const {
+
+ GURL image_url_object(url);
+ DCHECK(image_url_object.is_valid());
+ VLOG(1) << "URL to check for default image: " << image_url_object.spec();
+ std::vector<std::string> path_components;
+ base::SplitString(image_url_object.path(),
+ kURLPathSeparator,
+ &path_components);
+
+ if (path_components.size() != kProfileImageURLPathComponentsCount)
+ return false;
+
+ const std::string& photo_id = path_components[kPhotoIdPathComponentIndex];
+ const std::string& photo_version =
+ path_components[kPhotoVersionPathComponentIndex];
+
+ // There are at least two pairs of (ID, version) for the default photo:
+ // the default Google+ profile photo and the default Picasa profile photo.
+ return ((photo_id == kPicasaPhotoId &&
+ photo_version == kDefaultPicasaPhotoVersion) ||
+ (photo_id == kGooglePlusPhotoId &&
+ photo_version == kDefaultGooglePlusPhotoVersion));
+}
+
ProfileImageDownloader::ProfileImageDownloader(Delegate* delegate)
: delegate_(delegate) {
}
@@ -174,6 +226,11 @@
delegate_->OnDownloadFailure();
return;
}
+ if (IsDefaultProfileImageURL(image_url)) {
+ if (delegate_)
+ delegate_->OnDownloadDefaultImage();
+ return;
+ }
VLOG(1) << "Fetching profile image from " << image_url;
profile_image_fetcher_.reset(
new URLFetcher(GURL(image_url), URLFetcher::GET, this));
« 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