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" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
13 #include "base/string_number_conversions.h" | 13 #include "base/string_number_conversions.h" |
14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
17 #include "chrome/browser/prefs/pref_service.h" | 17 #include "chrome/browser/prefs/pref_service.h" |
18 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 18 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
19 #include "chrome/browser/profiles/profile_info_cache.h" | 19 #include "chrome/browser/profiles/profile_info_cache.h" |
20 #include "chrome/browser/sessions/session_service_factory.h" | 20 #include "chrome/browser/sessions/session_service_factory.h" |
21 #include "chrome/browser/sync/profile_sync_service.h" | 21 #include "chrome/browser/sync/profile_sync_service.h" |
22 #include "chrome/browser/ui/browser_window.h" | 22 #include "chrome/browser/ui/browser_window.h" |
23 #include "chrome/common/chrome_constants.h" | 23 #include "chrome/common/chrome_constants.h" |
24 #include "chrome/common/chrome_paths.h" | 24 #include "chrome/common/chrome_paths.h" |
25 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
26 #include "chrome/common/logging_chrome.h" | 26 #include "chrome/common/logging_chrome.h" |
27 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
| 28 #include "chrome/common/url_constants.h" |
28 #include "content/browser/browser_thread.h" | 29 #include "content/browser/browser_thread.h" |
29 #include "content/common/notification_service.h" | 30 #include "content/common/notification_service.h" |
30 #include "content/common/notification_type.h" | 31 #include "content/common/notification_type.h" |
31 #include "grit/generated_resources.h" | 32 #include "grit/generated_resources.h" |
32 #include "net/http/http_transaction_factory.h" | 33 #include "net/http/http_transaction_factory.h" |
33 #include "net/url_request/url_request_context.h" | 34 #include "net/url_request/url_request_context.h" |
34 #include "net/url_request/url_request_context_getter.h" | 35 #include "net/url_request/url_request_context_getter.h" |
35 #include "net/url_request/url_request_job.h" | 36 #include "net/url_request/url_request_job.h" |
36 #include "ui/base/l10n/l10n_util.h" | 37 #include "ui/base/l10n/l10n_util.h" |
37 | 38 |
38 #if defined(OS_CHROMEOS) | 39 #if defined(OS_CHROMEOS) |
39 #include "chrome/browser/chromeos/cros/cros_library.h" | 40 #include "chrome/browser/chromeos/cros/cros_library.h" |
40 #include "chrome/browser/chromeos/cros/cryptohome_library.h" | 41 #include "chrome/browser/chromeos/cros/cryptohome_library.h" |
41 #endif | 42 #endif |
42 | 43 |
43 bool ProfileManagerObserver::DeleteAfterCreation() { | 44 bool ProfileManagerObserver::DeleteAfterCreation() { |
44 return false; | 45 return false; |
45 } | 46 } |
46 | 47 |
47 // The NewProfileLauncher class is created when to wait for a multi-profile | 48 // The NewProfileLauncher class is created when to wait for a multi-profile |
48 // to be created asynchronously. Upon completion of profile creation, the | 49 // to be created asynchronously. Upon completion of profile creation, the |
49 // NPL takes care of launching a new browser window and signing the user | 50 // NPL takes care of launching a new browser window and signing the user |
50 // in to their Google account. | 51 // in to their Google account. |
51 class NewProfileLauncher : public ProfileManagerObserver { | 52 class NewProfileLauncher : public ProfileManagerObserver { |
52 public: | 53 public: |
53 virtual void OnProfileCreated(Profile* profile) { | 54 virtual void OnProfileCreated(Profile* profile) { |
54 Browser::NewWindowWithProfile(profile); | 55 Browser* browser = Browser::Create(profile); |
55 ProfileSyncService* service = profile->GetProfileSyncService(); | 56 browser->AddSelectedTabWithURL(GURL(chrome::kChromeUINewProfile), |
56 DCHECK(service); | 57 PageTransition::LINK); |
57 service->ShowLoginDialog(); | 58 browser->window()->Show(); |
58 ProfileSyncService::SyncEvent(ProfileSyncService::START_FROM_PROFILE_MENU); | |
59 } | 59 } |
60 | 60 |
61 virtual bool DeleteAfterCreation() OVERRIDE { return true; } | 61 virtual bool DeleteAfterCreation() OVERRIDE { return true; } |
62 }; | 62 }; |
63 | 63 |
64 // static | 64 // static |
65 void ProfileManager::ShutdownSessionServices() { | 65 void ProfileManager::ShutdownSessionServices() { |
66 ProfileManager* pm = g_browser_process->profile_manager(); | 66 ProfileManager* pm = g_browser_process->profile_manager(); |
67 if (!pm) // Is NULL when running unit tests. | 67 if (!pm) // Is NULL when running unit tests. |
68 return; | 68 return; |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 if (!logged_in_ && | 362 if (!logged_in_ && |
363 (!command_line.HasSwitch(switches::kTestType) || | 363 (!command_line.HasSwitch(switches::kTestType) || |
364 command_line.HasSwitch(switches::kLoginProfile))) { | 364 command_line.HasSwitch(switches::kLoginProfile))) { |
365 init_extensions = false; | 365 init_extensions = false; |
366 } | 366 } |
367 #endif | 367 #endif |
368 profile->InitExtensions(init_extensions); | 368 profile->InitExtensions(init_extensions); |
369 | 369 |
370 if (!command_line.HasSwitch(switches::kDisableWebResources)) | 370 if (!command_line.HasSwitch(switches::kDisableWebResources)) |
371 profile->InitPromoResources(); | 371 profile->InitPromoResources(); |
| 372 |
| 373 AddProfileToCache(profile); |
372 } | 374 } |
373 | 375 |
374 void ProfileManager::OnProfileCreated(Profile* profile, bool success) { | 376 void ProfileManager::OnProfileCreated(Profile* profile, bool success) { |
375 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 377 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
376 | 378 |
377 ProfilesInfoMap::iterator iter = profiles_info_.find(profile->GetPath()); | 379 ProfilesInfoMap::iterator iter = profiles_info_.find(profile->GetPath()); |
378 DCHECK(iter != profiles_info_.end()); | 380 DCHECK(iter != profiles_info_.end()); |
379 ProfileInfo* info = iter->second.get(); | 381 ProfileInfo* info = iter->second.get(); |
380 | 382 |
381 std::vector<ProfileManagerObserver*> observers; | 383 std::vector<ProfileManagerObserver*> observers; |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 | 508 |
507 ProfileInfoCache& ProfileManager::GetProfileInfoCache() { | 509 ProfileInfoCache& ProfileManager::GetProfileInfoCache() { |
508 if (!profile_info_cache_.get()) { | 510 if (!profile_info_cache_.get()) { |
509 FilePath user_data_dir; | 511 FilePath user_data_dir; |
510 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | 512 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
511 profile_info_cache_.reset(new ProfileInfoCache( | 513 profile_info_cache_.reset(new ProfileInfoCache( |
512 g_browser_process->local_state(), user_data_dir)); | 514 g_browser_process->local_state(), user_data_dir)); |
513 } | 515 } |
514 return *profile_info_cache_.get(); | 516 return *profile_info_cache_.get(); |
515 } | 517 } |
| 518 |
| 519 void ProfileManager::AddProfileToCache(Profile* profile) { |
| 520 ProfileInfoCache& cache = GetProfileInfoCache(); |
| 521 if (profile->GetPath().DirName() != cache.GetUserDataDir()) |
| 522 return; |
| 523 |
| 524 if (cache.GetIndexOfProfileWithPath(profile->GetPath()) != std::string::npos) |
| 525 return; |
| 526 |
| 527 if (profile->GetPath() == GetDefaultProfileDir(cache.GetUserDataDir())) { |
| 528 cache.AddProfileToCache( |
| 529 profile->GetPath(), |
| 530 l10n_util::GetStringUTF16(IDS_DEFAULT_PROFILE_NAME), 0); |
| 531 } else { |
| 532 cache.AddProfileToCache( |
| 533 profile->GetPath(), |
| 534 cache.ChooseNameForNewProfile(), |
| 535 cache.ChooseAvatarIconIndexForNewProfile()); |
| 536 } |
| 537 } |
OLD | NEW |