Chromium Code Reviews| 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/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
| 11 #include "chrome/browser/feedback/feedback_util.h" | 12 #include "chrome/browser/feedback/feedback_util.h" |
| 13 #include "chrome/browser/profiles/profile_info_cache.h" | |
| 14 #include "chrome/browser/profiles/profile_info_util.h" | |
| 12 #include "chrome/browser/profiles/profile_manager.h" | 15 #include "chrome/browser/profiles/profile_manager.h" |
| 13 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" | 16 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" |
| 14 #include "chrome/browser/ui/app_list/apps_model_builder.h" | 17 #include "chrome/browser/ui/app_list/apps_model_builder.h" |
| 15 #include "chrome/browser/ui/app_list/chrome_app_list_item.h" | 18 #include "chrome/browser/ui/app_list/chrome_app_list_item.h" |
| 16 #include "chrome/browser/ui/app_list/chrome_signin_delegate.h" | 19 #include "chrome/browser/ui/app_list/chrome_signin_delegate.h" |
| 17 #include "chrome/browser/ui/app_list/search/search_controller.h" | 20 #include "chrome/browser/ui/app_list/search/search_controller.h" |
| 18 #include "chrome/browser/ui/browser_finder.h" | 21 #include "chrome/browser/ui/browser_finder.h" |
| 19 #include "chrome/browser/ui/chrome_pages.h" | 22 #include "chrome/browser/ui/chrome_pages.h" |
| 20 #include "chrome/browser/ui/host_desktop.h" | 23 #include "chrome/browser/ui/host_desktop.h" |
| 21 #include "chrome/browser/ui/web_applications/web_app_ui.h" | 24 #include "chrome/browser/ui/web_applications/web_app_ui.h" |
| 22 #include "chrome/browser/web_applications/web_app.h" | 25 #include "chrome/browser/web_applications/web_app.h" |
| 23 #include "chrome/common/extensions/extension_constants.h" | 26 #include "chrome/common/extensions/extension_constants.h" |
| 24 #include "chrome/common/url_constants.h" | 27 #include "chrome/common/url_constants.h" |
| 25 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
| 26 #include "content/public/browser/page_navigator.h" | 29 #include "content/public/browser/page_navigator.h" |
| 27 #include "content/public/browser/user_metrics.h" | 30 #include "content/public/browser/user_metrics.h" |
| 31 #include "ui/base/models/avatar_menu_item_model.h" | |
| 28 | 32 |
| 29 #if defined(USE_ASH) | 33 #if defined(USE_ASH) |
| 30 #include "chrome/browser/ui/ash/app_list/app_sync_ui_state_watcher.h" | 34 #include "chrome/browser/ui/ash/app_list/app_sync_ui_state_watcher.h" |
| 31 #endif | 35 #endif |
| 32 | 36 |
| 33 #if defined(OS_WIN) | 37 #if defined(OS_WIN) |
| 34 #include "chrome/browser/web_applications/web_app_win.h" | 38 #include "chrome/browser/web_applications/web_app_win.h" |
| 35 #endif | 39 #endif |
| 36 | 40 |
| 37 namespace { | 41 namespace { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 51 | 55 |
| 52 } // namespace | 56 } // namespace |
| 53 | 57 |
| 54 AppListViewDelegate::AppListViewDelegate(AppListControllerDelegate* controller, | 58 AppListViewDelegate::AppListViewDelegate(AppListControllerDelegate* controller, |
| 55 Profile* profile) | 59 Profile* profile) |
| 56 : controller_(controller), | 60 : controller_(controller), |
| 57 profile_(profile) {} | 61 profile_(profile) {} |
| 58 | 62 |
| 59 AppListViewDelegate::~AppListViewDelegate() {} | 63 AppListViewDelegate::~AppListViewDelegate() {} |
| 60 | 64 |
| 65 void AppListViewDelegate::SetProfile(Profile* profile) { | |
| 66 profile_ = profile; | |
|
benwells
2013/07/31 05:47:13
Shouldn't this rebuild models and suchlike? Feels
calamity
2013/08/01 08:35:45
Done.
| |
| 67 } | |
| 68 | |
| 61 void AppListViewDelegate::SetModel(app_list::AppListModel* model) { | 69 void AppListViewDelegate::SetModel(app_list::AppListModel* model) { |
|
benwells
2013/07/31 05:47:13
This name is really bad. It rebuilds the whole mod
calamity
2013/08/01 08:35:45
Done. Switched to InitModel.
| |
| 62 if (model) { | 70 if (model) { |
| 71 ProfileInfoCache& cache = | |
| 72 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
| 73 | |
| 74 // Initialize the current user details. | |
| 75 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); | |
| 76 if (profile_index == std::string::npos) | |
| 77 NOTREACHED(); | |
|
tapted
2013/07/31 05:43:53
maybe DCHECK_NE(std::string::npos, profile_index),
calamity
2013/08/01 08:35:45
Done.
| |
| 78 model->SetCurrentUser(cache.GetNameOfProfileAtIndex(profile_index), | |
| 79 cache.GetUserNameOfProfileAtIndex(profile_index)); | |
| 80 | |
| 81 // Initialize the profile menu. | |
| 82 RebuildAvatarMenuItems(model); | |
| 83 | |
| 84 // Initialize apps model. | |
| 63 apps_builder_.reset(new AppsModelBuilder(profile_, | 85 apps_builder_.reset(new AppsModelBuilder(profile_, |
| 64 model->apps(), | 86 model->apps(), |
| 65 controller_.get())); | 87 controller_.get())); |
| 66 apps_builder_->Build(); | 88 apps_builder_->Build(); |
| 67 | 89 |
| 68 search_controller_.reset(new app_list::SearchController( | 90 search_controller_.reset(new app_list::SearchController( |
| 69 profile_, model->search_box(), model->results(), controller_.get())); | 91 profile_, model->search_box(), model->results(), controller_.get())); |
| 70 | 92 |
| 71 signin_delegate_.reset(new ChromeSigninDelegate(profile_)); | 93 signin_delegate_.reset(new ChromeSigninDelegate(profile_)); |
| 72 | |
| 73 #if defined(USE_ASH) | 94 #if defined(USE_ASH) |
| 74 app_sync_ui_state_watcher_.reset(new AppSyncUIStateWatcher(profile_, | 95 app_sync_ui_state_watcher_.reset(new AppSyncUIStateWatcher(profile_, |
| 75 model)); | 96 model_)); |
|
tapted
2013/07/31 05:43:53
`model_` with an underscore might be an error?
calamity
2013/08/01 08:35:45
Done.
| |
| 76 #endif | 97 #endif |
| 77 } else { | 98 } else { |
|
tapted
2013/07/31 05:43:53
Does something need to be done for the `else` case
calamity
2013/08/01 08:35:45
I removed the else case because it doesn't seem to
| |
| 78 apps_builder_.reset(); | 99 apps_builder_.reset(); |
| 79 search_controller_.reset(); | 100 search_controller_.reset(); |
| 80 #if defined(USE_ASH) | 101 #if defined(USE_ASH) |
| 81 app_sync_ui_state_watcher_.reset(); | 102 app_sync_ui_state_watcher_.reset(); |
| 82 #endif | 103 #endif |
| 83 } | 104 } |
| 84 } | 105 } |
| 85 | 106 |
| 86 app_list::SigninDelegate* AppListViewDelegate::GetSigninDelegate() { | 107 app_list::SigninDelegate* AppListViewDelegate::GetSigninDelegate() { |
| 87 return signin_delegate_.get(); | 108 return signin_delegate_.get(); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 } | 174 } |
| 154 | 175 |
| 155 void AppListViewDelegate::ViewActivationChanged(bool active) { | 176 void AppListViewDelegate::ViewActivationChanged(bool active) { |
| 156 controller_->ViewActivationChanged(active); | 177 controller_->ViewActivationChanged(active); |
| 157 } | 178 } |
| 158 | 179 |
| 159 gfx::ImageSkia AppListViewDelegate::GetWindowIcon() { | 180 gfx::ImageSkia AppListViewDelegate::GetWindowIcon() { |
| 160 return controller_->GetWindowIcon(); | 181 return controller_->GetWindowIcon(); |
| 161 } | 182 } |
| 162 | 183 |
| 163 string16 AppListViewDelegate::GetCurrentUserName() { | |
| 164 ProfileInfoCache& cache = | |
| 165 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
| 166 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); | |
| 167 if (profile_index != std::string::npos) | |
| 168 return cache.GetNameOfProfileAtIndex(profile_index); | |
| 169 | |
| 170 return string16(); | |
| 171 } | |
| 172 | |
| 173 string16 AppListViewDelegate::GetCurrentUserEmail() { | |
| 174 ProfileInfoCache& cache = | |
| 175 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
| 176 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); | |
| 177 if (profile_index != std::string::npos) | |
| 178 return cache.GetUserNameOfProfileAtIndex(profile_index); | |
| 179 | |
| 180 return string16(); | |
| 181 } | |
| 182 | |
| 183 void AppListViewDelegate::OpenSettings() { | 184 void AppListViewDelegate::OpenSettings() { |
| 184 ExtensionService* service = profile_->GetExtensionService(); | 185 ExtensionService* service = profile_->GetExtensionService(); |
| 185 DCHECK(service); | 186 DCHECK(service); |
| 186 const extensions::Extension* extension = service->GetInstalledExtension( | 187 const extensions::Extension* extension = service->GetInstalledExtension( |
| 187 extension_misc::kSettingsAppId); | 188 extension_misc::kSettingsAppId); |
| 188 DCHECK(extension); | 189 DCHECK(extension); |
| 189 controller_->ActivateApp(profile_, extension, 0); | 190 controller_->ActivateApp(profile_, extension, 0); |
| 190 } | 191 } |
| 191 | 192 |
| 192 void AppListViewDelegate::OpenHelp() { | 193 void AppListViewDelegate::OpenHelp() { |
| 193 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow( | 194 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow( |
| 194 controller_->GetAppListWindow()); | 195 controller_->GetAppListWindow()); |
| 195 Browser* browser = chrome::FindOrCreateTabbedBrowser( | 196 Browser* browser = chrome::FindOrCreateTabbedBrowser( |
| 196 profile_, desktop); | 197 profile_, desktop); |
| 197 browser->OpenURL(content::OpenURLParams(GURL(chrome::kAppLauncherHelpURL), | 198 browser->OpenURL(content::OpenURLParams(GURL(chrome::kAppLauncherHelpURL), |
| 198 content::Referrer(), | 199 content::Referrer(), |
| 199 NEW_FOREGROUND_TAB, | 200 NEW_FOREGROUND_TAB, |
| 200 content::PAGE_TRANSITION_LINK, | 201 content::PAGE_TRANSITION_LINK, |
| 201 false)); | 202 false)); |
| 202 } | 203 } |
| 203 | 204 |
| 204 void AppListViewDelegate::OpenFeedback() { | 205 void AppListViewDelegate::OpenFeedback() { |
| 205 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow( | 206 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow( |
| 206 controller_->GetAppListWindow()); | 207 controller_->GetAppListWindow()); |
| 207 Browser* browser = chrome::FindOrCreateTabbedBrowser( | 208 Browser* browser = chrome::FindOrCreateTabbedBrowser( |
| 208 profile_, desktop); | 209 profile_, desktop); |
| 209 chrome::ShowFeedbackPage(browser, std::string(), | 210 chrome::ShowFeedbackPage(browser, std::string(), |
| 210 chrome::kAppLauncherCategoryTag); | 211 chrome::kAppLauncherCategoryTag); |
| 211 } | 212 } |
| 213 | |
| 214 void AppListViewDelegate::ShowForProfileAtIndex(size_t index) { | |
| 215 controller_->ShowForProfileAtIndex(index); | |
| 216 } | |
| 217 | |
| 218 void AppListViewDelegate::RebuildAvatarMenuItems( | |
| 219 app_list::AppListModel* model) { | |
| 220 ProfileInfoCache& cache = | |
| 221 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
| 222 STLDeleteElements(&model->avatar_menu_items()); | |
|
tapted
2013/07/31 05:43:53
it's a bit odd to expose a non-const reference to
calamity
2013/08/01 08:35:45
Done.
| |
| 223 profiles::PopulateAvatarMenuItemModels(model->avatar_menu_items(), | |
| 224 &cache, | |
| 225 base::FilePath()); | |
| 226 } | |
| OLD | NEW |