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

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: Add profiles to wrench menu 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 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, const FilePath& user_data_dir) {
sky 2011/06/13 23:15:15 each param on its own line.
sail 2011/06/13 23:26:12 Done.
451 FilePath base_name = GetSortedProfilesFromDirectoryMap()[index].first;
452 return user_data_dir.Append(base_name);
453 }
454
455 bool ProfileManager::CompareProfilePathAndName(
456 const ProfileManager::ProfilePathAndName& pair1,
457 const ProfileManager::ProfilePathAndName& pair2) {
458 int name_compare = pair1.second.compare(pair2.second);
459 if (name_compare < 0) {
460 return true;
461 } else if (name_compare > 0) {
462 return false;
463 } else {
464 return pair1.first < pair2.first;
465 }
466 }
467
468 ProfileManager::ProfilePathAndNames
469 ProfileManager::GetSortedProfilesFromDirectoryMap() {
470 ProfilePathAndNames profiles;
471
472 const DictionaryValue* path_map =
473 g_browser_process->local_state()->GetDictionary(
474 prefs::kProfileDirectoryMap);
475 if (!path_map)
476 return profiles;
477
478 for (DictionaryValue::key_iterator it = path_map->begin_keys();
479 it != path_map->end_keys(); ++it) {
480 std::string name_ascii;
481 path_map->GetString(*it, &name_ascii);
482 string16 name = ASCIIToUTF16(name_ascii);
483 if (name.empty())
484 name = l10n_util::GetStringUTF16(IDS_DEFAULT_PROFILE_NAME);
485 #if defined(OS_POSIX)
486 FilePath file_path(*it);
487 #elif defined(OS_WIN)
488 FilePath file_path(ASCIIToWide(*it));
489 #endif
490
491 // Pending, need to insert it alphabetically.
492 profiles.push_back(std::pair<FilePath, string16>(file_path, name));
493 }
494
495 std::sort(profiles.begin(), profiles.end(), CompareProfilePathAndName);
496 return profiles;
497 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698