Commit 6d33da17 authored by sail@chromium.org's avatar sail@chromium.org

Make ProfileImageDownloader available to non-chromeos code

BUG=91241
TEST=


Review URL: http://codereview.chromium.org/8510069

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111098 0039d316-1c4b-4281-b951-d872f2087c98
parent 0de5d860
......@@ -8,7 +8,7 @@
#include <string>
#include "chrome/browser/chromeos/login/image_decoder.h"
#include "chrome/browser/image_decoder.h"
#include "googleurl/src/gurl.h"
#include "ui/views/window/dialog_delegate.h"
#include "views/controls/button/button.h"
......
......@@ -10,7 +10,7 @@
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/chromeos/login/image_decoder.h"
#include "chrome/browser/image_decoder.h"
#include "content/public/common/url_fetcher_delegate.h"
#include "googleurl/src/gurl.h"
......
......@@ -30,6 +30,7 @@
#include "chrome/common/net/gaia/gaia_auth_consumer.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_pref_service.h"
#include "content/public/common/url_fetcher_delegate.h"
#include "content/test/test_browser_thread.h"
#include "content/test/test_url_fetcher_factory.h"
#include "net/url_request/url_request.h"
......
......@@ -9,7 +9,6 @@
#include "base/file_util.h"
#include "base/message_loop.h"
#include "chrome/browser/chromeos/login/helper.h"
#include "chrome/browser/chromeos/login/image_decoder.h"
#include "content/public/browser/browser_thread.h"
#include "skia/ext/image_operations.h"
#include "third_party/skia/include/core/SkBitmap.h"
......
......@@ -11,7 +11,7 @@
#include "base/callback.h"
#include "base/memory/ref_counted.h"
#include "chrome/browser/chromeos/login/image_decoder.h"
#include "chrome/browser/image_decoder.h"
class MessageLoop;
class SkBitmap;
......
......@@ -36,6 +36,8 @@
#include "chrome/browser/defaults.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/prefs/scoped_user_pref_update.h"
#include "chrome/browser/profiles/profile_downloader.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/webui/web_ui_util.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_paths.h"
......@@ -85,6 +87,17 @@ const long kProfileImageDownloadDelayMs = 10000;
base::LazyInstance<UserManager> g_user_manager = LAZY_INSTANCE_INITIALIZER;
// Enum for reporting histograms about profile picture download.
enum ProfileDownloadResult {
kDownloadSuccessChanged,
kDownloadSuccess,
kDownloadFailure,
kDownloadDefault,
// Must be the last, convenient count.
kDownloadResultsCount
};
// Used to handle the asynchronous response of deleting a cryptohome directory.
class RemoveAttempt : public CryptohomeLibrary::Delegate {
public:
......@@ -454,7 +467,13 @@ void UserManager::DownloadProfileImage() {
// Another download is already in progress
return;
}
profile_image_downloader_.reset(new ProfileImageDownloader(this));
if (logged_in_user().email().empty()) {
// This is a guest login so there's no profile image to download.
return;
}
profile_image_downloader_.reset(new ProfileDownloader(this));
profile_image_downloader_->Start();
profile_image_load_start_time_ = base::Time::Now();
}
......@@ -789,20 +808,36 @@ void UserManager::CheckOwnership() {
is_owner));
}
void UserManager::OnDownloadSuccess(const SkBitmap& image) {
VLOG(1) << "Downloaded profile image for logged-in user.";
UMA_HISTOGRAM_ENUMERATION("UserImageDownloadResult.LoggedIn",
ProfileImageDownloader::kDownloadSuccess,
ProfileImageDownloader::kDownloadResultsCount);
int UserManager::GetDesiredImageSideLength() {
return login::kUserImageSize;
}
Profile* UserManager::GetBrowserProfile() {
return ProfileManager::GetDefaultProfile();
}
void UserManager::OnDownloadComplete(ProfileDownloader* downloader,
bool success) {
ProfileDownloadResult result;
if (!success)
result = kDownloadFailure;
else if (downloader->GetProfilePicture().isNull())
result = kDownloadDefault;
else
result = kDownloadSuccess;
UMA_HISTOGRAM_ENUMERATION("UserImage.ProfileDownloadResult",
result, kDownloadResultsCount);
if (result == kDownloadSuccess) {
// Check if this image is not the same as already downloaded.
std::string new_image_data_url = web_ui_util::GetImageDataUrl(image);
std::string new_image_data_url =
web_ui_util::GetImageDataUrl(downloader->GetProfilePicture());
if (!downloaded_profile_image_data_url_.empty() &&
new_image_data_url == downloaded_profile_image_data_url_)
return;
downloaded_profile_image_data_url_ = new_image_data_url;
downloaded_profile_image_ = image;
downloaded_profile_image_ = downloader->GetProfilePicture();
if (logged_in_user().image_index() == User::kProfileImageIndex) {
std::string current_image_data_url =
......@@ -811,43 +846,27 @@ void UserManager::OnDownloadSuccess(const SkBitmap& image) {
return;
VLOG(1) << "Updating profile image for logged-in user";
UMA_HISTOGRAM_ENUMERATION("UserImageDownloadResult.LoggedIn",
ProfileImageDownloader::kDownloadSuccessChanged,
ProfileImageDownloader::kDownloadResultsCount);
UMA_HISTOGRAM_ENUMERATION("UserImage.ProfileDownloadResult",
kDownloadSuccessChanged,
kDownloadResultsCount);
// This will persist |downloaded_profile_image_| to file.
SaveUserImageFromProfileImage(logged_in_user().email());
}
}
if (result == kDownloadSuccess) {
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_PROFILE_IMAGE_UPDATED,
content::Source<UserManager>(this),
content::Details<const SkBitmap>(&image));
profile_image_downloader_.reset();
}
void UserManager::OnDownloadFailure() {
VLOG(1) << "Download of profile image for logged-in user failed.";
UMA_HISTOGRAM_ENUMERATION("UserImageDownloadResult.LoggedIn",
ProfileImageDownloader::kDownloadFailure,
ProfileImageDownloader::kDownloadResultsCount);
content::Details<const SkBitmap>(&downloader->GetProfilePicture()));
} else {
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_PROFILE_IMAGE_UPDATE_FAILED,
content::Source<UserManager>(this),
content::NotificationService::NoDetails());
profile_image_downloader_.reset();
}
}
void UserManager::OnDownloadDefaultImage() {
VLOG(1) << "Logged-in user still has the default profile image.";
UMA_HISTOGRAM_ENUMERATION("UserImageDownloadResult.LoggedIn",
ProfileImageDownloader::kDownloadDefault,
ProfileImageDownloader::kDownloadResultsCount);
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_PROFILE_IMAGE_UPDATE_FAILED,
content::Source<UserManager>(this),
content::NotificationService::NoDetails());
profile_image_downloader_.reset();
}
......
......@@ -14,15 +14,16 @@
#include "base/observer_list.h"
#include "base/synchronization/lock.h"
#include "base/time.h"
#include "chrome/browser/chromeos/login/profile_image_downloader.h"
#include "chrome/browser/chromeos/login/user.h"
#include "chrome/browser/chromeos/login/user_image_loader.h"
#include "chrome/browser/profiles/profile_downloader_delegate.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "third_party/skia/include/core/SkBitmap.h"
class FilePath;
class PrefService;
class ProfileDownloader;
namespace base {
template<typename> struct DefaultLazyInstanceTraits;
......@@ -34,7 +35,7 @@ class RemoveUserDelegate;
// This class provides a mechanism for discovering users who have logged
// into this chromium os device before and updating that list.
class UserManager : public ProfileImageDownloader::Delegate,
class UserManager : public ProfileDownloaderDelegate,
public content::NotificationObserver {
public:
// Returns a shared instance of a UserManager. Not thread-safe, should only be
......@@ -210,10 +211,11 @@ class UserManager : public ProfileImageDownloader::Delegate,
// Checks current user's ownership on file thread.
void CheckOwnership();
// ProfileImageDownloader::Delegate implementation.
virtual void OnDownloadSuccess(const SkBitmap& image) OVERRIDE;
virtual void OnDownloadFailure() OVERRIDE;
virtual void OnDownloadDefaultImage() OVERRIDE;
// ProfileDownloaderDelegate implementation.
virtual int GetDesiredImageSideLength() OVERRIDE;
virtual Profile* GetBrowserProfile() OVERRIDE;
virtual void OnDownloadComplete(ProfileDownloader* downloader,
bool success) OVERRIDE;
// Creates a new User instance.
User* CreateUser(const std::string& email) const;
......@@ -259,7 +261,7 @@ class UserManager : public ProfileImageDownloader::Delegate,
ObserverList<Observer> observer_list_;
// Download user profile image on login to update it if it's changed.
scoped_ptr<ProfileImageDownloader> profile_image_downloader_;
scoped_ptr<ProfileDownloader> profile_image_downloader_;
// Time when the profile image download has started.
base::Time profile_image_load_start_time_;
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/chromeos/login/image_decoder.h"
#include "chrome/browser/image_decoder.h"
#include "base/bind.h"
#include "chrome/browser/browser_process.h"
......@@ -11,8 +11,6 @@
using content::BrowserThread;
namespace chromeos {
ImageDecoder::ImageDecoder(Delegate* delegate,
const std::string& image_data)
: delegate_(delegate),
......@@ -64,5 +62,3 @@ void ImageDecoder::DecodeImageInSandbox(
target_thread_id_);
utility_process_host->Send(new ChromeUtilityMsg_DecodeImage(image_data));
}
} // namespace chromeos
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_IMAGE_DECODER_H_
#define CHROME_BROWSER_CHROMEOS_LOGIN_IMAGE_DECODER_H_
#ifndef CHROME_BROWSER_IMAGE_DECODER_H_
#define CHROME_BROWSER_IMAGE_DECODER_H_
#pragma once
#include <string>
......@@ -13,8 +13,6 @@
class SkBitmap;
namespace chromeos {
// Decodes an image in a sandboxed process.
class ImageDecoder : public UtilityProcessHost::Client {
public:
......@@ -61,6 +59,4 @@ class ImageDecoder : public UtilityProcessHost::Client {
DISALLOW_COPY_AND_ASSIGN(ImageDecoder);
};
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_LOGIN_IMAGE_DECODER_H_
#endif // CHROME_BROWSER_IMAGE_DECODER_H_
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/chromeos/login/profile_image_downloader.h"
#include "chrome/browser/profiles/profile_downloader.h"
#include <string>
#include <vector>
......@@ -13,10 +13,9 @@
#include "base/string_split.h"
#include "base/string_util.h"
#include "base/stringprintf.h"
#include "chrome/browser/chromeos/login/helper.h"
#include "chrome/browser/chromeos/login/user_manager.h"
#include "chrome/browser/net/gaia/token_service.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_downloader_delegate.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/net/gaia/gaia_constants.h"
#include "content/public/browser/browser_thread.h"
......@@ -31,8 +30,6 @@
using content::BrowserThread;
namespace chromeos {
namespace {
// Template for optional authorization header.
......@@ -43,6 +40,9 @@ const char kUserEntryURL[] =
"http://picasaweb.google.com/data/entry/api/user/default?alt=json";
// Path in JSON dictionary to user's photo thumbnail URL.
const char kPhotoThumbnailURLPath[] = "entry.gphoto$thumbnail.$t";
const char kNickNamePath[] = "entry.gphoto$nickname.$t";
// Path format for specifying thumbnail's size.
const char kThumbnailSizeFormat[] = "s%d-c";
// Default Picasa thumbnail size.
......@@ -74,8 +74,14 @@ const int kPhotoVersionPathComponentIndex = 3;
} // namespace
std::string ProfileImageDownloader::GetProfileImageURL(
const std::string& data) const {
bool ProfileDownloader::GetProfileNickNameAndImageURL(const std::string& data,
string16* nick_name,
std::string* url) const {
DCHECK(nick_name);
DCHECK(url);
*nick_name = string16();
*url = std::string();
int error_code = -1;
std::string error_message;
scoped_ptr<base::Value> root_value(base::JSONReader::ReadAndReturnError(
......@@ -83,22 +89,28 @@ std::string ProfileImageDownloader::GetProfileImageURL(
if (!root_value.get()) {
LOG(ERROR) << "Error while parsing Picasa user entry response: "
<< error_message;
return std::string();
return false;
}
if (!root_value->IsType(base::Value::TYPE_DICTIONARY)) {
LOG(ERROR) << "JSON root is not a dictionary: "
<< root_value->GetType();
return std::string();
return false;
}
base::DictionaryValue* root_dictionary =
static_cast<base::DictionaryValue*>(root_value.get());
if (!root_dictionary->GetString(kNickNamePath, nick_name)) {
LOG(ERROR) << "Can't find nick name path in JSON data: "
<< data;
return false;
}
std::string thumbnail_url_string;
if (!root_dictionary->GetString(
kPhotoThumbnailURLPath, &thumbnail_url_string)) {
LOG(ERROR) << "Can't find thumbnail path in JSON data: "
<< data;
return std::string();
return false;
}
// Try to change the size of thumbnail we are going to get.
......@@ -106,8 +118,9 @@ std::string ProfileImageDownloader::GetProfileImageURL(
// http://lh0.ggpht.com/-abcd1aBCDEf/AAAA/AAA_A/abc12/s64-c/1234567890.jpg
std::string default_thumbnail_size_path_component(
base::StringPrintf(kThumbnailSizeFormat, kDefaultThumbnailSize));
int image_size = delegate_->GetDesiredImageSideLength();
std::string new_thumbnail_size_path_component(
base::StringPrintf(kThumbnailSizeFormat, login::kUserImageSize));
base::StringPrintf(kThumbnailSizeFormat, image_size));
size_t thumbnail_size_pos =
thumbnail_url_string.find(default_thumbnail_size_path_component);
if (thumbnail_size_pos != std::string::npos) {
......@@ -128,14 +141,13 @@ std::string ProfileImageDownloader::GetProfileImageURL(
GURL thumbnail_url(thumbnail_url_string);
if (!thumbnail_url.is_valid()) {
LOG(ERROR) << "Thumbnail URL is not valid: " << thumbnail_url_string;
return std::string();
return false;
}
return thumbnail_url.spec();
*url = thumbnail_url.spec();
return true;
}
bool ProfileImageDownloader::IsDefaultProfileImageURL(
const std::string& url) const {
bool ProfileDownloader::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();
......@@ -159,21 +171,20 @@ bool ProfileImageDownloader::IsDefaultProfileImageURL(
photo_version == kDefaultGooglePlusPhotoVersion));
}
ProfileImageDownloader::ProfileImageDownloader(Delegate* delegate)
ProfileDownloader::ProfileDownloader(ProfileDownloaderDelegate* delegate)
: delegate_(delegate) {
DCHECK(delegate_);
}
void ProfileImageDownloader::Start() {
VLOG(1) << "Starting profile image downloader...";
void ProfileDownloader::Start() {
VLOG(1) << "Starting profile downloader...";
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
TokenService* service =
ProfileManager::GetDefaultProfile()->GetTokenService();
TokenService* service = delegate_->GetBrowserProfile()->GetTokenService();
if (!service) {
// This can happen in some test paths.
LOG(WARNING) << "User has no token service";
if (delegate_)
delegate_->OnDownloadFailure();
delegate_->OnDownloadComplete(this, false);
return;
}
if (service->HasTokenForService(GaiaConstants::kPicasaService)) {
......@@ -190,15 +201,20 @@ void ProfileImageDownloader::Start() {
}
}
void ProfileImageDownloader::StartFetchingImage() {
std::string email = UserManager::Get()->logged_in_user().email();
if (email.empty())
return;
const string16& ProfileDownloader::GetProfileFullName() const {
return profile_full_name_;
}
const SkBitmap& ProfileDownloader::GetProfilePicture() const {
return profile_picture_;
}
void ProfileDownloader::StartFetchingImage() {
VLOG(1) << "Fetching user entry with token: " << auth_token_;
user_entry_fetcher_.reset(content::URLFetcher::Create(
GURL(kUserEntryURL), content::URLFetcher::GET, this));
user_entry_fetcher_->SetRequestContext(
ProfileManager::GetDefaultProfile()->GetRequestContext());
delegate_->GetBrowserProfile()->GetRequestContext());
if (!auth_token_.empty()) {
user_entry_fetcher_->SetExtraRequestHeaders(
base::StringPrintf(kAuthorizationHeader, auth_token_.c_str()));
......@@ -206,10 +222,9 @@ void ProfileImageDownloader::StartFetchingImage() {
user_entry_fetcher_->Start();
}
ProfileImageDownloader::~ProfileImageDownloader() {}
ProfileDownloader::~ProfileDownloader() {}
void ProfileImageDownloader::OnURLFetchComplete(
const content::URLFetcher* source) {
void ProfileDownloader::OnURLFetchComplete(const content::URLFetcher* source) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
std::string data;
source->GetResponseAsString(&data);
......@@ -217,28 +232,25 @@ void ProfileImageDownloader::OnURLFetchComplete(
LOG(ERROR) << "Response code is " << source->GetResponseCode();
LOG(ERROR) << "Url is " << source->GetURL().spec();
LOG(ERROR) << "Data is " << data;
if (delegate_)
delegate_->OnDownloadFailure();
delegate_->OnDownloadComplete(this, false);
return;
}
if (source == user_entry_fetcher_.get()) {
std::string image_url = GetProfileImageURL(data);
if (image_url.empty()) {
if (delegate_)
delegate_->OnDownloadFailure();
std::string image_url;
if (!GetProfileNickNameAndImageURL(data, &profile_full_name_, &image_url)) {
delegate_->OnDownloadComplete(this, false);
return;
}
if (IsDefaultProfileImageURL(image_url)) {
if (delegate_)
delegate_->OnDownloadDefaultImage();
delegate_->OnDownloadComplete(this, true);
return;
}
VLOG(1) << "Fetching profile image from " << image_url;
profile_image_fetcher_.reset(content::URLFetcher::Create(
GURL(image_url), content::URLFetcher::GET, this));
profile_image_fetcher_->SetRequestContext(
ProfileManager::GetDefaultProfile()->GetRequestContext());
delegate_->GetBrowserProfile()->GetRequestContext());
if (!auth_token_.empty()) {
profile_image_fetcher_->SetExtraRequestHeaders(
base::StringPrintf(kAuthorizationHeader, auth_token_.c_str()));
......@@ -252,25 +264,24 @@ void ProfileImageDownloader::OnURLFetchComplete(
}
}
void ProfileImageDownloader::OnImageDecoded(const ImageDecoder* decoder,
void ProfileDownloader::OnImageDecoded(const ImageDecoder* decoder,
const SkBitmap& decoded_image) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
SkBitmap resized_image = skia::ImageOperations::Resize(
int image_size = delegate_->GetDesiredImageSideLength();
profile_picture_ = skia::ImageOperations::Resize(
decoded_image,
skia::ImageOperations::RESIZE_BEST,
login::kUserImageSize,
login::kUserImageSize);
if (delegate_)
delegate_->OnDownloadSuccess(resized_image);
image_size,
image_size);
delegate_->OnDownloadComplete(this, true);
}
void ProfileImageDownloader::OnDecodeImageFailed(const ImageDecoder* decoder) {
void ProfileDownloader::OnDecodeImageFailed(const ImageDecoder* decoder) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (delegate_)
delegate_->OnDownloadFailure();
delegate_->OnDownloadComplete(this, false);
}
void ProfileImageDownloader::Observe(
void ProfileDownloader::Observe(
int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
......@@ -287,11 +298,8 @@ void ProfileImageDownloader::Observe(
}
} else {
if (token_details->service() == GaiaConstants::kPicasaService) {
LOG(WARNING) << "ProfileImageDownloader: token request failed";
if (delegate_)
delegate_->OnDownloadFailure();
LOG(WARNING) << "ProfileDownloader: token request failed";
delegate_->OnDownloadComplete(this, false);
}
}
}
} // namespace chromeos
......@@ -2,63 +2,47 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_PROFILE_IMAGE_DOWNLOADER_H_
#define CHROME_BROWSER_CHROMEOS_LOGIN_PROFILE_IMAGE_DOWNLOADER_H_
#ifndef CHROME_BROWSER_PROFILES_PROFILE_DOWNLOADER_H_
#define CHROME_BROWSER_PROFILES_PROFILE_DOWNLOADER_H_
#pragma once
#include <string>
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/chromeos/login/image_decoder.h"
#include "base/string16.h"
#include "chrome/browser/image_decoder.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/common/url_fetcher_delegate.h"
#include "googleurl/src/gurl.h"
#include "third_party/skia/include/core/SkBitmap.h"
namespace chromeos {
class ProfileDownloaderDelegate;
// Downloads user profile image, decodes it in a sandboxed process.
class ProfileImageDownloader : public content::URLFetcherDelegate,
// Downloads user profile information. The profile picture is decoded in a
// sandboxed process.
class ProfileDownloader : public content::URLFetcherDelegate,
public ImageDecoder::Delegate,
public content::NotificationObserver {
public:
// Enum for reporting histograms about profile picture download.
enum DownloadResult {
kDownloadSuccessChanged,
kDownloadSuccess,
kDownloadFailure,
kDownloadDefault,
// Must be the last, convenient count.
kDownloadResultsCount
};
// Reports on success or failure of Profile image download. It is OK to
// delete the |ProfileImageDownloader| instance in any of these handlers.
class Delegate {
public:
virtual ~Delegate() {}
// Called when image is successfully downloaded and decoded.
virtual void OnDownloadSuccess(const SkBitmap& image) = 0;
// Called on download failure.
virtual void OnDownloadFailure() {}
// Called when user has the default profile image and we won't download
// it.
virtual void OnDownloadDefaultImage() {}
};
explicit ProfileDownloader(ProfileDownloaderDelegate* delegate);
virtual ~ProfileDownloader();
explicit ProfileImageDownloader(Delegate* delegate);
virtual ~ProfileImageDownloader();
// Starts downloading the picture if the necessary authorization token is
// ready. If not, subscribes to token service and starts fetching if the
// Starts downloading profile information if the necessary authorization token
// is ready. If not, subscribes to token service and starts fetching if the
// token is available. Should not be called more than once.
void Start();
// On successful download this returns the full name of the user. For example
// "Pat Smith".
const string16& GetProfileFullName() const;
// On successful download this returns the profile picture of the user.
// For users with no profile picture set (that is, they have the default
// profile picture) this will return an Null bitmap.
const SkBitmap& GetProfilePicture() const;
private:
// Overriden from content::URLFetcherDelegate:
virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE;
......@@ -73,9 +57,11 @@ class ProfileImageDownloader : public content::URLFetcherDelegate,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
// Searches for profile image URL in user entry response from Picasa.
// Returns an empty string on failure.
std::string GetProfileImageURL(const std::string& data) const;
// Parses the entry response from Picasa and gets the nick name and
// and profile image URL. Returns false to indicate a parsing error.
bool GetProfileNickNameAndImageURL(const std::string& data,
string16* nick_name,
std::string* url) const;
// Returns true if the image url is url of the default profile picture.
bool IsDefaultProfileImageURL(const std::string& url) const;
......@@ -83,15 +69,15 @@ class ProfileImageDownloader : public content::URLFetcherDelegate,
// Issues the first request to get user profile image.
void StartFetchingImage();
Delegate* delegate_;
ProfileDownloaderDelegate* delegate_;
std::string auth_token_;
scoped_ptr<content::URLFetcher> user_entry_fetcher_;
scoped_ptr<content::URLFetcher> profile_image_fetcher_;
content::NotificationRegistrar registrar_;
string16 profile_full_name_;
SkBitmap profile_picture_;
DISALLOW_COPY_AND_ASSIGN(ProfileImageDownloader);
DISALLOW_COPY_AND_ASSIGN(ProfileDownloader);
};
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_LOGIN_PROFILE_IMAGE_DOWNLOADER_H_
#endif // CHROME_BROWSER_PROFILES_PROFILE_DOWNLOADER_H_
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_PROFILES_PROFILE_DOWNLOADER_DELEGATE_H_
#define CHROME_BROWSER_PROFILES_PROFILE_DOWNLOADER_DELEGATE_H_
#pragma once
#include <string>
#include "base/basictypes.h"
#include "base/string16.h"
class Profile;
class ProfileDownloader;
// Reports on success or failure of Profile download. It is OK to delete the
// |ProfileImageDownloader| instance in any of these handlers.
class ProfileDownloaderDelegate {
public:
virtual ~ProfileDownloaderDelegate() {}
// Returns the desired side length of the profile image. If 0, returns image
// of the originally uploaded size.
virtual int GetDesiredImageSideLength() = 0;
// Returns the browser profile associated with this download request.
virtual Profile* GetBrowserProfile() = 0;
// Called when the download is complete. On success delegate should query
// the downloader for values.
virtual void OnDownloadComplete(ProfileDownloader* downloader,
bool success) = 0;
};
#endif // CHROME_BROWSER_PROFILES_PROFILE_DOWNLOADER_DELEGATE_H_
......@@ -570,8 +570,6 @@
'browser/chromeos/login/helper.h',
'browser/chromeos/login/html_page_screen.cc',
'browser/chromeos/login/html_page_screen.h',
'browser/chromeos/login/image_decoder.cc',
'browser/chromeos/login/image_decoder.h',
'browser/chromeos/login/image_downloader.cc',
'browser/chromeos/login/image_downloader.h',
'browser/chromeos/login/issue_response_handler.cc',
......@@ -613,8 +611,6 @@
'browser/chromeos/login/parallel_authenticator.h',
'browser/chromeos/login/password_changed_view.cc',
'browser/chromeos/login/password_changed_view.h',
'browser/chromeos/login/profile_image_downloader.cc',
'browser/chromeos/login/profile_image_downloader.h',
'browser/chromeos/login/proxy_settings_dialog.cc',
'browser/chromeos/login/proxy_settings_dialog.h',
'browser/chromeos/login/registration_screen.cc',
......@@ -1394,6 +1390,8 @@
'browser/idle_query_linux.cc',
'browser/idle_query_linux.h',
'browser/idle_win.cc',
'browser/image_decoder.cc',
'browser/image_decoder.h',
'browser/importer/external_process_importer_bridge.cc',
'browser/importer/external_process_importer_bridge.h',
'browser/importer/external_process_importer_client.cc',
......@@ -1952,6 +1950,9 @@
'browser/profiles/profile.h',
'browser/profiles/profile_dependency_manager.cc',
'browser/profiles/profile_dependency_manager.h',
'browser/profiles/profile_downloader.cc',
'browser/profiles/profile_downloader.h',
'browser/profiles/profile_downloader_delegate.h',
'browser/profiles/profile_impl.cc',
'browser/profiles/profile_impl.h',
'browser/profiles/profile_impl_io_data.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment