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

Side by Side Diff: chrome/browser/ui/webui/options/manage_profile_handler.cc

Issue 33753002: Sooper experimental refactoring of the profile info cache. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 7 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/options/manage_profile_handler.h" 5 #include "chrome/browser/ui/webui/options/manage_profile_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 } 238 }
239 239
240 void ManageProfileHandler::SendProfileIcons( 240 void ManageProfileHandler::SendProfileIcons(
241 const base::StringValue& icon_grid) { 241 const base::StringValue& icon_grid) {
242 ListValue image_url_list; 242 ListValue image_url_list;
243 243
244 // First add the GAIA picture if it's available. 244 // First add the GAIA picture if it's available.
245 const ProfileInfoCache& cache = 245 const ProfileInfoCache& cache =
246 g_browser_process->profile_manager()->GetProfileInfoCache(); 246 g_browser_process->profile_manager()->GetProfileInfoCache();
247 Profile* profile = Profile::FromWebUI(web_ui()); 247 Profile* profile = Profile::FromWebUI(web_ui());
248 size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); 248
249 if (profile_index != std::string::npos) { 249 ProfileInfoEntry entry;
250 if (cache.GetInfoForProfile(profile->GetPath(), &entry)) {
250 const gfx::Image* icon = 251 const gfx::Image* icon =
251 cache.GetGAIAPictureOfProfileAtIndex(profile_index); 252 cache.GetGAIAPictureOfProfile(profile->GetPath());
252 if (icon) { 253 if (icon) {
253 gfx::Image icon2 = profiles::GetAvatarIconForWebUI(*icon, true); 254 gfx::Image icon2 = profiles::GetAvatarIconForWebUI(*icon, true);
254 gaia_picture_url_ = webui::GetBitmapDataUrl(icon2.AsBitmap()); 255 gaia_picture_url_ = webui::GetBitmapDataUrl(icon2.AsBitmap());
255 image_url_list.Append(new base::StringValue(gaia_picture_url_)); 256 image_url_list.Append(new base::StringValue(gaia_picture_url_));
256 } 257 }
257 } 258 }
258 259
259 // Next add the default avatar icons. 260 // Next add the default avatar icons.
260 for (size_t i = 0; i < ProfileInfoCache::GetDefaultAvatarIconCount(); i++) { 261 for (size_t i = 0; i < ProfileInfoCache::GetDefaultAvatarIconCount(); i++) {
261 std::string url = ProfileInfoCache::GetDefaultAvatarIconUrl(i); 262 std::string url = ProfileInfoCache::GetDefaultAvatarIconUrl(i);
262 image_url_list.Append(new base::StringValue(url)); 263 image_url_list.Append(new base::StringValue(url));
263 } 264 }
264 265
265 web_ui()->CallJavascriptFunction( 266 web_ui()->CallJavascriptFunction(
266 "ManageProfileOverlay.receiveDefaultProfileIcons", icon_grid, 267 "ManageProfileOverlay.receiveDefaultProfileIcons", icon_grid,
267 image_url_list); 268 image_url_list);
268 } 269 }
269 270
270 void ManageProfileHandler::SendProfileNames() { 271 void ManageProfileHandler::SendProfileNames() {
271 const ProfileInfoCache& cache = 272 const ProfileInfoCache& cache =
272 g_browser_process->profile_manager()->GetProfileInfoCache(); 273 g_browser_process->profile_manager()->GetProfileInfoCache();
273 DictionaryValue profile_name_dict; 274 DictionaryValue profile_name_dict;
274 for (size_t i = 0, e = cache.GetNumberOfProfiles(); i < e; ++i) 275
275 profile_name_dict.SetBoolean(UTF16ToUTF8(cache.GetNameOfProfileAtIndex(i)), 276 const std::vector<ProfileInfoEntry> entries(cache.GetProfilesSortedByName());
276 true); 277 for (std::vector<ProfileInfoEntry>::const_iterator it = entries.begin();
278 it != entries.end(); ++it) {
279 profile_name_dict.SetBoolean(UTF16ToUTF8(it->GetDisplayName()), true);
280 }
277 281
278 web_ui()->CallJavascriptFunction("ManageProfileOverlay.receiveProfileNames", 282 web_ui()->CallJavascriptFunction("ManageProfileOverlay.receiveProfileNames",
279 profile_name_dict); 283 profile_name_dict);
280 } 284 }
281 285
282 void ManageProfileHandler::SetProfileIconAndName(const ListValue* args) { 286 void ManageProfileHandler::SetProfileIconAndName(const ListValue* args) {
283 DCHECK(args); 287 DCHECK(args);
284 288
285 base::FilePath profile_file_path; 289 base::FilePath profile_file_path;
286 if (!GetProfilePathFromArgs(args, &profile_file_path)) 290 if (!GetProfilePathFromArgs(args, &profile_file_path))
287 return; 291 return;
288 292
289 ProfileInfoCache& cache = 293 ProfileInfoCache& cache =
290 g_browser_process->profile_manager()->GetProfileInfoCache(); 294 g_browser_process->profile_manager()->GetProfileInfoCache();
291 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_file_path); 295
292 if (profile_index == std::string::npos) 296 ProfileInfoEntry entry;
297 if (!cache.GetInfoForProfile(profile_file_path, &entry))
293 return; 298 return;
294 299
295 Profile* profile = 300 Profile* profile =
296 g_browser_process->profile_manager()->GetProfile(profile_file_path); 301 g_browser_process->profile_manager()->GetProfile(profile_file_path);
297 if (!profile) 302 if (!profile)
298 return; 303 return;
299 304
300 std::string icon_url; 305 std::string icon_url;
301 if (!args->GetString(1, &icon_url)) 306 if (!args->GetString(1, &icon_url))
302 return; 307 return;
303 308
304 // Metrics logging variable. 309 // Metrics logging variable.
305 bool previously_using_gaia_icon = 310 bool previously_using_gaia_icon = entry.is_using_GAIA_picture();
306 cache.IsUsingGAIAPictureOfProfileAtIndex(profile_index);
307 311
308 size_t new_icon_index; 312 size_t new_icon_index;
309 if (icon_url == gaia_picture_url_) { 313 if (icon_url == gaia_picture_url_) {
310 cache.SetIsUsingGAIAPictureOfProfileAtIndex(profile_index, true); 314 entry.set_is_using_GAIA_picture(true);
311 if (!previously_using_gaia_icon) { 315 if (!previously_using_gaia_icon) {
312 // Only log if they changed to the GAIA photo. 316 // Only log if they changed to the GAIA photo.
313 // Selection of GAIA photo as avatar is logged as part of the function 317 // Selection of GAIA photo as avatar is logged as part of the function
314 // below. 318 // below.
315 ProfileMetrics::LogProfileSwitchGaia(ProfileMetrics::GAIA_OPT_IN); 319 ProfileMetrics::LogProfileSwitchGaia(ProfileMetrics::GAIA_OPT_IN);
316 } 320 }
317 } else if (cache.IsDefaultAvatarIconUrl(icon_url, &new_icon_index)) { 321 } else if (cache.IsDefaultAvatarIconUrl(icon_url, &new_icon_index)) {
318 ProfileMetrics::LogProfileAvatarSelection(new_icon_index); 322 ProfileMetrics::LogProfileAvatarSelection(new_icon_index);
319 PrefService* pref_service = profile->GetPrefs(); 323 PrefService* pref_service = profile->GetPrefs();
320 // Updating the profile preference will cause the cache to be updated for 324 // Updating the profile preference will cause the cache to be updated for
321 // this preference. 325 // this preference.
322 pref_service->SetInteger(prefs::kProfileAvatarIndex, new_icon_index); 326 pref_service->SetInteger(prefs::kProfileAvatarIndex, new_icon_index);
323 cache.SetIsUsingGAIAPictureOfProfileAtIndex(profile_index, false); 327 entry.set_is_using_GAIA_picture(true);
324 } 328 }
325 ProfileMetrics::LogProfileUpdate(profile_file_path); 329 ProfileMetrics::LogProfileUpdate(profile_file_path);
330 cache.SetInfoForProfile(entry);
326 331
327 if (profile->IsManaged()) 332 if (profile->IsManaged())
328 return; 333 return;
329 334
330 string16 new_profile_name; 335 string16 new_profile_name;
331 if (!args->GetString(2, &new_profile_name)) 336 if (!args->GetString(2, &new_profile_name))
332 return; 337 return;
333 338
334 if ((new_profile_name == 339 if ((new_profile_name == entry.GAIA_given_name()) ||
335 cache.GetGAIAGivenNameOfProfileAtIndex(profile_index)) || 340 (new_profile_name == entry.GAIA_full_name())) {
336 (new_profile_name == cache.GetGAIANameOfProfileAtIndex(profile_index))) {
337 // Set the profile to use the GAIA name as the profile name. Note, this 341 // Set the profile to use the GAIA name as the profile name. Note, this
338 // is a little weird if the user typed their GAIA name manually but 342 // is a little weird if the user typed their GAIA name manually but
339 // it's not a big deal. 343 // it's not a big deal.
340 cache.SetIsUsingGAIANameOfProfileAtIndex(profile_index, true); 344 entry.set_is_using_GAIA_name(true);
341 } else { 345 } else {
342 PrefService* pref_service = profile->GetPrefs(); 346 PrefService* pref_service = profile->GetPrefs();
343 // Updating the profile preference will cause the cache to be updated for 347 // Updating the profile preference will cause the cache to be updated for
344 // this preference. 348 // this preference.
345 pref_service->SetString(prefs::kProfileName, UTF16ToUTF8(new_profile_name)); 349 pref_service->SetString(prefs::kProfileName, UTF16ToUTF8(new_profile_name));
346 350 entry.set_is_using_GAIA_name(false);
347 // Changing the profile name can invalidate the profile index.
348 profile_index = cache.GetIndexOfProfileWithPath(profile_file_path);
349 if (profile_index == std::string::npos)
350 return;
351
352 cache.SetIsUsingGAIANameOfProfileAtIndex(profile_index, false);
353 } 351 }
352 cache.SetInfoForProfile(entry);
354 } 353 }
355 354
356 #if defined(ENABLE_SETTINGS_APP) 355 #if defined(ENABLE_SETTINGS_APP)
357 void ManageProfileHandler::SwitchAppListProfile(const ListValue* args) { 356 void ManageProfileHandler::SwitchAppListProfile(const ListValue* args) {
358 DCHECK(args); 357 DCHECK(args);
359 DCHECK(profiles::IsMultipleProfilesEnabled()); 358 DCHECK(profiles::IsMultipleProfilesEnabled());
360 359
361 const Value* file_path_value; 360 const Value* file_path_value;
362 base::FilePath profile_file_path; 361 base::FilePath profile_file_path;
363 if (!args->Get(0, &file_path_value) || 362 if (!args->Get(0, &file_path_value) ||
(...skipping 27 matching lines...) Expand all
391 return; 390 return;
392 391
393 if (icon_url != gaia_picture_url_) 392 if (icon_url != gaia_picture_url_)
394 return; 393 return;
395 394
396 // If the selection is the GAIA picture then also show the profile name in the 395 // If the selection is the GAIA picture then also show the profile name in the
397 // text field. This will display either the GAIA given name, if available, 396 // text field. This will display either the GAIA given name, if available,
398 // or the first name. 397 // or the first name.
399 ProfileInfoCache& cache = 398 ProfileInfoCache& cache =
400 g_browser_process->profile_manager()->GetProfileInfoCache(); 399 g_browser_process->profile_manager()->GetProfileInfoCache();
401 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_file_path); 400
402 if (profile_index == std::string::npos) 401 ProfileInfoEntry entry;
402 if (!cache.GetInfoForProfile(profile_file_path, &entry))
403 return; 403 return;
404 string16 gaia_name = cache.GetNameOfProfileAtIndex(profile_index); 404
405 string16 gaia_name = entry.GetDisplayName();
405 if (gaia_name.empty()) 406 if (gaia_name.empty())
406 return; 407 return;
407 408
408 StringValue gaia_name_value(gaia_name); 409 StringValue gaia_name_value(gaia_name);
409 web_ui()->CallJavascriptFunction("ManageProfileOverlay.setProfileName", 410 web_ui()->CallJavascriptFunction("ManageProfileOverlay.setProfileName",
410 gaia_name_value); 411 gaia_name_value);
411 } 412 }
412 413
413 void ManageProfileHandler::RequestHasProfileShortcuts(const ListValue* args) { 414 void ManageProfileHandler::RequestHasProfileShortcuts(const ListValue* args) {
414 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 415 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
415 DCHECK(ProfileShortcutManager::IsFeatureEnabled()); 416 DCHECK(ProfileShortcutManager::IsFeatureEnabled());
416 417
417 base::FilePath profile_file_path; 418 base::FilePath profile_file_path;
418 if (!GetProfilePathFromArgs(args, &profile_file_path)) 419 if (!GetProfilePathFromArgs(args, &profile_file_path))
419 return; 420 return;
420 421
421 const ProfileInfoCache& cache = 422 const ProfileInfoCache& cache =
422 g_browser_process->profile_manager()->GetProfileInfoCache(); 423 g_browser_process->profile_manager()->GetProfileInfoCache();
423 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_file_path); 424
424 if (profile_index == std::string::npos) 425 ProfileInfoEntry entry;
426 if (!cache.GetInfoForProfile(profile_file_path, &entry))
425 return; 427 return;
426 428
427 const base::FilePath profile_path = 429 const base::FilePath profile_path = entry.path();
428 cache.GetPathOfProfileAtIndex(profile_index);
429 ProfileShortcutManager* shortcut_manager = 430 ProfileShortcutManager* shortcut_manager =
430 g_browser_process->profile_manager()->profile_shortcut_manager(); 431 g_browser_process->profile_manager()->profile_shortcut_manager();
431 shortcut_manager->HasProfileShortcuts( 432 shortcut_manager->HasProfileShortcuts(
432 profile_path, base::Bind(&ManageProfileHandler::OnHasProfileShortcuts, 433 profile_path, base::Bind(&ManageProfileHandler::OnHasProfileShortcuts,
433 weak_factory_.GetWeakPtr())); 434 weak_factory_.GetWeakPtr()));
434 } 435 }
435 436
436 void ManageProfileHandler::RequestCreateProfileUpdate( 437 void ManageProfileHandler::RequestCreateProfileUpdate(
437 const base::ListValue* args) { 438 const base::ListValue* args) {
438 Profile* profile = Profile::FromWebUI(web_ui()); 439 Profile* profile = Profile::FromWebUI(web_ui());
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 g_browser_process->profile_manager()->profile_shortcut_manager(); 495 g_browser_process->profile_manager()->profile_shortcut_manager();
495 DCHECK(shortcut_manager); 496 DCHECK(shortcut_manager);
496 497
497 shortcut_manager->RemoveProfileShortcuts(profile_file_path); 498 shortcut_manager->RemoveProfileShortcuts(profile_file_path);
498 499
499 // Update the UI buttons. 500 // Update the UI buttons.
500 OnHasProfileShortcuts(false); 501 OnHasProfileShortcuts(false);
501 } 502 }
502 503
503 } // namespace options 504 } // namespace options
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698