Index: chrome/browser/gaia_userinfo/profile_downloader.cc |
diff --git a/chrome/browser/chromeos/login/profile_image_downloader.cc b/chrome/browser/gaia_userinfo/profile_downloader.cc |
similarity index 78% |
rename from chrome/browser/chromeos/login/profile_image_downloader.cc |
rename to chrome/browser/gaia_userinfo/profile_downloader.cc |
index 475d94896d5b3eb5aa46fa4c06f2bc9b426514f8..eb8e2a385a6f265f0712d4b56092daf943eae12c 100644 |
--- a/chrome/browser/chromeos/login/profile_image_downloader.cc |
+++ b/chrome/browser/gaia_userinfo/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/gaia_userinfo/profile_downloader.h" |
#include <string> |
#include <vector> |
@@ -13,10 +13,8 @@ |
#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/common/chrome_notification_types.h" |
#include "chrome/common/net/gaia/gaia_constants.h" |
#include "content/public/browser/browser_thread.h" |
@@ -28,11 +26,10 @@ |
#include "content/public/common/url_fetcher.h" |
#include "googleurl/src/gurl.h" |
#include "skia/ext/image_operations.h" |
+#include "third_party/skia/include/core/SkBitmap.h" |
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 { |
+void ProfileDownloader::GetProfileNickNameAndImageURL(const std::string& data, |
+ string16* nick_name, |
+ std::string* url) const { |
+ DCHECK(nick_name); |
+ DCHECK(url); |
+ *nick_name = string16(); |
+ *url = string16(); |
+ |
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; |
} |
if (!root_value->IsType(base::Value::TYPE_DICTIONARY)) { |
LOG(ERROR) << "JSON root is not a dictionary: " |
<< root_value->GetType(); |
- return std::string(); |
+ return; |
} |
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; |
+ } |
+ |
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; |
} |
// 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_->GetDesiredImageSize(); |
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,12 @@ 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; |
} |
- return thumbnail_url.spec(); |
+ *url = thumbnail_url.spec(); |
} |
-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 +170,19 @@ bool ProfileImageDownloader::IsDefaultProfileImageURL( |
photo_version == kDefaultGooglePlusPhotoVersion)); |
} |
-ProfileImageDownloader::ProfileImageDownloader(Delegate* delegate) |
- : delegate_(delegate) { |
+ProfileDownloader::ProfileDownloader(Delegate* delegate) : delegate_(delegate) { |
Ivan Korotkov
2011/11/15 11:05:08
Please break line before :
whywhat
2011/11/15 12:19:21
This is not necessary for such short initializer l
sail
2011/11/15 20:17:22
Done.
|
+ DCHECK(delegate_); |
} |
-void ProfileImageDownloader::Start() { |
+void ProfileDownloader::Start() { |
VLOG(1) << "Starting profile image 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_->OnDownloadFailure(); |
return; |
} |
if (service->HasTokenForService(GaiaConstants::kPicasaService)) { |
@@ -190,15 +199,15 @@ void ProfileImageDownloader::Start() { |
} |
} |
-void ProfileImageDownloader::StartFetchingImage() { |
- std::string email = UserManager::Get()->logged_in_user().email(); |
+void ProfileDownloader::StartFetchingImage() { |
+ std::string email = delegate_->GetProfileUserName(); |
if (email.empty()) |
return; |
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 +215,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 +225,26 @@ 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_->OnDownloadFailure(); |
return; |
} |
if (source == user_entry_fetcher_.get()) { |
- std::string image_url = GetProfileImageURL(data); |
+ std::string image_url; |
+ GetProfileNickNameAndImageURL(data, &full_name_, &image_url); |
if (image_url.empty()) { |
- if (delegate_) |
- delegate_->OnDownloadFailure(); |
+ delegate_->OnDownloadFailure(); |
return; |
} |
if (IsDefaultProfileImageURL(image_url)) { |
- if (delegate_) |
- delegate_->OnDownloadDefaultImage(); |
+ delegate_->OnDownloadDefaultImage(full_name_); |
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,28 +258,26 @@ 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)); |
+ int image_size = delegate_->GetDesiredImageSize(); |
SkBitmap resized_image = skia::ImageOperations::Resize( |
decoded_image, |
skia::ImageOperations::RESIZE_BEST, |
- login::kUserImageSize, |
- login::kUserImageSize); |
- if (delegate_) |
- delegate_->OnDownloadSuccess(resized_image); |
+ image_size, |
+ image_size); |
+ delegate_->OnDownloadSuccess(resized_image); |
whywhat
2011/11/15 12:19:21
Shouldn't you pass full_name_ here as well?
sail
2011/11/15 20:17:22
Done.
|
} |
-void ProfileImageDownloader::OnDecodeImageFailed(const ImageDecoder* decoder) { |
+void ProfileDownloader::OnDecodeImageFailed(const ImageDecoder* decoder) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
- if (delegate_) |
- delegate_->OnDownloadFailure(); |
+ delegate_->OnDownloadFailure(); |
} |
-void ProfileImageDownloader::Observe( |
- int type, |
whywhat
2011/11/15 12:19:21
optional: I liked the original formatting. If some
sail
2011/11/15 20:17:22
Done.
|
- const content::NotificationSource& source, |
- const content::NotificationDetails& details) { |
+void ProfileDownloader::Observe(int type, |
+ const content::NotificationSource& source, |
+ const content::NotificationDetails& details) { |
DCHECK(type == chrome::NOTIFICATION_TOKEN_AVAILABLE || |
type == chrome::NOTIFICATION_TOKEN_REQUEST_FAILED); |
@@ -287,11 +291,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_->OnDownloadFailure(); |
} |
} |
} |
- |
-} // namespace chromeos |