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

Side by Side Diff: chrome/browser/profiles/profile_manager.cc

Issue 7138002: Add profiles to wrench menu (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed menu item Created 9 years, 6 months 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <set> 5 #include <set>
6 6
7 #include "chrome/browser/profiles/profile_manager.h" 7 #include "chrome/browser/profiles/profile_manager.h"
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/file_path.h" 10 #include "base/file_path.h"
(...skipping 14 matching lines...) Expand all
25 #include "chrome/common/logging_chrome.h" 25 #include "chrome/common/logging_chrome.h"
26 #include "chrome/common/pref_names.h" 26 #include "chrome/common/pref_names.h"
27 #include "content/browser/browser_thread.h" 27 #include "content/browser/browser_thread.h"
28 #include "content/common/notification_service.h" 28 #include "content/common/notification_service.h"
29 #include "content/common/notification_type.h" 29 #include "content/common/notification_type.h"
30 #include "grit/generated_resources.h" 30 #include "grit/generated_resources.h"
31 #include "net/http/http_transaction_factory.h" 31 #include "net/http/http_transaction_factory.h"
32 #include "net/url_request/url_request_context.h" 32 #include "net/url_request/url_request_context.h"
33 #include "net/url_request/url_request_context_getter.h" 33 #include "net/url_request/url_request_context_getter.h"
34 #include "net/url_request/url_request_job.h" 34 #include "net/url_request/url_request_job.h"
35 #include "ui/base/l10n/l10n_util.h"
35 36
36 #if defined(OS_CHROMEOS) 37 #if defined(OS_CHROMEOS)
37 #include "chrome/browser/chromeos/cros/cros_library.h" 38 #include "chrome/browser/chromeos/cros/cros_library.h"
38 #include "chrome/browser/chromeos/cros/cryptohome_library.h" 39 #include "chrome/browser/chromeos/cros/cryptohome_library.h"
39 #endif 40 #endif
40 41
41 bool ProfileManagerObserver::DeleteAfterCreation() { 42 bool ProfileManagerObserver::DeleteAfterCreation() {
42 return false; 43 return false;
43 } 44 }
44 45
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 RegisterProfile(profile, true); 296 RegisterProfile(profile, true);
296 DoFinalInit(profile); 297 DoFinalInit(profile);
297 return true; 298 return true;
298 } 299 }
299 300
300 ProfileManager::ProfileInfo* ProfileManager::RegisterProfile(Profile* profile, 301 ProfileManager::ProfileInfo* ProfileManager::RegisterProfile(Profile* profile,
301 bool created) { 302 bool created) {
302 ProfileInfo* info = new ProfileInfo(profile, created); 303 ProfileInfo* info = new ProfileInfo(profile, created);
303 ProfilesInfoMap::iterator new_elem = 304 ProfilesInfoMap::iterator new_elem =
304 (profiles_info_.insert(std::make_pair(profile->GetPath(), info))).first; 305 (profiles_info_.insert(std::make_pair(profile->GetPath(), info))).first;
306
305 return info; 307 return info;
306 } 308 }
307 309
308 Profile* ProfileManager::GetProfileByPath(const FilePath& path) const { 310 Profile* ProfileManager::GetProfileByPath(const FilePath& path) const {
309 ProfilesInfoMap::const_iterator iter = profiles_info_.find(path); 311 ProfilesInfoMap::const_iterator iter = profiles_info_.find(path);
310 return (iter == profiles_info_.end()) ? NULL : iter->second->profile.get(); 312 return (iter == profiles_info_.end()) ? NULL : iter->second->profile.get();
311 } 313 }
312 314
313 void ProfileManager::Observe( 315 void ProfileManager::Observe(
314 NotificationType type, 316 NotificationType type,
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 NewProfileLauncher* launcher = new NewProfileLauncher(); 424 NewProfileLauncher* launcher = new NewProfileLauncher();
423 profile_manager->CreateProfileAsync(new_path, launcher); 425 profile_manager->CreateProfileAsync(new_path, launcher);
424 } 426 }
425 427
426 // static 428 // static
427 void ProfileManager::RegisterPrefs(PrefService* prefs) { 429 void ProfileManager::RegisterPrefs(PrefService* prefs) {
428 prefs->RegisterStringPref(prefs::kProfileLastUsed, ""); 430 prefs->RegisterStringPref(prefs::kProfileLastUsed, "");
429 prefs->RegisterDictionaryPref(prefs::kProfileDirectoryMap); 431 prefs->RegisterDictionaryPref(prefs::kProfileDirectoryMap);
430 prefs->RegisterIntegerPref(prefs::kProfilesNumCreated, 1); 432 prefs->RegisterIntegerPref(prefs::kProfilesNumCreated, 1);
431 } 433 }
434
435
436 size_t ProfileManager::GetNumberOfProfiles() {
437 const DictionaryValue* path_map =
438 g_browser_process->local_state()->GetDictionary(
439 prefs::kProfileDirectoryMap);
440 return path_map ? path_map->size() : 0;
441 }
442
443 string16 ProfileManager::GetNameOfProfileAtIndex(size_t index) {
444 return GetSortedProfilesFromDirectoryMap()[index].second;
445 }
446
447 FilePath ProfileManager::GetFilePathOfProfileAtIndex(
448 size_t index, const FilePath& user_data_dir) {
449 FilePath base_name = GetSortedProfilesFromDirectoryMap()[index].first;
450 return user_data_dir.Append(base_name);
451 }
452
453 bool ProfileManager::CompareProfilePathAndName(
454 const ProfileManager::ProfilePathAndName& pair1,
455 const ProfileManager::ProfilePathAndName& pair2) {
456 int name_compare = pair1.second.compare(pair2.second);
457 if (name_compare < 0) {
458 return true;
459 } else if (name_compare > 0) {
460 return false;
461 } else {
462 return pair1.first < pair2.first;
463 }
464 }
465
466 ProfileManager::ProfilePathAndNames
467 ProfileManager::GetSortedProfilesFromDirectoryMap() {
468 ProfilePathAndNames profiles;
469
470 const DictionaryValue* path_map =
471 g_browser_process->local_state()->GetDictionary(
472 prefs::kProfileDirectoryMap);
473 if (!path_map)
474 return profiles;
475
476 for (DictionaryValue::key_iterator it = path_map->begin_keys();
477 it != path_map->end_keys(); ++it) {
478 std::string name_ascii;
479 path_map->GetString(*it, &name_ascii);
480 string16 name = ASCIIToUTF16(name_ascii);
481 if (name.empty())
482 name = l10n_util::GetStringUTF16(IDS_DEFAULT_PROFILE_NAME);
483 FilePath file_path(*it);
Miranda Callahan 2011/06/11 15:09:08 I think you're going to need to handle Windows dif
sail 2011/06/13 19:00:02 Ouch, fixed. Testing on windows right now. Also,
484
485 // Pending, need to insert it alphabetically.
486 profiles.push_back(std::pair<FilePath, string16>(file_path, name));
487 }
488
489 std::sort(profiles.begin(), profiles.end(), CompareProfilePathAndName);
490 return profiles;
491 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_manager.h ('k') | chrome/browser/ui/toolbar/wrench_menu_model.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698