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

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: '' 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
« no previous file with comments | « chrome/browser/profiles/profile_manager.h ('k') | chrome/browser/ui/profile_menu_model.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 245
245 void ProfileManager::CreateProfileAsync(const FilePath& user_data_dir, 246 void ProfileManager::CreateProfileAsync(const FilePath& user_data_dir,
246 ProfileManagerObserver* observer) { 247 ProfileManagerObserver* observer) {
247 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 248 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
248 ProfilesInfoMap::iterator iter = profiles_info_.find(user_data_dir); 249 ProfilesInfoMap::iterator iter = profiles_info_.find(user_data_dir);
249 if (iter != profiles_info_.end()) { 250 if (iter != profiles_info_.end()) {
250 ProfileInfo* info = iter->second.get(); 251 ProfileInfo* info = iter->second.get();
251 if (info->created) { 252 if (info->created) {
252 // Profile has already been created. Call observer immediately. 253 // Profile has already been created. Call observer immediately.
253 observer->OnProfileCreated(info->profile.get()); 254 observer->OnProfileCreated(info->profile.get());
255 if (observer->DeleteAfterCreation())
256 delete observer;
254 } else { 257 } else {
255 // Profile is being created. Add observer to list. 258 // Profile is being created. Add observer to list.
256 info->observers.push_back(observer); 259 info->observers.push_back(observer);
257 } 260 }
258 } else { 261 } else {
259 // Initiate asynchronous creation process. 262 // Initiate asynchronous creation process.
260 ProfileInfo* info = 263 ProfileInfo* info =
261 RegisterProfile(Profile::CreateProfileAsync(user_data_dir, this), 264 RegisterProfile(Profile::CreateProfileAsync(user_data_dir, this),
262 false); 265 false);
263 info->observers.push_back(observer); 266 info->observers.push_back(observer);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 RegisterProfile(profile, true); 298 RegisterProfile(profile, true);
296 DoFinalInit(profile); 299 DoFinalInit(profile);
297 return true; 300 return true;
298 } 301 }
299 302
300 ProfileManager::ProfileInfo* ProfileManager::RegisterProfile(Profile* profile, 303 ProfileManager::ProfileInfo* ProfileManager::RegisterProfile(Profile* profile,
301 bool created) { 304 bool created) {
302 ProfileInfo* info = new ProfileInfo(profile, created); 305 ProfileInfo* info = new ProfileInfo(profile, created);
303 ProfilesInfoMap::iterator new_elem = 306 ProfilesInfoMap::iterator new_elem =
304 (profiles_info_.insert(std::make_pair(profile->GetPath(), info))).first; 307 (profiles_info_.insert(std::make_pair(profile->GetPath(), info))).first;
308
305 return info; 309 return info;
306 } 310 }
307 311
308 Profile* ProfileManager::GetProfileByPath(const FilePath& path) const { 312 Profile* ProfileManager::GetProfileByPath(const FilePath& path) const {
309 ProfilesInfoMap::const_iterator iter = profiles_info_.find(path); 313 ProfilesInfoMap::const_iterator iter = profiles_info_.find(path);
310 return (iter == profiles_info_.end()) ? NULL : iter->second->profile.get(); 314 return (iter == profiles_info_.end()) ? NULL : iter->second->profile.get();
311 } 315 }
312 316
313 void ProfileManager::Observe( 317 void ProfileManager::Observe(
314 NotificationType type, 318 NotificationType type,
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 NewProfileLauncher* launcher = new NewProfileLauncher(); 426 NewProfileLauncher* launcher = new NewProfileLauncher();
423 profile_manager->CreateProfileAsync(new_path, launcher); 427 profile_manager->CreateProfileAsync(new_path, launcher);
424 } 428 }
425 429
426 // static 430 // static
427 void ProfileManager::RegisterPrefs(PrefService* prefs) { 431 void ProfileManager::RegisterPrefs(PrefService* prefs) {
428 prefs->RegisterStringPref(prefs::kProfileLastUsed, ""); 432 prefs->RegisterStringPref(prefs::kProfileLastUsed, "");
429 prefs->RegisterDictionaryPref(prefs::kProfileDirectoryMap); 433 prefs->RegisterDictionaryPref(prefs::kProfileDirectoryMap);
430 prefs->RegisterIntegerPref(prefs::kProfilesNumCreated, 1); 434 prefs->RegisterIntegerPref(prefs::kProfilesNumCreated, 1);
431 } 435 }
436
437
438 size_t ProfileManager::GetNumberOfProfiles() {
439 const DictionaryValue* path_map =
440 g_browser_process->local_state()->GetDictionary(
441 prefs::kProfileDirectoryMap);
442 return path_map ? path_map->size() : 0;
443 }
444
445 string16 ProfileManager::GetNameOfProfileAtIndex(size_t index) {
446 return GetSortedProfilesFromDirectoryMap()[index].second;
447 }
448
449 FilePath ProfileManager::GetFilePathOfProfileAtIndex(
450 size_t index,
451 const FilePath& user_data_dir) {
452 FilePath base_name = GetSortedProfilesFromDirectoryMap()[index].first;
453 return user_data_dir.Append(base_name);
454 }
455
456 bool ProfileManager::CompareProfilePathAndName(
457 const ProfileManager::ProfilePathAndName& pair1,
458 const ProfileManager::ProfilePathAndName& pair2) {
459 int name_compare = pair1.second.compare(pair2.second);
460 if (name_compare < 0) {
461 return true;
462 } else if (name_compare > 0) {
463 return false;
464 } else {
465 return pair1.first < pair2.first;
466 }
467 }
468
469 ProfileManager::ProfilePathAndNames
470 ProfileManager::GetSortedProfilesFromDirectoryMap() {
471 ProfilePathAndNames profiles;
472
473 const DictionaryValue* path_map =
474 g_browser_process->local_state()->GetDictionary(
475 prefs::kProfileDirectoryMap);
476 if (!path_map)
477 return profiles;
478
479 for (DictionaryValue::key_iterator it = path_map->begin_keys();
480 it != path_map->end_keys(); ++it) {
481 std::string name_ascii;
482 path_map->GetString(*it, &name_ascii);
483 string16 name = ASCIIToUTF16(name_ascii);
484 if (name.empty())
485 name = l10n_util::GetStringUTF16(IDS_DEFAULT_PROFILE_NAME);
486 #if defined(OS_POSIX)
487 FilePath file_path(*it);
488 #elif defined(OS_WIN)
489 FilePath file_path(ASCIIToWide(*it));
490 #endif
491
492 // Pending, need to insert it alphabetically.
493 profiles.push_back(std::pair<FilePath, string16>(file_path, name));
494 }
495
496 std::sort(profiles.begin(), profiles.end(), CompareProfilePathAndName);
497 return profiles;
498 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_manager.h ('k') | chrome/browser/ui/profile_menu_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698