| 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 "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/stl_util.h" |
| 9 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
| 11 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
| 12 #include "chrome/browser/feedback/feedback_util.h" | 13 #include "chrome/browser/feedback/feedback_util.h" |
| 14 #include "chrome/browser/profiles/profile_info_cache.h" |
| 15 #include "chrome/browser/profiles/profile_info_util.h" |
| 13 #include "chrome/browser/profiles/profile_manager.h" | 16 #include "chrome/browser/profiles/profile_manager.h" |
| 14 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" | 17 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" |
| 15 #include "chrome/browser/ui/app_list/apps_model_builder.h" | 18 #include "chrome/browser/ui/app_list/apps_model_builder.h" |
| 16 #include "chrome/browser/ui/app_list/chrome_app_list_item.h" | 19 #include "chrome/browser/ui/app_list/chrome_app_list_item.h" |
| 17 #include "chrome/browser/ui/app_list/chrome_signin_delegate.h" | 20 #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_details.h" | 30 #include "content/public/browser/notification_details.h" |
| 28 #include "content/public/browser/notification_service.h" | 31 #include "content/public/browser/notification_service.h" |
| 29 #include "content/public/browser/notification_source.h" | 32 #include "content/public/browser/notification_source.h" |
| 30 #include "content/public/browser/page_navigator.h" | 33 #include "content/public/browser/page_navigator.h" |
| 31 #include "content/public/browser/user_metrics.h" | 34 #include "content/public/browser/user_metrics.h" |
| 35 #include "ui/app_list/search_box_model.h" |
| 36 #include "ui/base/profile_selector/avatar_menu_item_model.h" |
| 32 | 37 |
| 33 #if defined(USE_ASH) | 38 #if defined(USE_ASH) |
| 34 #include "chrome/browser/ui/ash/app_list/app_sync_ui_state_watcher.h" | 39 #include "chrome/browser/ui/ash/app_list/app_sync_ui_state_watcher.h" |
| 35 #endif | 40 #endif |
| 36 | 41 |
| 37 #if defined(OS_WIN) | 42 #if defined(OS_WIN) |
| 38 #include "chrome/browser/web_applications/web_app_win.h" | 43 #include "chrome/browser/web_applications/web_app_win.h" |
| 39 #endif | 44 #endif |
| 40 | 45 |
| 41 namespace { | 46 namespace { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 53 } | 58 } |
| 54 #endif | 59 #endif |
| 55 | 60 |
| 56 } // namespace | 61 } // namespace |
| 57 | 62 |
| 58 AppListViewDelegate::AppListViewDelegate(AppListControllerDelegate* controller, | 63 AppListViewDelegate::AppListViewDelegate(AppListControllerDelegate* controller, |
| 59 Profile* profile) | 64 Profile* profile) |
| 60 : controller_(controller), | 65 : controller_(controller), |
| 61 profile_(profile), | 66 profile_(profile), |
| 62 model_(NULL) { | 67 model_(NULL) { |
| 68 RegisterForNotifications(); |
| 69 } |
| 70 |
| 71 AppListViewDelegate::~AppListViewDelegate() { |
| 72 if (signin_delegate_.get()) |
| 73 signin_delegate_->RemoveObserver(this); |
| 74 } |
| 75 |
| 76 void AppListViewDelegate::RegisterForNotifications() { |
| 77 registrar_.RemoveAll(); |
| 63 DCHECK(profile_); | 78 DCHECK(profile_); |
| 79 |
| 64 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, | 80 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, |
| 65 content::NotificationService::AllSources()); | 81 content::NotificationService::AllSources()); |
| 66 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, | 82 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, |
| 67 content::Source<Profile>(profile_)); | 83 content::Source<Profile>(profile_)); |
| 68 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED, | 84 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED, |
| 69 content::Source<Profile>(profile_)); | 85 content::Source<Profile>(profile_)); |
| 70 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNED_OUT, | 86 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNED_OUT, |
| 71 content::Source<Profile>(profile_)); | 87 content::Source<Profile>(profile_)); |
| 72 } | 88 } |
| 73 | 89 |
| 74 AppListViewDelegate::~AppListViewDelegate() { | |
| 75 if (signin_delegate_.get()) | |
| 76 signin_delegate_->RemoveObserver(this); | |
| 77 } | |
| 78 | |
| 79 void AppListViewDelegate::OnProfileChanged() { | 90 void AppListViewDelegate::OnProfileChanged() { |
| 80 model_->SetSignedIn(!signin_delegate_->NeedSignin()); | 91 model_->SetSignedIn(!GetSigninDelegate()->NeedSignin()); |
| 81 ProfileInfoCache& cache = | 92 ProfileInfoCache& cache = |
| 82 g_browser_process->profile_manager()->GetProfileInfoCache(); | 93 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 83 // Populate the current user details. | 94 // Populate the current user details. |
| 84 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); | 95 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); |
| 85 // The profile won't exist in the cache if the current app list profile is | 96 // The profile won't exist in the cache if the current app list profile is |
| 86 // being deleted. | 97 // being deleted. |
| 87 if (profile_index == std::string::npos) | 98 if (profile_index == std::string::npos) |
| 88 return; | 99 return; |
| 89 | 100 |
| 90 model_->SetCurrentUser(cache.GetNameOfProfileAtIndex(profile_index), | 101 model_->SetCurrentUser(cache.GetNameOfProfileAtIndex(profile_index), |
| 91 cache.GetUserNameOfProfileAtIndex(profile_index)); | 102 cache.GetUserNameOfProfileAtIndex(profile_index)); |
| 103 |
| 104 // Populate the profile menu items. |
| 105 app_list::AppListModel::ProfileMenuItems profile_menu_items; |
| 106 profiles::PopulateAvatarMenuItemModels(&cache, |
| 107 profile_->GetPath(), |
| 108 &profile_menu_items); |
| 109 model_->SetProfileMenuItems(profile_menu_items); |
| 92 } | 110 } |
| 93 | 111 |
| 94 void AppListViewDelegate::SetModel(app_list::AppListModel* model) { | 112 void AppListViewDelegate::SetProfileByPath(const base::FilePath& profile_path) { |
| 95 if (signin_delegate_.get()) | 113 DCHECK(model_); |
| 96 signin_delegate_->RemoveObserver(this); | |
| 97 if (model) { | |
| 98 model_ = model; | |
| 99 apps_builder_.reset(new AppsModelBuilder(profile_, | |
| 100 model->apps(), | |
| 101 controller_.get())); | |
| 102 apps_builder_->Build(); | |
| 103 | 114 |
| 104 search_controller_.reset(new app_list::SearchController( | 115 // The profile must be loaded before this is called. |
| 105 profile_, model->search_box(), model->results(), controller_.get())); | 116 profile_ = |
| 117 g_browser_process->profile_manager()->GetProfileByPath(profile_path); |
| 118 DCHECK(profile_); |
| 106 | 119 |
| 107 signin_delegate_.reset(new ChromeSigninDelegate(profile_)); | 120 RegisterForNotifications(); |
| 108 signin_delegate_->AddObserver(this); | 121 |
| 122 apps_builder_->SetProfile(profile_); |
| 123 |
| 124 search_controller_.reset(new app_list::SearchController( |
| 125 profile_, model_->search_box(), model_->results(), controller_.get())); |
| 126 |
| 127 signin_delegate_->SetProfile(profile_); |
| 109 | 128 |
| 110 #if defined(USE_ASH) | 129 #if defined(USE_ASH) |
| 111 app_sync_ui_state_watcher_.reset(new AppSyncUIStateWatcher(profile_, | 130 app_sync_ui_state_watcher_.reset(new AppSyncUIStateWatcher(profile_, |
| 112 model)); | 131 model_)); |
| 113 #endif | 132 #endif |
| 114 OnProfileChanged(); | 133 OnProfileChanged(); |
| 115 } else { | 134 if (!model_->search_box()->text().empty()) |
| 116 model_ = NULL; | 135 StartSearch(); |
| 117 apps_builder_.reset(); | 136 } |
| 118 search_controller_.reset(); | 137 |
| 138 void AppListViewDelegate::InitModel(app_list::AppListModel* model) { |
| 139 DCHECK(!model_); |
| 140 DCHECK(model); |
| 141 model_ = model; |
| 142 |
| 143 // Initialize apps model. |
| 144 apps_builder_.reset(new AppsModelBuilder(profile_, |
| 145 model->apps(), |
| 146 controller_.get())); |
| 147 apps_builder_->Build(); |
| 148 |
| 149 search_controller_.reset(new app_list::SearchController( |
| 150 profile_, model->search_box(), model->results(), controller_.get())); |
| 151 |
| 152 signin_delegate_.reset(new ChromeSigninDelegate(profile_)); |
| 153 signin_delegate_->AddObserver(this); |
| 154 |
| 119 #if defined(USE_ASH) | 155 #if defined(USE_ASH) |
| 120 app_sync_ui_state_watcher_.reset(); | 156 app_sync_ui_state_watcher_.reset(new AppSyncUIStateWatcher(profile_, |
| 157 model)); |
| 121 #endif | 158 #endif |
| 122 } | 159 // Initialize the profile information in the app list menu. |
| 160 OnProfileChanged(); |
| 123 } | 161 } |
| 124 | 162 |
| 125 app_list::SigninDelegate* AppListViewDelegate::GetSigninDelegate() { | 163 app_list::SigninDelegate* AppListViewDelegate::GetSigninDelegate() { |
| 126 return signin_delegate_.get(); | 164 return signin_delegate_.get(); |
| 127 } | 165 } |
| 128 | 166 |
| 129 void AppListViewDelegate::ActivateAppListItem( | 167 void AppListViewDelegate::ActivateAppListItem( |
| 130 app_list::AppListItemModel* item, | 168 app_list::AppListItemModel* item, |
| 131 int event_flags) { | 169 int event_flags) { |
| 132 content::RecordAction(content::UserMetricsAction("AppList_ClickOnApp")); | 170 content::RecordAction(content::UserMetricsAction("AppList_ClickOnApp")); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 | 260 |
| 223 void AppListViewDelegate::OpenFeedback() { | 261 void AppListViewDelegate::OpenFeedback() { |
| 224 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow( | 262 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow( |
| 225 controller_->GetAppListWindow()); | 263 controller_->GetAppListWindow()); |
| 226 Browser* browser = chrome::FindOrCreateTabbedBrowser( | 264 Browser* browser = chrome::FindOrCreateTabbedBrowser( |
| 227 profile_, desktop); | 265 profile_, desktop); |
| 228 chrome::ShowFeedbackPage(browser, std::string(), | 266 chrome::ShowFeedbackPage(browser, std::string(), |
| 229 chrome::kAppLauncherCategoryTag); | 267 chrome::kAppLauncherCategoryTag); |
| 230 } | 268 } |
| 231 | 269 |
| 270 void AppListViewDelegate::ShowForProfileByPath( |
| 271 const base::FilePath& profile_path) { |
| 272 controller_->ShowForProfileByPath(profile_path); |
| 273 } |
| 274 |
| 232 void AppListViewDelegate::OnSigninSuccess() { | 275 void AppListViewDelegate::OnSigninSuccess() { |
| 233 OnProfileChanged(); | 276 OnProfileChanged(); |
| 234 } | 277 } |
| 235 | 278 |
| 236 void AppListViewDelegate::Observe( | 279 void AppListViewDelegate::Observe( |
| 237 int type, | 280 int type, |
| 238 const content::NotificationSource& source, | 281 const content::NotificationSource& source, |
| 239 const content::NotificationDetails& details) { | 282 const content::NotificationDetails& details) { |
| 240 OnProfileChanged(); | 283 OnProfileChanged(); |
| 241 } | 284 } |
| OLD | NEW |