OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/webui/signin/user_manager_screen_handler.h" | 5 #include "chrome/browser/ui/webui/signin/user_manager_screen_handler.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/value_conversions.h" | 8 #include "base/value_conversions.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
11 #include "chrome/browser/profiles/avatar_menu.h" | 11 #include "chrome/browser/profiles/avatar_menu.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/profiles/profile_info_cache.h" | 13 #include "chrome/browser/profiles/profile_info_cache.h" |
14 #include "chrome/browser/profiles/profile_info_cache_observer.h" | 14 #include "chrome/browser/profiles/profile_info_cache_observer.h" |
| 15 #include "chrome/browser/profiles/profile_info_entry.h" |
15 #include "chrome/browser/profiles/profile_info_util.h" | 16 #include "chrome/browser/profiles/profile_info_util.h" |
16 #include "chrome/browser/profiles/profile_manager.h" | 17 #include "chrome/browser/profiles/profile_manager.h" |
17 #include "chrome/browser/profiles/profile_window.h" | 18 #include "chrome/browser/profiles/profile_window.h" |
18 #include "chrome/browser/profiles/profiles_state.h" | 19 #include "chrome/browser/profiles/profiles_state.h" |
19 #include "chrome/browser/ui/browser_finder.h" | 20 #include "chrome/browser/ui/browser_finder.h" |
20 #include "chrome/browser/ui/singleton_tabs.h" | 21 #include "chrome/browser/ui/singleton_tabs.h" |
21 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
22 #include "content/public/browser/web_contents_view.h" | 23 #include "content/public/browser/web_contents_view.h" |
23 #include "content/public/browser/web_ui.h" | 24 #include "content/public/browser/web_ui.h" |
24 #include "grit/browser_resources.h" | 25 #include "grit/browser_resources.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 if (status != Profile::CREATE_STATUS_INITIALIZED) | 70 if (status != Profile::CREATE_STATUS_INITIALIZED) |
70 return; | 71 return; |
71 profiles::FindOrCreateNewWindowForProfile( | 72 profiles::FindOrCreateNewWindowForProfile( |
72 profile, | 73 profile, |
73 chrome::startup::IS_PROCESS_STARTUP, | 74 chrome::startup::IS_PROCESS_STARTUP, |
74 chrome::startup::IS_FIRST_RUN, | 75 chrome::startup::IS_FIRST_RUN, |
75 desktop_type, | 76 desktop_type, |
76 false); | 77 false); |
77 } | 78 } |
78 | 79 |
79 std::string GetAvatarImageAtIndex( | 80 std::string GetAvatarImageForProfile(const base::FilePath profile_path, |
80 size_t index, const ProfileInfoCache& info_cache) { | 81 bool is_using_GAIA_picture, |
81 bool is_gaia_picture = | 82 const ProfileInfoCache& info_cache) { |
82 info_cache.IsUsingGAIAPictureOfProfileAtIndex(index) && | 83 bool is_gaia_picture = is_using_GAIA_picture && |
83 info_cache.GetGAIAPictureOfProfileAtIndex(index); | 84 info_cache.GetGAIAPictureOfProfile(profile_path); |
84 | 85 |
85 gfx::Image icon = profiles::GetSizedAvatarIconWithBorder( | 86 gfx::Image icon = profiles::GetSizedAvatarIconWithBorder( |
86 info_cache.GetAvatarIconOfProfileAtIndex(index), | 87 info_cache.GetAvatarIconOfProfile(profile_path), |
87 is_gaia_picture, kAvatarIconSize, kAvatarIconSize); | 88 is_gaia_picture, kAvatarIconSize, kAvatarIconSize); |
88 return webui::GetBitmapDataUrl(icon.AsBitmap()); | 89 return webui::GetBitmapDataUrl(icon.AsBitmap()); |
89 } | 90 } |
90 | 91 |
91 } // namespace | 92 } // namespace |
92 | 93 |
93 // ProfileUpdateObserver ------------------------------------------------------ | 94 // ProfileUpdateObserver ------------------------------------------------------ |
94 | 95 |
95 class UserManagerScreenHandler::ProfileUpdateObserver | 96 class UserManagerScreenHandler::ProfileUpdateObserver |
96 : public ProfileInfoCacheObserver { | 97 : public ProfileInfoCacheObserver { |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 void UserManagerScreenHandler::HandleLaunchUser(const base::ListValue* args) { | 199 void UserManagerScreenHandler::HandleLaunchUser(const base::ListValue* args) { |
199 string16 emailAddress; | 200 string16 emailAddress; |
200 string16 displayName; | 201 string16 displayName; |
201 | 202 |
202 if (!args->GetString(0, &emailAddress) || | 203 if (!args->GetString(0, &emailAddress) || |
203 !args->GetString(1, &displayName)) { | 204 !args->GetString(1, &displayName)) { |
204 NOTREACHED(); | 205 NOTREACHED(); |
205 return; | 206 return; |
206 } | 207 } |
207 | 208 |
208 ProfileInfoCache& info_cache = | 209 ProfileInfoCache& cache = |
209 g_browser_process->profile_manager()->GetProfileInfoCache(); | 210 g_browser_process->profile_manager()->GetProfileInfoCache(); |
210 | 211 |
211 for (size_t i = 0; i < info_cache.GetNumberOfProfiles(); ++i) { | 212 const std::vector<ProfileInfoEntry> entries(cache.GetProfilesSortedByName()); |
212 if (info_cache.GetUserNameOfProfileAtIndex(i) == emailAddress && | 213 for (std::vector<ProfileInfoEntry>::const_iterator it = entries.begin(); |
213 info_cache.GetNameOfProfileAtIndex(i) == displayName) { | 214 it != entries.end(); ++it) { |
214 base::FilePath path = info_cache.GetPathOfProfileAtIndex(i); | 215 if (it->user_name() == emailAddress && |
215 profiles::SwitchToProfile(path, desktop_type_, true); | 216 it->GetDisplayName() == displayName) { |
| 217 profiles::SwitchToProfile(it->path(), desktop_type_, true); |
216 break; | 218 break; |
217 } | 219 } |
218 } | 220 } |
219 } | 221 } |
220 | 222 |
221 void UserManagerScreenHandler::RegisterMessages() { | 223 void UserManagerScreenHandler::RegisterMessages() { |
222 web_ui()->RegisterMessageCallback(kJsApiUserManagerInitialize, | 224 web_ui()->RegisterMessageCallback(kJsApiUserManagerInitialize, |
223 base::Bind(&UserManagerScreenHandler::HandleInitialize, | 225 base::Bind(&UserManagerScreenHandler::HandleInitialize, |
224 base::Unretained(this))); | 226 base::Unretained(this))); |
225 web_ui()->RegisterMessageCallback(kJsApiUserManagerAddUser, | 227 web_ui()->RegisterMessageCallback(kJsApiUserManagerAddUser, |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 localized_strings->SetString("publicAccountReminder", string16()); | 298 localized_strings->SetString("publicAccountReminder", string16()); |
297 localized_strings->SetString("publicAccountEnter", string16()); | 299 localized_strings->SetString("publicAccountEnter", string16()); |
298 localized_strings->SetString("publicAccountEnterAccessibleName", string16()); | 300 localized_strings->SetString("publicAccountEnterAccessibleName", string16()); |
299 localized_strings->SetString("multiple-signin-banner-text", string16()); | 301 localized_strings->SetString("multiple-signin-banner-text", string16()); |
300 } | 302 } |
301 | 303 |
302 void UserManagerScreenHandler::SendUserList() { | 304 void UserManagerScreenHandler::SendUserList() { |
303 ListValue users_list; | 305 ListValue users_list; |
304 base::FilePath active_profile_path = | 306 base::FilePath active_profile_path = |
305 web_ui()->GetWebContents()->GetBrowserContext()->GetPath(); | 307 web_ui()->GetWebContents()->GetBrowserContext()->GetPath(); |
306 const ProfileInfoCache& info_cache = | 308 const ProfileInfoCache& cache = |
307 g_browser_process->profile_manager()->GetProfileInfoCache(); | 309 g_browser_process->profile_manager()->GetProfileInfoCache(); |
308 | 310 |
309 // If the active user is a managed user, then they may not perform | 311 // If the active user is a managed user, then they may not perform |
310 // certain actions (i.e. delete another user). | 312 // certain actions (i.e. delete another user). |
311 bool active_user_is_managed = Profile::FromWebUI(web_ui())->IsManaged(); | 313 bool active_user_is_managed = Profile::FromWebUI(web_ui())->IsManaged(); |
312 for (size_t i = 0; i < info_cache.GetNumberOfProfiles(); ++i) { | 314 |
| 315 const std::vector<ProfileInfoEntry> entries(cache.GetProfilesSortedByName()); |
| 316 for (std::vector<ProfileInfoEntry>::const_iterator it = entries.begin(); |
| 317 it != entries.end(); ++it) { |
| 318 bool is_active_user = (it->path() == active_profile_path); |
| 319 |
313 DictionaryValue* profile_value = new DictionaryValue(); | 320 DictionaryValue* profile_value = new DictionaryValue(); |
314 | 321 profile_value->SetString(kKeyUsername, it->user_name()); |
315 base::FilePath profile_path = info_cache.GetPathOfProfileAtIndex(i); | 322 profile_value->SetString(kKeyEmailAddress, it->user_name()); |
316 bool is_active_user = (profile_path == active_profile_path); | 323 profile_value->SetString(kKeyDisplayName, it->GetDisplayName()); |
317 | 324 profile_value->SetString(kKeyProfilePath, it->path().MaybeAsASCII()); |
318 profile_value->SetString( | |
319 kKeyUsername, info_cache.GetUserNameOfProfileAtIndex(i)); | |
320 profile_value->SetString( | |
321 kKeyEmailAddress, info_cache.GetUserNameOfProfileAtIndex(i)); | |
322 profile_value->SetString( | |
323 kKeyDisplayName, info_cache.GetNameOfProfileAtIndex(i)); | |
324 profile_value->SetString(kKeyProfilePath, profile_path.MaybeAsASCII()); | |
325 profile_value->SetBoolean(kKeyPublicAccount, false); | 325 profile_value->SetBoolean(kKeyPublicAccount, false); |
326 profile_value->SetBoolean(kKeyLocallyManagedUser, false); | 326 profile_value->SetBoolean(kKeyLocallyManagedUser, false); |
327 profile_value->SetBoolean(kKeySignedIn, is_active_user); | 327 profile_value->SetBoolean(kKeySignedIn, is_active_user); |
328 profile_value->SetBoolean( | 328 profile_value->SetBoolean(kKeyNeedsSignin, it->is_signin_required()); |
329 kKeyNeedsSignin, info_cache.ProfileIsSigninRequiredAtIndex(i)); | |
330 profile_value->SetBoolean(kKeyIsOwner, false); | 329 profile_value->SetBoolean(kKeyIsOwner, false); |
331 profile_value->SetBoolean(kKeyCanRemove, !active_user_is_managed); | 330 profile_value->SetBoolean(kKeyCanRemove, !active_user_is_managed); |
332 profile_value->SetBoolean(kKeyIsDesktop, true); | 331 profile_value->SetBoolean(kKeyIsDesktop, true); |
333 profile_value->SetString( | 332 profile_value->SetString(kKeyAvatarUrl, |
334 kKeyAvatarUrl, GetAvatarImageAtIndex(i, info_cache)); | 333 GetAvatarImageForProfile(it->path(), |
| 334 it->is_using_GAIA_picture(), |
| 335 cache)); |
335 | 336 |
336 // The row of user pods should display the active user first. | 337 // The row of user pods should display the active user first. |
337 if (is_active_user) | 338 if (is_active_user) |
338 users_list.Insert(0, profile_value); | 339 users_list.Insert(0, profile_value); |
339 else | 340 else |
340 users_list.Append(profile_value); | 341 users_list.Append(profile_value); |
341 } | 342 } |
342 | 343 |
343 web_ui()->CallJavascriptFunction("login.AccountPickerScreen.loadUsers", | 344 web_ui()->CallJavascriptFunction("login.AccountPickerScreen.loadUsers", |
344 users_list, base::FundamentalValue(false), base::FundamentalValue(true)); | 345 users_list, base::FundamentalValue(false), base::FundamentalValue(true)); |
345 } | 346 } |
OLD | NEW |