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 "chrome/browser/profiles/avatar_menu_model.h" | 5 #include "chrome/browser/profiles/avatar_menu_model.h" |
6 | 6 |
| 7 #include "base/bind.h" |
7 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
8 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
9 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/profiles/avatar_menu_model_observer.h" | 11 #include "chrome/browser/profiles/avatar_menu_model_observer.h" |
11 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/profiles/profile_info_cache.h" | 13 #include "chrome/browser/profiles/profile_info_cache.h" |
13 #include "chrome/browser/profiles/profile_info_util.h" | 14 #include "chrome/browser/profiles/profile_info_util.h" |
14 #include "chrome/browser/profiles/profile_manager.h" | 15 #include "chrome/browser/profiles/profile_manager.h" |
15 #include "chrome/browser/profiles/profile_metrics.h" | 16 #include "chrome/browser/profiles/profile_metrics.h" |
16 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
17 #include "chrome/browser/ui/browser_init.h" | 18 #include "chrome/browser/ui/browser_init.h" |
18 #include "chrome/browser/ui/browser_list.h" | 19 #include "chrome/browser/ui/browser_list.h" |
19 #include "chrome/browser/ui/browser_window.h" | 20 #include "chrome/browser/ui/browser_window.h" |
20 #include "chrome/common/chrome_notification_types.h" | 21 #include "chrome/common/chrome_notification_types.h" |
21 #include "chrome/common/url_constants.h" | 22 #include "chrome/common/url_constants.h" |
22 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
23 #include "grit/generated_resources.h" | 24 #include "grit/generated_resources.h" |
24 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
25 | 26 |
26 using content::BrowserThread; | 27 using content::BrowserThread; |
27 | 28 |
28 namespace { | 29 namespace { |
29 | 30 |
30 class ProfileSwitchObserver : public ProfileManagerObserver { | 31 void OnProfileCreated(Profile* profile, |
31 public: | 32 Profile::CreateStatus status) { |
32 virtual void OnProfileCreated(Profile* profile, Status status) OVERRIDE { | 33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
34 | 34 |
35 if (status == STATUS_INITIALIZED) { | 35 if (status == Profile::CREATE_STATUS_INITIALIZED) { |
36 ProfileManager::NewWindowWithProfile(profile, | 36 ProfileManager::NewWindowWithProfile(profile, |
37 BrowserInit::IS_NOT_PROCESS_STARTUP, | 37 BrowserInit::IS_NOT_PROCESS_STARTUP, |
38 BrowserInit::IS_NOT_FIRST_RUN); | 38 BrowserInit::IS_NOT_FIRST_RUN); |
39 } | |
40 } | 39 } |
41 | 40 } |
42 virtual bool DeleteAfter() OVERRIDE { return true; } | |
43 }; | |
44 | 41 |
45 } // namespace | 42 } // namespace |
46 | 43 |
47 AvatarMenuModel::AvatarMenuModel(ProfileInfoInterface* profile_cache, | 44 AvatarMenuModel::AvatarMenuModel(ProfileInfoInterface* profile_cache, |
48 AvatarMenuModelObserver* observer, | 45 AvatarMenuModelObserver* observer, |
49 Browser* browser) | 46 Browser* browser) |
50 : profile_info_(profile_cache), | 47 : profile_info_(profile_cache), |
51 observer_(observer), | 48 observer_(observer), |
52 browser_(browser) { | 49 browser_(browser) { |
53 DCHECK(profile_info_); | 50 DCHECK(profile_info_); |
(...skipping 17 matching lines...) Expand all Loading... |
71 active(false), | 68 active(false), |
72 model_index(model_index) { | 69 model_index(model_index) { |
73 } | 70 } |
74 | 71 |
75 AvatarMenuModel::Item::~Item() { | 72 AvatarMenuModel::Item::~Item() { |
76 } | 73 } |
77 | 74 |
78 void AvatarMenuModel::SwitchToProfile(size_t index) { | 75 void AvatarMenuModel::SwitchToProfile(size_t index) { |
79 const Item& item = GetItemAt(index); | 76 const Item& item = GetItemAt(index); |
80 FilePath path = profile_info_->GetPathOfProfileAtIndex(item.model_index); | 77 FilePath path = profile_info_->GetPathOfProfileAtIndex(item.model_index); |
| 78 g_browser_process->profile_manager()->CreateProfileAsync( |
| 79 path, base::Bind(&OnProfileCreated)); |
81 | 80 |
82 // This will be deleted by the manager after the profile is ready. | |
83 ProfileSwitchObserver* observer = new ProfileSwitchObserver(); | |
84 g_browser_process->profile_manager()->CreateProfileAsync( | |
85 path, observer); | |
86 ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::SWITCH_PROFILE_ICON); | 81 ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::SWITCH_PROFILE_ICON); |
87 } | 82 } |
88 | 83 |
89 void AvatarMenuModel::EditProfile(size_t index) { | 84 void AvatarMenuModel::EditProfile(size_t index) { |
90 Browser* browser = browser_; | 85 Browser* browser = browser_; |
91 if (!browser) { | 86 if (!browser) { |
92 Profile* profile = g_browser_process->profile_manager()->GetProfileByPath( | 87 Profile* profile = g_browser_process->profile_manager()->GetProfileByPath( |
93 profile_info_->GetPathOfProfileAtIndex(GetItemAt(index).model_index)); | 88 profile_info_->GetPathOfProfileAtIndex(GetItemAt(index).model_index)); |
94 browser = Browser::Create(profile); | 89 browser = Browser::Create(profile); |
95 } | 90 } |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 item->active = browser_->profile()->GetPath() == path; | 164 item->active = browser_->profile()->GetPath() == path; |
170 } | 165 } |
171 items_.push_back(item); | 166 items_.push_back(item); |
172 } | 167 } |
173 } | 168 } |
174 | 169 |
175 void AvatarMenuModel::ClearMenu() { | 170 void AvatarMenuModel::ClearMenu() { |
176 STLDeleteContainerPointers(items_.begin(), items_.end()); | 171 STLDeleteContainerPointers(items_.begin(), items_.end()); |
177 items_.clear(); | 172 items_.clear(); |
178 } | 173 } |
OLD | NEW |