Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 | |
| 307 NotificationService::current()->Notify( | |
| 308 NotificationType::PROFILE_ADDED, | |
| 309 Source<Profile>(profile), | |
| 310 NotificationService::NoDetails()); | |
| 311 | |
| 305 return info; | 312 return info; |
| 306 } | 313 } |
| 307 | 314 |
| 308 Profile* ProfileManager::GetProfileByPath(const FilePath& path) const { | 315 Profile* ProfileManager::GetProfileByPath(const FilePath& path) const { |
| 309 ProfilesInfoMap::const_iterator iter = profiles_info_.find(path); | 316 ProfilesInfoMap::const_iterator iter = profiles_info_.find(path); |
| 310 return (iter == profiles_info_.end()) ? NULL : iter->second->profile.get(); | 317 return (iter == profiles_info_.end()) ? NULL : iter->second->profile.get(); |
| 311 } | 318 } |
| 312 | 319 |
| 313 void ProfileManager::Observe( | 320 void ProfileManager::Observe( |
| 314 NotificationType type, | 321 NotificationType type, |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 422 NewProfileLauncher* launcher = new NewProfileLauncher(); | 429 NewProfileLauncher* launcher = new NewProfileLauncher(); |
| 423 profile_manager->CreateProfileAsync(new_path, launcher); | 430 profile_manager->CreateProfileAsync(new_path, launcher); |
| 424 } | 431 } |
| 425 | 432 |
| 426 // static | 433 // static |
| 427 void ProfileManager::RegisterPrefs(PrefService* prefs) { | 434 void ProfileManager::RegisterPrefs(PrefService* prefs) { |
| 428 prefs->RegisterStringPref(prefs::kProfileLastUsed, ""); | 435 prefs->RegisterStringPref(prefs::kProfileLastUsed, ""); |
| 429 prefs->RegisterDictionaryPref(prefs::kProfileDirectoryMap); | 436 prefs->RegisterDictionaryPref(prefs::kProfileDirectoryMap); |
| 430 prefs->RegisterIntegerPref(prefs::kProfilesNumCreated, 1); | 437 prefs->RegisterIntegerPref(prefs::kProfilesNumCreated, 1); |
| 431 } | 438 } |
| 439 | |
| 440 | |
| 441 size_t ProfileManager::GetNumberOfProfiles() { | |
| 442 const DictionaryValue* path_map = | |
| 443 g_browser_process->local_state()->GetDictionary( | |
| 444 prefs::kProfileDirectoryMap); | |
| 445 if (path_map) | |
|
sky
2011/06/10 16:24:14
nit: return path_map ? path_map->size() : 0;
sail
2011/06/11 01:27:37
Done.
| |
| 446 return path_map->size(); | |
| 447 return 0; | |
| 448 } | |
| 449 | |
| 450 string16 ProfileManager::GetNameOfProfileAtIndex(size_t index) { | |
| 451 return GetSortedProfilesFromDirectoryMap()[index].second; | |
| 452 } | |
| 453 | |
| 454 FilePath ProfileManager::GetFilePathOfProfileAtIndex( | |
| 455 size_t index, FilePath user_data_dir) { | |
| 456 FilePath base_name = GetSortedProfilesFromDirectoryMap()[index].first; | |
| 457 return user_data_dir.Append(base_name); | |
| 458 } | |
| 459 | |
| 460 std::vector<std::pair<FilePath, string16> > | |
| 461 ProfileManager::GetSortedProfilesFromDirectoryMap() { | |
| 462 std::vector<std::pair<FilePath, string16> > profiles; | |
| 463 | |
| 464 const DictionaryValue* path_map = | |
| 465 g_browser_process->local_state()->GetDictionary( | |
| 466 prefs::kProfileDirectoryMap); | |
| 467 if (!path_map) | |
| 468 return profiles; | |
| 469 | |
| 470 for (DictionaryValue::key_iterator it = path_map->begin_keys(); | |
| 471 it != path_map->end_keys(); ++it) { | |
| 472 std::string name_ascii; | |
| 473 path_map->GetString(*it, &name_ascii); | |
| 474 string16 name = ASCIIToUTF16(name_ascii); | |
| 475 if (name.empty()) | |
| 476 name = l10n_util::GetStringUTF16(IDS_DEFAULT_PROFILE_NAME); | |
| 477 FilePath file_path(*it); | |
| 478 | |
| 479 // Pending, need to insert it alphabetically. | |
|
sky
2011/06/10 16:24:14
Pending -> TODO
sail
2011/06/11 01:27:37
Removed and added sorting.
| |
| 480 profiles.push_back(std::pair<FilePath, string16>(file_path, name)); | |
| 481 } | |
| 482 | |
| 483 return profiles; | |
| 484 } | |
| OLD | NEW |