Commit 199ae200 authored by avayvod@chromium.org's avatar avayvod@chromium.org

[cros] Added histograms for user image usage

R=altimofeev@chromium.org
BUG=chromium-os:18916
TEST=Sign in as a new or existing user with different images chosen. Change picture to different ones. Check that each time the appropriate histogram is updated at chrome://histograms.

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@96176 0039d316-1c4b-4281-b951-d872f2087c98
parent f0f1a234
...@@ -209,7 +209,7 @@ gfx::Rect UserController::GetMainInputScreenBounds() const { ...@@ -209,7 +209,7 @@ gfx::Rect UserController::GetMainInputScreenBounds() const {
void UserController::OnUserImageChanged(UserManager::User* user) { void UserController::OnUserImageChanged(UserManager::User* user) {
if (user_.email() != user->email()) if (user_.email() != user->email())
return; return;
user_.set_image(user->image()); user_.SetImage(user->image(), user->default_image_index());
// Controller might exist without windows, // Controller might exist without windows,
// i.e. if user pod doesn't fit on the screen. // i.e. if user pod doesn't fit on the screen.
if (user_view_) if (user_view_)
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "chrome/browser/chromeos/login/user_image_screen.h" #include "chrome/browser/chromeos/login/user_image_screen.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/metrics/histogram.h"
#include "chrome/browser/chromeos/login/default_user_images.h" #include "chrome/browser/chromeos/login/default_user_images.h"
#include "chrome/browser/chromeos/login/login_utils.h" #include "chrome/browser/chromeos/login/login_utils.h"
#include "chrome/browser/chromeos/login/screen_observer.h" #include "chrome/browser/chromeos/login/screen_observer.h"
...@@ -111,6 +112,10 @@ void UserImageScreen::OnPhotoTaken(const SkBitmap& image) { ...@@ -111,6 +112,10 @@ void UserImageScreen::OnPhotoTaken(const SkBitmap& image) {
user_manager->SetLoggedInUserImage(image); user_manager->SetLoggedInUserImage(image);
user_manager->SaveUserImage(user.email(), image); user_manager->SaveUserImage(user.email(), image);
get_screen_observer()->OnExit(ScreenObserver::USER_IMAGE_SELECTED); get_screen_observer()->OnExit(ScreenObserver::USER_IMAGE_SELECTED);
UMA_HISTOGRAM_ENUMERATION("UserImage.FirstTimeChoice",
kDefaultImagesCount,
kDefaultImagesCount + 1);
} }
void UserImageScreen::OnDefaultImageSelected(int index) { void UserImageScreen::OnDefaultImageSelected(int index) {
...@@ -129,6 +134,10 @@ void UserImageScreen::OnDefaultImageSelected(int index) { ...@@ -129,6 +134,10 @@ void UserImageScreen::OnDefaultImageSelected(int index) {
user.email(), user.email(),
GetDefaultImagePath(static_cast<size_t>(index))); GetDefaultImagePath(static_cast<size_t>(index)));
get_screen_observer()->OnExit(ScreenObserver::USER_IMAGE_SELECTED); get_screen_observer()->OnExit(ScreenObserver::USER_IMAGE_SELECTED);
UMA_HISTOGRAM_ENUMERATION("UserImage.FirstTimeChoice",
index,
kDefaultImagesCount + 1);
} }
void UserImageScreen::OnActorDestroyed(UserImageScreenActor* actor) { void UserImageScreen::OnActorDestroyed(UserImageScreenActor* actor) {
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/file_util.h" #include "base/file_util.h"
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/metrics/histogram.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/string_util.h" #include "base/string_util.h"
#include "base/stringprintf.h" #include "base/stringprintf.h"
...@@ -223,6 +224,12 @@ UserManager::User::User() : oauth_token_status_(OAUTH_TOKEN_STATUS_UNKNOWN), ...@@ -223,6 +224,12 @@ UserManager::User::User() : oauth_token_status_(OAUTH_TOKEN_STATUS_UNKNOWN),
UserManager::User::~User() {} UserManager::User::~User() {}
void UserManager::User::SetImage(const SkBitmap& image,
int default_image_index) {
image_ = image;
default_image_index_ = default_image_index;
}
std::string UserManager::User::GetDisplayName() const { std::string UserManager::User::GetDisplayName() const {
size_t i = email_.find('@'); size_t i = email_.find('@');
if (i == 0 || i == std::string::npos) { if (i == 0 || i == std::string::npos) {
...@@ -303,29 +310,30 @@ std::vector<UserManager::User> UserManager::GetUsers() const { ...@@ -303,29 +310,30 @@ std::vector<UserManager::User> UserManager::GetUsers() const {
} }
} }
UserImages::const_iterator image_it = user_images_.find(email);
std::string image_path; std::string image_path;
if (image_it == user_images_.end()) {
// Get account image path. // Get account image path.
if (prefs_images && if (prefs_images &&
prefs_images->GetStringWithoutPathExpansion(email, &image_path)) { prefs_images->GetStringWithoutPathExpansion(email, &image_path)) {
int default_image_id = kDefaultImagesCount; int default_image_id = kDefaultImagesCount;
if (IsDefaultImagePath(image_path, &default_image_id)) { if (IsDefaultImagePath(image_path, &default_image_id)) {
DCHECK(default_image_id >= 0);
DCHECK(default_image_id < kDefaultImagesCount); DCHECK(default_image_id < kDefaultImagesCount);
int resource_id = kDefaultImageResources[default_image_id]; int resource_id = kDefaultImageResources[default_image_id];
user.set_image( user.SetImage(
*ResourceBundle::GetSharedInstance().GetBitmapNamed( *ResourceBundle::GetSharedInstance().GetBitmapNamed(
resource_id)); resource_id),
user_images_[email] = user.image(); default_image_id);
} else { } else {
UserImages::const_iterator image_it = user_images_.find(email);
if (image_it == user_images_.end()) {
// Insert the default image so we don't send another request if // Insert the default image so we don't send another request if
// GetUsers is called twice. // GetUsers is called twice.
user_images_[email] = user.image(); user_images_[email] = user.image();
image_loader_->Start(email, image_path, false); image_loader_->Start(email, image_path, false);
} else {
user.SetImage(image_it->second, -1);
} }
} }
} else {
user.set_image(image_it->second);
} }
// Makes table to determine whether displayname is unique. // Makes table to determine whether displayname is unique.
...@@ -389,8 +397,16 @@ void UserManager::UserLoggedIn(const std::string& email) { ...@@ -389,8 +397,16 @@ void UserManager::UserLoggedIn(const std::string& email) {
} }
prefs->SavePersistentPrefs(); prefs->SavePersistentPrefs();
NotifyOnLogin(); NotifyOnLogin();
if (current_user_is_new_) if (current_user_is_new_) {
SetDefaultUserImage(email); SetDefaultUserImage(email);
} else {
int metric = kDefaultImagesCount;
if (logged_in_user_.default_image_index() != -1)
metric = logged_in_user_.default_image_index();
UMA_HISTOGRAM_ENUMERATION("UserImage.LoggedIn",
metric,
kDefaultImagesCount + 1);
}
} }
void UserManager::RemoveUser(const std::string& email, void UserManager::RemoveUser(const std::string& email,
...@@ -580,9 +596,9 @@ void UserManager::OnImageLoaded(const std::string& username, ...@@ -580,9 +596,9 @@ void UserManager::OnImageLoaded(const std::string& username,
user_images_[username] = image; user_images_[username] = image;
User user; User user;
user.set_email(username); user.set_email(username);
user.set_image(image); user.SetImage(image, -1);
if (logged_in_user_.email() == username) if (logged_in_user_.email() == username)
logged_in_user_.set_image(image); logged_in_user_.SetImage(image, -1);
if (should_save_image) if (should_save_image)
SaveUserImage(username, image); SaveUserImage(username, image);
NotificationService::current()->Notify( NotificationService::current()->Notify(
......
...@@ -62,8 +62,10 @@ class UserManager : public UserImageLoader::Delegate, ...@@ -62,8 +62,10 @@ class UserManager : public UserImageLoader::Delegate,
bool NeedsNameTooltip() const; bool NeedsNameTooltip() const;
// The image for this user. // The image for this user.
void set_image(const SkBitmap& image) { image_ = image; } void SetImage(const SkBitmap& image,
int default_image_index);
const SkBitmap& image() const { return image_; } const SkBitmap& image() const { return image_; }
int default_image_index() const { return default_image_index_; }
// OAuth token status for this user. // OAuth token status for this user.
OAuthTokenStatus oauth_token_status() const { return oauth_token_status_; } OAuthTokenStatus oauth_token_status() const { return oauth_token_status_; }
...@@ -80,6 +82,10 @@ class UserManager : public UserImageLoader::Delegate, ...@@ -80,6 +82,10 @@ class UserManager : public UserImageLoader::Delegate,
// Cached flag of whether any users has same display name. // Cached flag of whether any users has same display name.
bool is_displayname_unique_; bool is_displayname_unique_;
// Index of the default image the user has set. -1 if it's some other
// image.
int default_image_index_;
}; };
// Gets a shared instance of a UserManager. Not thread-safe...should // Gets a shared instance of a UserManager. Not thread-safe...should
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "chrome/browser/ui/webui/options/chromeos/change_picture_options_handler.h" #include "chrome/browser/ui/webui/options/chromeos/change_picture_options_handler.h"
#include "base/callback.h" #include "base/callback.h"
#include "base/metrics/histogram.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/chromeos/login/default_user_images.h" #include "chrome/browser/chromeos/login/default_user_images.h"
...@@ -151,12 +152,18 @@ void ChangePictureOptionsHandler::HandleSelectImage(const ListValue* args) { ...@@ -151,12 +152,18 @@ void ChangePictureOptionsHandler::HandleSelectImage(const ListValue* args) {
user_manager->SaveUserImagePath( user_manager->SaveUserImagePath(
user_manager->logged_in_user().email(), user_manager->logged_in_user().email(),
GetDefaultImagePath(user_image_index)); GetDefaultImagePath(user_image_index));
UMA_HISTOGRAM_ENUMERATION("UserImage.ChangeChoice",
user_image_index,
kDefaultImagesCount + 2);
} }
void ChangePictureOptionsHandler::FileSelected(const FilePath& path, void ChangePictureOptionsHandler::FileSelected(const FilePath& path,
int index, int index,
void* params) { void* params) {
UserManager::Get()->LoadLoggedInUserImage(path); UserManager::Get()->LoadLoggedInUserImage(path);
UMA_HISTOGRAM_ENUMERATION("UserImage.ChangeChoice",
kDefaultImagesCount + 1,
kDefaultImagesCount + 2);
} }
void ChangePictureOptionsHandler::OnPhotoAccepted(const SkBitmap& photo) { void ChangePictureOptionsHandler::OnPhotoAccepted(const SkBitmap& photo) {
...@@ -168,6 +175,9 @@ void ChangePictureOptionsHandler::OnPhotoAccepted(const SkBitmap& photo) { ...@@ -168,6 +175,9 @@ void ChangePictureOptionsHandler::OnPhotoAccepted(const SkBitmap& photo) {
user_manager->SetLoggedInUserImage(photo); user_manager->SetLoggedInUserImage(photo);
user_manager->SaveUserImage(user.email(), photo); user_manager->SaveUserImage(user.email(), photo);
UMA_HISTOGRAM_ENUMERATION("UserImage.ChangeChoice",
kDefaultImagesCount,
kDefaultImagesCount + 2);
} }
gfx::NativeWindow ChangePictureOptionsHandler::GetBrowserWindow() const { gfx::NativeWindow ChangePictureOptionsHandler::GetBrowserWindow() const {
......
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