summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/chromeos/login/captcha_view.h2
-rw-r--r--chrome/browser/chromeos/login/image_downloader.h2
-rw-r--r--chrome/browser/chromeos/login/login_utils_browsertest.cc1
-rw-r--r--chrome/browser/chromeos/login/profile_image_downloader.h97
-rw-r--r--chrome/browser/chromeos/login/user_image_loader.cc1
-rw-r--r--chrome/browser/chromeos/login/user_image_loader.h2
-rw-r--r--chrome/browser/chromeos/login/user_manager.cc119
-rw-r--r--chrome/browser/chromeos/login/user_manager.h16
-rw-r--r--chrome/browser/image_decoder.cc (renamed from chrome/browser/chromeos/login/image_decoder.cc)6
-rw-r--r--chrome/browser/image_decoder.h (renamed from chrome/browser/chromeos/login/image_decoder.h)10
-rw-r--r--chrome/browser/profiles/profile_downloader.cc (renamed from chrome/browser/chromeos/login/profile_image_downloader.cc)122
-rw-r--r--chrome/browser/profiles/profile_downloader.h83
-rw-r--r--chrome/browser/profiles/profile_downloader_delegate.h36
-rw-r--r--chrome/chrome_browser.gypi9
14 files changed, 275 insertions, 231 deletions
diff --git a/chrome/browser/chromeos/login/captcha_view.h b/chrome/browser/chromeos/login/captcha_view.h
index 3122bc7..0ef4c57 100644
--- a/chrome/browser/chromeos/login/captcha_view.h
+++ b/chrome/browser/chromeos/login/captcha_view.h
@@ -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"
diff --git a/chrome/browser/chromeos/login/image_downloader.h b/chrome/browser/chromeos/login/image_downloader.h
index 4fd61ca..02b1f84 100644
--- a/chrome/browser/chromeos/login/image_downloader.h
+++ b/chrome/browser/chromeos/login/image_downloader.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"
diff --git a/chrome/browser/chromeos/login/login_utils_browsertest.cc b/chrome/browser/chromeos/login/login_utils_browsertest.cc
index 8f66f66..85b15a4 100644
--- a/chrome/browser/chromeos/login/login_utils_browsertest.cc
+++ b/chrome/browser/chromeos/login/login_utils_browsertest.cc
@@ -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"
diff --git a/chrome/browser/chromeos/login/profile_image_downloader.h b/chrome/browser/chromeos/login/profile_image_downloader.h
deleted file mode 100644
index 8701b34..0000000
--- a/chrome/browser/chromeos/login/profile_image_downloader.h
+++ /dev/null
@@ -1,97 +0,0 @@
-// 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_CHROMEOS_LOGIN_PROFILE_IMAGE_DOWNLOADER_H_
-#define CHROME_BROWSER_CHROMEOS_LOGIN_PROFILE_IMAGE_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 "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"
-
-namespace chromeos {
-
-// Downloads user profile image, decodes it in a sandboxed process.
-class ProfileImageDownloader : 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 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
- // token is available. Should not be called more than once.
- void Start();
-
- private:
- // Overriden from content::URLFetcherDelegate:
- virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE;
-
- // Overriden from ImageDecoder::Delegate:
- virtual void OnImageDecoded(const ImageDecoder* decoder,
- const SkBitmap& decoded_image) OVERRIDE;
- virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE;
-
- // Overriden from content::NotificationObserver:
- virtual void Observe(int type,
- 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;
-
- // Returns true if the image url is url of the default profile picture.
- bool IsDefaultProfileImageURL(const std::string& url) const;
-
- // Issues the first request to get user profile image.
- void StartFetchingImage();
-
- Delegate* delegate_;
- std::string auth_token_;
- scoped_ptr<content::URLFetcher> user_entry_fetcher_;
- scoped_ptr<content::URLFetcher> profile_image_fetcher_;
- content::NotificationRegistrar registrar_;
-
- DISALLOW_COPY_AND_ASSIGN(ProfileImageDownloader);
-};
-
-} // namespace chromeos
-
-#endif // CHROME_BROWSER_CHROMEOS_LOGIN_PROFILE_IMAGE_DOWNLOADER_H_
diff --git a/chrome/browser/chromeos/login/user_image_loader.cc b/chrome/browser/chromeos/login/user_image_loader.cc
index 2d635dd..21b8813 100644
--- a/chrome/browser/chromeos/login/user_image_loader.cc
+++ b/chrome/browser/chromeos/login/user_image_loader.cc
@@ -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"
diff --git a/chrome/browser/chromeos/login/user_image_loader.h b/chrome/browser/chromeos/login/user_image_loader.h
index e507d10..a3212ac5 100644
--- a/chrome/browser/chromeos/login/user_image_loader.h
+++ b/chrome/browser/chromeos/login/user_image_loader.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;
diff --git a/chrome/browser/chromeos/login/user_manager.cc b/chrome/browser/chromeos/login/user_manager.cc
index 6b90367..b64c68b6 100644
--- a/chrome/browser/chromeos/login/user_manager.cc
+++ b/chrome/browser/chromeos/login/user_manager.cc
@@ -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,65 +808,65 @@ 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;
+}
- // Check if this image is not the same as already downloaded.
- std::string new_image_data_url = web_ui_util::GetImageDataUrl(image);
- if (!downloaded_profile_image_data_url_.empty() &&
- new_image_data_url == downloaded_profile_image_data_url_)
- return;
+Profile* UserManager::GetBrowserProfile() {
+ return ProfileManager::GetDefaultProfile();
+}
- downloaded_profile_image_data_url_ = new_image_data_url;
- downloaded_profile_image_ = image;
+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 (logged_in_user().image_index() == User::kProfileImageIndex) {
- std::string current_image_data_url =
- web_ui_util::GetImageDataUrl(logged_in_user().image());
- if (current_image_data_url == new_image_data_url)
+ if (result == kDownloadSuccess) {
+ // Check if this image is not the same as already downloaded.
+ 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;
- VLOG(1) << "Updating profile image for logged-in user";
- UMA_HISTOGRAM_ENUMERATION("UserImageDownloadResult.LoggedIn",
- ProfileImageDownloader::kDownloadSuccessChanged,
- ProfileImageDownloader::kDownloadResultsCount);
+ downloaded_profile_image_data_url_ = new_image_data_url;
+ downloaded_profile_image_ = downloader->GetProfilePicture();
- // This will persist |downloaded_profile_image_| to file.
- SaveUserImageFromProfileImage(logged_in_user().email());
- }
+ if (logged_in_user().image_index() == User::kProfileImageIndex) {
+ std::string current_image_data_url =
+ web_ui_util::GetImageDataUrl(logged_in_user().image());
+ if (current_image_data_url == new_image_data_url)
+ return;
- content::NotificationService::current()->Notify(
- chrome::NOTIFICATION_PROFILE_IMAGE_UPDATED,
- content::Source<UserManager>(this),
- content::Details<const SkBitmap>(&image));
+ VLOG(1) << "Updating profile image for logged-in user";
+ UMA_HISTOGRAM_ENUMERATION("UserImage.ProfileDownloadResult",
+ kDownloadSuccessChanged,
+ kDownloadResultsCount);
- profile_image_downloader_.reset();
-}
+ // This will persist |downloaded_profile_image_| to file.
+ SaveUserImageFromProfileImage(logged_in_user().email());
+ }
+ }
-void UserManager::OnDownloadFailure() {
- VLOG(1) << "Download of profile image for logged-in user failed.";
- UMA_HISTOGRAM_ENUMERATION("UserImageDownloadResult.LoggedIn",
- ProfileImageDownloader::kDownloadFailure,
- ProfileImageDownloader::kDownloadResultsCount);
- content::NotificationService::current()->Notify(
- chrome::NOTIFICATION_PROFILE_IMAGE_UPDATE_FAILED,
- content::Source<UserManager>(this),
- content::NotificationService::NoDetails());
- profile_image_downloader_.reset();
-}
+ if (result == kDownloadSuccess) {
+ content::NotificationService::current()->Notify(
+ chrome::NOTIFICATION_PROFILE_IMAGE_UPDATED,
+ content::Source<UserManager>(this),
+ content::Details<const SkBitmap>(&downloader->GetProfilePicture()));
+ } else {
+ content::NotificationService::current()->Notify(
+ chrome::NOTIFICATION_PROFILE_IMAGE_UPDATE_FAILED,
+ content::Source<UserManager>(this),
+ content::NotificationService::NoDetails());
+ }
-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();
}
diff --git a/chrome/browser/chromeos/login/user_manager.h b/chrome/browser/chromeos/login/user_manager.h
index 4e3aa2f..d1137a9 100644
--- a/chrome/browser/chromeos/login/user_manager.h
+++ b/chrome/browser/chromeos/login/user_manager.h
@@ -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_;
diff --git a/chrome/browser/chromeos/login/image_decoder.cc b/chrome/browser/image_decoder.cc
index 87671c2..3fb7aa8 100644
--- a/chrome/browser/chromeos/login/image_decoder.cc
+++ b/chrome/browser/image_decoder.cc
@@ -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
diff --git a/chrome/browser/chromeos/login/image_decoder.h b/chrome/browser/image_decoder.h
index c60f248..ec90d01 100644
--- a/chrome/browser/chromeos/login/image_decoder.h
+++ b/chrome/browser/image_decoder.h
@@ -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_
diff --git a/chrome/browser/chromeos/login/profile_image_downloader.cc b/chrome/browser/profiles/profile_downloader.cc
index 475d948..468cc8c 100644
--- a/chrome/browser/chromeos/login/profile_image_downloader.cc
+++ b/chrome/browser/profiles/profile_downloader.cc
@@ -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,
- const SkBitmap& decoded_image) {
+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
diff --git a/chrome/browser/profiles/profile_downloader.h b/chrome/browser/profiles/profile_downloader.h
new file mode 100644
index 0000000..2b9733e
--- /dev/null
+++ b/chrome/browser/profiles/profile_downloader.h
@@ -0,0 +1,83 @@
+// 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_H_
+#define CHROME_BROWSER_PROFILES_PROFILE_DOWNLOADER_H_
+#pragma once
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/memory/scoped_ptr.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"
+
+class ProfileDownloaderDelegate;
+
+// 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:
+ explicit ProfileDownloader(ProfileDownloaderDelegate* delegate);
+ virtual ~ProfileDownloader();
+
+ // 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;
+
+ // Overriden from ImageDecoder::Delegate:
+ virtual void OnImageDecoded(const ImageDecoder* decoder,
+ const SkBitmap& decoded_image) OVERRIDE;
+ virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE;
+
+ // Overriden from content::NotificationObserver:
+ virtual void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) OVERRIDE;
+
+ // 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;
+
+ // Issues the first request to get user profile image.
+ void StartFetchingImage();
+
+ 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(ProfileDownloader);
+};
+
+#endif // CHROME_BROWSER_PROFILES_PROFILE_DOWNLOADER_H_
diff --git a/chrome/browser/profiles/profile_downloader_delegate.h b/chrome/browser/profiles/profile_downloader_delegate.h
new file mode 100644
index 0000000..2a71a19
--- /dev/null
+++ b/chrome/browser/profiles/profile_downloader_delegate.h
@@ -0,0 +1,36 @@
+// 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_
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 5e1c77a..ba4b788 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -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',