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

Unified Diff: chrome/browser/ui/webui/options/manage_profile_handler.cc

Issue 8511064: GAIA Profile info prototype (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: test 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/ui/webui/options/manage_profile_handler.cc
diff --git a/chrome/browser/ui/webui/options/manage_profile_handler.cc b/chrome/browser/ui/webui/options/manage_profile_handler.cc
index ec38b07f8b25e524aa3bb0172b0c79a11410c00d..27835af68b40a311c75faaa41fe1d3b20566cdb3 100644
--- a/chrome/browser/ui/webui/options/manage_profile_handler.cc
+++ b/chrome/browser/ui/webui/options/manage_profile_handler.cc
@@ -11,13 +11,19 @@
#include "base/value_conversions.h"
#include "base/values.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile_info_cache.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profile_metrics.h"
+#include "chrome/browser/ui/webui/web_ui_util.h"
#include "chrome/common/chrome_notification_types.h"
+#include "chrome/common/pref_names.h"
#include "content/browser/tab_contents/tab_contents.h"
#include "content/public/browser/notification_service.h"
#include "grit/generated_resources.h"
+#include "chrome/browser/profiles/profile_impl.h"
+
+extern SkBitmap FixGAIABmp(const SkBitmap& bmp);
ManageProfileHandler::ManageProfileHandler() {
}
@@ -47,6 +53,10 @@ void ManageProfileHandler::Initialize() {
registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED,
content::NotificationService::AllSources());
SendProfileNames();
+
+ Profile* profile = Profile::FromWebUI(web_ui_);
+ ProfileImpl* profile_impl = static_cast<ProfileImpl*>(profile);
+ profile_impl->UpdateGAIAProfileInfo();
}
void ManageProfileHandler::RegisterMessages() {
@@ -68,14 +78,34 @@ void ManageProfileHandler::Observe(
int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
- if (type == chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED)
+ if (type == chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED) {
SendProfileNames();
- else
+ SendProfileIcons();
+ } else {
OptionsPageUIHandler::Observe(type, source, details);
+ }
}
void ManageProfileHandler::RequestDefaultProfileIcons(const ListValue* args) {
+ SendProfileIcons();
+}
+
+void ManageProfileHandler::SendProfileIcons() {
ListValue image_url_list;
+
+ ProfileInfoCache& cache =
+ g_browser_process->profile_manager()->GetProfileInfoCache();
+ Profile* profile = Profile::FromWebUI(web_ui_);
+ size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath());
+ if (profile_index != std::string::npos) {
+ SkBitmap gaia_bmp = cache.GetGAIAPictureOfProfileAtIndex(profile_index);
+ if (!gaia_bmp.isNull()) {
+ SkBitmap bmp = FixGAIABmp(gaia_bmp);
+ gaia_profile_url_ = web_ui_util::GetImageDataUrl(bmp);
+ image_url_list.Append(Value::CreateStringValue(gaia_profile_url_));
+ }
+ }
+
for (size_t i = 0; i < ProfileInfoCache::GetDefaultAvatarIconCount(); i++) {
std::string url = ProfileInfoCache::GetDefaultAvatarIconUrl(i);
image_url_list.Append(Value::CreateStringValue(url));
@@ -113,10 +143,16 @@ void ManageProfileHandler::SetProfileNameAndIcon(const ListValue* args) {
if (profile_index == std::string::npos)
return;
+ cache.SetIsUsingGAIANameForProfileAtIndex(profile_index, false);
+ profile_index = cache.GetIndexOfProfileWithPath(profile_file_path);
+ if (profile_index == std::string::npos)
+ return;
+
string16 new_profile_name;
if (!args->GetString(1, &new_profile_name))
return;
+
cache.SetNameOfProfileAtIndex(profile_index, new_profile_name);
// The index in the cache may have changed if a new name triggered an
// alphabetical resort.
@@ -124,14 +160,22 @@ void ManageProfileHandler::SetProfileNameAndIcon(const ListValue* args) {
if (profile_index == std::string::npos)
return;
- string16 icon_url;
- size_t new_icon_index;
- if (!args->GetString(2, &icon_url) ||
- !cache.IsDefaultAvatarIconUrl(UTF16ToUTF8(icon_url), &new_icon_index))
+ std::string icon_url;
+ if (!args->GetString(2, &icon_url))
return;
- ProfileMetrics::LogProfileAvatarSelection(new_icon_index);
- cache.SetAvatarIconOfProfileAtIndex(profile_index, new_icon_index);
+ size_t new_icon_index;
+ if (icon_url == gaia_profile_url_) {
+ cache.SetIsUsingCustomAvatarIconForProfileAtIndex(
+ profile_index, true);
+ } else if (cache.IsDefaultAvatarIconUrl(icon_url, &new_icon_index)) {
+ ProfileMetrics::LogProfileAvatarSelection(new_icon_index);
+ cache.SetAvatarIconOfProfileAtIndex(profile_index, new_icon_index);
+ cache.SetIsUsingCustomAvatarIconForProfileAtIndex(
+ profile_index, false);
+ } else {
+ return;
+ }
ProfileMetrics::LogProfileUpdate(profile_file_path);
}
@@ -171,15 +215,23 @@ void ManageProfileHandler::RequestProfileInfo(const ListValue* args) {
FilePath current_profile_path =
web_ui_->tab_contents()->browser_context()->GetPath();
- size_t icon_index = cache.GetAvatarIconIndexOfProfileAtIndex(index);
FilePath profile_path = cache.GetPathOfProfileAtIndex(index);
profile_value.SetString("name", cache.GetNameOfProfileAtIndex(index));
- profile_value.SetString("iconURL",
- cache.GetDefaultAvatarIconUrl(icon_index));
profile_value.Set("filePath", base::CreateFilePathValue(profile_path));
profile_value.SetBoolean("isCurrentProfile",
profile_path == current_profile_path);
+ std::string bmp_url;
+ if (!cache.IsUsingCustomAvatarIconForProfileAtIndex(index)) {
+ size_t icon_index = cache.GetAvatarIconIndexOfProfileAtIndex(index);
+ bmp_url = cache.GetDefaultAvatarIconUrl(icon_index);
+ } else {
+ SkBitmap bmp = cache.GetGAIAPictureOfProfileAtIndex(index);
+ SkBitmap bmp2 = FixGAIABmp(bmp);
+ bmp_url = web_ui_util::GetImageDataUrl(bmp2);
+ }
+ profile_value.SetString("iconURL", bmp_url);
+
web_ui_->CallJavascriptFunction("ManageProfileOverlay.setProfileInfo",
profile_value);
}
« no previous file with comments | « chrome/browser/ui/webui/options/manage_profile_handler.h ('k') | chrome/browser/ui/webui/options/personal_options_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698