OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/app_list/app_list_view_delegate.h" | 5 #include "chrome/browser/ui/app_list/app_list_view_delegate.h" |
6 | 6 |
7 #include <vector> | |
8 | |
7 #include "base/callback.h" | 9 #include "base/callback.h" |
8 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/stl_util.h" | |
9 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
11 #include "chrome/browser/extensions/extension_service.h" | 14 #include "chrome/browser/extensions/extension_service.h" |
12 #include "chrome/browser/feedback/feedback_util.h" | 15 #include "chrome/browser/feedback/feedback_util.h" |
16 #include "chrome/browser/profiles/profile_info_cache.h" | |
13 #include "chrome/browser/profiles/profile_manager.h" | 17 #include "chrome/browser/profiles/profile_manager.h" |
14 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" | 18 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" |
15 #include "chrome/browser/ui/app_list/apps_model_builder.h" | 19 #include "chrome/browser/ui/app_list/apps_model_builder.h" |
16 #include "chrome/browser/ui/app_list/chrome_app_list_item.h" | 20 #include "chrome/browser/ui/app_list/chrome_app_list_item.h" |
17 #include "chrome/browser/ui/app_list/chrome_signin_delegate.h" | |
18 #include "chrome/browser/ui/app_list/search/search_controller.h" | 21 #include "chrome/browser/ui/app_list/search/search_controller.h" |
19 #include "chrome/browser/ui/browser_finder.h" | 22 #include "chrome/browser/ui/browser_finder.h" |
20 #include "chrome/browser/ui/chrome_pages.h" | 23 #include "chrome/browser/ui/chrome_pages.h" |
21 #include "chrome/browser/ui/host_desktop.h" | 24 #include "chrome/browser/ui/host_desktop.h" |
22 #include "chrome/browser/ui/web_applications/web_app_ui.h" | 25 #include "chrome/browser/ui/web_applications/web_app_ui.h" |
23 #include "chrome/browser/web_applications/web_app.h" | 26 #include "chrome/browser/web_applications/web_app.h" |
24 #include "chrome/common/extensions/extension_constants.h" | 27 #include "chrome/common/extensions/extension_constants.h" |
25 #include "chrome/common/url_constants.h" | 28 #include "chrome/common/url_constants.h" |
26 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
27 #include "content/public/browser/notification_source.h" | 30 #include "content/public/browser/notification_source.h" |
28 #include "content/public/browser/page_navigator.h" | 31 #include "content/public/browser/page_navigator.h" |
29 #include "content/public/browser/user_metrics.h" | 32 #include "content/public/browser/user_metrics.h" |
33 #include "ui/app_list/search_box_model.h" | |
30 | 34 |
31 #if defined(USE_ASH) | 35 #if defined(USE_ASH) |
32 #include "chrome/browser/ui/ash/app_list/app_sync_ui_state_watcher.h" | 36 #include "chrome/browser/ui/ash/app_list/app_sync_ui_state_watcher.h" |
33 #endif | 37 #endif |
34 | 38 |
35 #if defined(OS_WIN) | 39 #if defined(OS_WIN) |
36 #include "chrome/browser/web_applications/web_app_win.h" | 40 #include "chrome/browser/web_applications/web_app_win.h" |
37 #endif | 41 #endif |
38 | 42 |
39 namespace { | 43 namespace { |
40 | 44 |
41 #if defined(OS_WIN) | 45 #if defined(OS_WIN) |
42 void CreateShortcutInWebAppDir( | 46 void CreateShortcutInWebAppDir( |
43 const base::FilePath& app_data_dir, | 47 const base::FilePath& app_data_dir, |
44 base::Callback<void(const base::FilePath&)> callback, | 48 base::Callback<void(const base::FilePath&)> callback, |
45 const ShellIntegration::ShortcutInfo& info) { | 49 const ShellIntegration::ShortcutInfo& info) { |
46 content::BrowserThread::PostTaskAndReplyWithResult( | 50 content::BrowserThread::PostTaskAndReplyWithResult( |
47 content::BrowserThread::FILE, | 51 content::BrowserThread::FILE, |
48 FROM_HERE, | 52 FROM_HERE, |
49 base::Bind(web_app::CreateShortcutInWebAppDir, app_data_dir, info), | 53 base::Bind(web_app::CreateShortcutInWebAppDir, app_data_dir, info), |
50 callback); | 54 callback); |
51 } | 55 } |
52 #endif | 56 #endif |
53 | 57 |
58 void PopulateUsers(const ProfileInfoCache& profile_info, | |
59 const base::FilePath& active_profile_path, | |
60 app_list::AppListModel::Users* users) { | |
61 const size_t count = profile_info.GetNumberOfProfiles(); | |
62 for (size_t i = 0; i < count; ++i) { | |
63 app_list::AppListModel::User user; | |
64 user.name = profile_info.GetNameOfProfileAtIndex(i); | |
65 user.email = profile_info.GetUserNameOfProfileAtIndex(i); | |
66 user.profile_path = profile_info.GetPathOfProfileAtIndex(i); | |
67 user.active = active_profile_path == user.profile_path; | |
68 users->push_back(user); | |
69 } | |
70 } | |
71 | |
54 } // namespace | 72 } // namespace |
55 | 73 |
56 AppListViewDelegate::AppListViewDelegate(AppListControllerDelegate* controller, | 74 AppListViewDelegate::AppListViewDelegate(AppListControllerDelegate* controller, |
57 Profile* profile) | 75 Profile* profile) |
58 : controller_(controller), | 76 : controller_(controller), |
59 profile_(profile), | 77 profile_(profile), |
60 model_(NULL) { | 78 model_(NULL) { |
61 DCHECK(profile_); | 79 RegisterForNotifications(); |
62 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, | |
63 content::Source<Profile>(profile_)); | |
64 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED, | |
65 content::Source<Profile>(profile_)); | |
66 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNED_OUT, | |
67 content::Source<Profile>(profile_)); | |
68 g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver(this); | 80 g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver(this); |
69 } | 81 } |
70 | 82 |
71 AppListViewDelegate::~AppListViewDelegate() { | 83 AppListViewDelegate::~AppListViewDelegate() { |
72 g_browser_process-> | 84 g_browser_process-> |
73 profile_manager()->GetProfileInfoCache().RemoveObserver(this); | 85 profile_manager()->GetProfileInfoCache().RemoveObserver(this); |
74 } | 86 } |
75 | 87 |
88 void AppListViewDelegate::RegisterForNotifications() { | |
89 registrar_.RemoveAll(); | |
90 DCHECK(profile_); | |
91 | |
92 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, | |
93 content::Source<Profile>(profile_)); | |
94 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED, | |
95 content::Source<Profile>(profile_)); | |
96 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNED_OUT, | |
97 content::Source<Profile>(profile_)); | |
98 } | |
99 | |
76 void AppListViewDelegate::OnProfileChanged() { | 100 void AppListViewDelegate::OnProfileChanged() { |
77 model_->SetSignedIn(!signin_delegate_->NeedSignin()); | 101 search_controller_.reset(new app_list::SearchController( |
78 ProfileInfoCache& cache = | 102 profile_, model_->search_box(), model_->results(), controller_.get())); |
79 g_browser_process->profile_manager()->GetProfileInfoCache(); | 103 |
80 // Populate the current user details. | 104 signin_delegate_.SetProfile(profile_); |
81 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); | 105 |
82 // The profile won't exist in the cache if the current app list profile is | 106 #if defined(USE_ASH) |
83 // being deleted. | 107 app_sync_ui_state_watcher_.reset(new AppSyncUIStateWatcher(profile_, |
84 if (profile_index == std::string::npos) | 108 model_)); |
109 #endif | |
110 | |
111 model_->SetSignedIn(!GetSigninDelegate()->NeedSignin()); | |
112 | |
113 // Don't populate the app list users if we are on the ash desktop. | |
114 if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH) | |
tapted
2013/09/19 06:03:21
GetActiveDesktop is recommended as a last-resort.
calamity
2013/09/19 08:15:25
Done.
| |
85 return; | 115 return; |
86 | 116 |
87 model_->SetCurrentUser(cache.GetNameOfProfileAtIndex(profile_index), | 117 // Populate the app list users. |
88 cache.GetUserNameOfProfileAtIndex(profile_index)); | 118 app_list::AppListModel::Users users; |
119 PopulateUsers(g_browser_process->profile_manager()->GetProfileInfoCache(), | |
120 profile_->GetPath(), &users); | |
121 model_->SetUsers(users); | |
89 } | 122 } |
90 | 123 |
91 void AppListViewDelegate::SetModel(app_list::AppListModel* model) { | 124 void AppListViewDelegate::SetProfileByPath(const base::FilePath& profile_path) { |
tapted
2013/09/19 06:03:21
If true (pretty sure it is!), I think this method
calamity
2013/09/19 08:15:25
Added comment to ui/app_list/app_list_view_delegat
| |
92 if (model) { | 125 DCHECK(model_); |
93 model_ = model; | |
94 apps_builder_.reset(new AppsModelBuilder(profile_, | |
95 model->apps(), | |
96 controller_.get())); | |
97 apps_builder_->Build(); | |
98 | 126 |
99 search_controller_.reset(new app_list::SearchController( | 127 // The profile must be loaded before this is called. |
100 profile_, model->search_box(), model->results(), controller_.get())); | 128 profile_ = |
129 g_browser_process->profile_manager()->GetProfileByPath(profile_path); | |
130 DCHECK(profile_); | |
101 | 131 |
102 signin_delegate_.reset(new ChromeSigninDelegate(profile_)); | 132 RegisterForNotifications(); |
103 | 133 |
104 #if defined(USE_ASH) | 134 apps_builder_->SwitchProfile(profile_); |
105 app_sync_ui_state_watcher_.reset(new AppSyncUIStateWatcher(profile_, | 135 |
106 model)); | 136 OnProfileChanged(); |
107 #endif | 137 |
108 OnProfileChanged(); | 138 // Clear search query. |
109 } else { | 139 model_->search_box()->SetText(base::string16()); |
110 model_ = NULL; | 140 } |
111 apps_builder_.reset(); | 141 |
112 search_controller_.reset(); | 142 void AppListViewDelegate::InitModel(app_list::AppListModel* model) { |
113 signin_delegate_.reset(); | 143 DCHECK(!model_); |
114 #if defined(USE_ASH) | 144 DCHECK(model); |
115 app_sync_ui_state_watcher_.reset(); | 145 model_ = model; |
116 #endif | 146 |
117 } | 147 // Initialize apps model. |
148 apps_builder_.reset(new AppsModelBuilder(profile_, | |
149 model->apps(), | |
150 controller_.get())); | |
151 | |
152 // Initialize the profile information in the app list menu. | |
153 OnProfileChanged(); | |
118 } | 154 } |
119 | 155 |
120 app_list::SigninDelegate* AppListViewDelegate::GetSigninDelegate() { | 156 app_list::SigninDelegate* AppListViewDelegate::GetSigninDelegate() { |
121 return signin_delegate_.get(); | 157 return &signin_delegate_; |
122 } | 158 } |
123 | 159 |
124 void AppListViewDelegate::ActivateAppListItem( | 160 void AppListViewDelegate::ActivateAppListItem( |
125 app_list::AppListItemModel* item, | 161 app_list::AppListItemModel* item, |
126 int event_flags) { | 162 int event_flags) { |
127 content::RecordAction(content::UserMetricsAction("AppList_ClickOnApp")); | 163 content::RecordAction(content::UserMetricsAction("AppList_ClickOnApp")); |
128 static_cast<ChromeAppListItem*>(item)->Activate(event_flags); | 164 static_cast<ChromeAppListItem*>(item)->Activate(event_flags); |
129 } | 165 } |
130 | 166 |
131 void AppListViewDelegate::GetShortcutPathForApp( | 167 void AppListViewDelegate::GetShortcutPathForApp( |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
213 | 249 |
214 void AppListViewDelegate::OpenFeedback() { | 250 void AppListViewDelegate::OpenFeedback() { |
215 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow( | 251 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow( |
216 controller_->GetAppListWindow()); | 252 controller_->GetAppListWindow()); |
217 Browser* browser = chrome::FindOrCreateTabbedBrowser( | 253 Browser* browser = chrome::FindOrCreateTabbedBrowser( |
218 profile_, desktop); | 254 profile_, desktop); |
219 chrome::ShowFeedbackPage(browser, std::string(), | 255 chrome::ShowFeedbackPage(browser, std::string(), |
220 chrome::kAppLauncherCategoryTag); | 256 chrome::kAppLauncherCategoryTag); |
221 } | 257 } |
222 | 258 |
259 void AppListViewDelegate::ShowForProfileByPath( | |
260 const base::FilePath& profile_path) { | |
261 controller_->ShowForProfileByPath(profile_path); | |
262 } | |
263 | |
223 void AppListViewDelegate::Observe( | 264 void AppListViewDelegate::Observe( |
224 int type, | 265 int type, |
225 const content::NotificationSource& source, | 266 const content::NotificationSource& source, |
226 const content::NotificationDetails& details) { | 267 const content::NotificationDetails& details) { |
227 OnProfileChanged(); | 268 OnProfileChanged(); |
228 } | 269 } |
229 | 270 |
271 void AppListViewDelegate::OnProfileAdded(const base::FilePath& profile_path) { | |
272 OnProfileChanged(); | |
273 } | |
274 | |
230 void AppListViewDelegate::OnProfileNameChanged( | 275 void AppListViewDelegate::OnProfileNameChanged( |
231 const base::FilePath& profile_path, | 276 const base::FilePath& profile_path, |
232 const base::string16& old_profile_name) { | 277 const base::string16& old_profile_name) { |
233 if (profile_->GetPath() != profile_path) | |
234 return; | |
235 | |
236 OnProfileChanged(); | 278 OnProfileChanged(); |
237 } | 279 } |
OLD | NEW |