| 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));
|
|
|