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 "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/chrome_notification_types.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" |
| 12 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
| 13 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" | 14 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" |
| 14 #include "chrome/browser/ui/app_list/apps_model_builder.h" | 15 #include "chrome/browser/ui/app_list/apps_model_builder.h" |
| 15 #include "chrome/browser/ui/app_list/chrome_app_list_item.h" | 16 #include "chrome/browser/ui/app_list/chrome_app_list_item.h" |
| 16 #include "chrome/browser/ui/app_list/chrome_signin_delegate.h" | 17 #include "chrome/browser/ui/app_list/chrome_signin_delegate.h" |
| 17 #include "chrome/browser/ui/app_list/search/search_controller.h" | 18 #include "chrome/browser/ui/app_list/search/search_controller.h" |
| 18 #include "chrome/browser/ui/browser_finder.h" | 19 #include "chrome/browser/ui/browser_finder.h" |
| 19 #include "chrome/browser/ui/chrome_pages.h" | 20 #include "chrome/browser/ui/chrome_pages.h" |
| 20 #include "chrome/browser/ui/host_desktop.h" | 21 #include "chrome/browser/ui/host_desktop.h" |
| 21 #include "chrome/browser/ui/web_applications/web_app_ui.h" | 22 #include "chrome/browser/ui/web_applications/web_app_ui.h" |
| 22 #include "chrome/browser/web_applications/web_app.h" | 23 #include "chrome/browser/web_applications/web_app.h" |
| 23 #include "chrome/common/extensions/extension_constants.h" | 24 #include "chrome/common/extensions/extension_constants.h" |
| 24 #include "chrome/common/url_constants.h" | 25 #include "chrome/common/url_constants.h" |
| 25 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
| 27 #include "content/public/browser/notification_details.h" | |
|
tapted
2013/08/14 03:53:11
nit: content::NotificationSource and content::Noti
calamity
2013/08/14 09:19:00
Done. notification_source.h is needed for content:
| |
| 28 #include "content/public/browser/notification_service.h" | |
| 29 #include "content/public/browser/notification_source.h" | |
| 26 #include "content/public/browser/page_navigator.h" | 30 #include "content/public/browser/page_navigator.h" |
| 27 #include "content/public/browser/user_metrics.h" | 31 #include "content/public/browser/user_metrics.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 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 47 base::Bind(web_app::CreateShortcutInWebAppDir, app_data_dir, info), | 51 base::Bind(web_app::CreateShortcutInWebAppDir, app_data_dir, info), |
| 48 callback); | 52 callback); |
| 49 } | 53 } |
| 50 #endif | 54 #endif |
| 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), |
| 62 model_(NULL) { | |
| 63 DCHECK(profile_); | |
| 64 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, | |
|
tfarina
2013/08/14 03:57:00
do you need to use notifications? we are moving aw
calamity
2013/08/14 09:19:00
I'll split out the NOTIFICATION_PROFILE_CACHED_INF
| |
| 65 content::NotificationService::AllSources()); | |
| 66 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNED_OUT, | |
| 67 content::Source<Profile>(profile_)); | |
| 68 } | |
| 58 | 69 |
| 59 AppListViewDelegate::~AppListViewDelegate() {} | 70 AppListViewDelegate::~AppListViewDelegate() { |
| 71 if (signin_delegate_.get()) | |
|
tapted
2013/08/14 03:53:11
nit: the `.get()` is usually dropped when used as
calamity
2013/08/14 09:19:00
Done.
| |
| 72 signin_delegate_->RemoveObserver(this); | |
| 73 } | |
| 74 | |
| 75 void AppListViewDelegate::OnProfileChanged() { | |
| 76 model_->SetSignedIn(!signin_delegate_->NeedSignin()); | |
| 77 ProfileInfoCache& cache = | |
| 78 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
| 79 // Populate the current user details. | |
| 80 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); | |
| 81 // The profile won't exist in the cache if the current app list profile is | |
| 82 // being deleted. | |
| 83 if (profile_index == std::string::npos) | |
| 84 return; | |
| 85 | |
| 86 model_->SetCurrentUser(cache.GetNameOfProfileAtIndex(profile_index), | |
| 87 cache.GetUserNameOfProfileAtIndex(profile_index)); | |
| 88 } | |
| 60 | 89 |
| 61 void AppListViewDelegate::SetModel(app_list::AppListModel* model) { | 90 void AppListViewDelegate::SetModel(app_list::AppListModel* model) { |
| 91 if (signin_delegate_.get()) | |
| 92 signin_delegate_->RemoveObserver(this); | |
| 62 if (model) { | 93 if (model) { |
| 94 model_ = model; | |
| 63 apps_builder_.reset(new AppsModelBuilder(profile_, | 95 apps_builder_.reset(new AppsModelBuilder(profile_, |
| 64 model->apps(), | 96 model->apps(), |
| 65 controller_.get())); | 97 controller_.get())); |
| 66 apps_builder_->Build(); | 98 apps_builder_->Build(); |
| 67 | 99 |
| 68 search_controller_.reset(new app_list::SearchController( | 100 search_controller_.reset(new app_list::SearchController( |
| 69 profile_, model->search_box(), model->results(), controller_.get())); | 101 profile_, model->search_box(), model->results(), controller_.get())); |
| 70 | 102 |
| 71 signin_delegate_.reset(new ChromeSigninDelegate(profile_)); | 103 signin_delegate_.reset(new ChromeSigninDelegate(profile_)); |
| 104 signin_delegate_->AddObserver(this); | |
| 72 | 105 |
| 73 #if defined(USE_ASH) | 106 #if defined(USE_ASH) |
| 74 app_sync_ui_state_watcher_.reset(new AppSyncUIStateWatcher(profile_, | 107 app_sync_ui_state_watcher_.reset(new AppSyncUIStateWatcher(profile_, |
| 75 model)); | 108 model)); |
| 76 #endif | 109 #endif |
| 110 OnProfileChanged(); | |
| 77 } else { | 111 } else { |
|
tapted
2013/08/14 03:53:11
I think while this else is still around, it also n
calamity
2013/08/14 09:19:00
Done.
| |
| 112 model_ = NULL; | |
| 78 apps_builder_.reset(); | 113 apps_builder_.reset(); |
| 79 search_controller_.reset(); | 114 search_controller_.reset(); |
| 80 #if defined(USE_ASH) | 115 #if defined(USE_ASH) |
| 81 app_sync_ui_state_watcher_.reset(); | 116 app_sync_ui_state_watcher_.reset(); |
| 82 #endif | 117 #endif |
| 83 } | 118 } |
| 84 } | 119 } |
| 85 | 120 |
| 86 app_list::SigninDelegate* AppListViewDelegate::GetSigninDelegate() { | 121 app_list::SigninDelegate* AppListViewDelegate::GetSigninDelegate() { |
| 87 return signin_delegate_.get(); | 122 return signin_delegate_.get(); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 } | 188 } |
| 154 | 189 |
| 155 void AppListViewDelegate::ViewActivationChanged(bool active) { | 190 void AppListViewDelegate::ViewActivationChanged(bool active) { |
| 156 controller_->ViewActivationChanged(active); | 191 controller_->ViewActivationChanged(active); |
| 157 } | 192 } |
| 158 | 193 |
| 159 gfx::ImageSkia AppListViewDelegate::GetWindowIcon() { | 194 gfx::ImageSkia AppListViewDelegate::GetWindowIcon() { |
| 160 return controller_->GetWindowIcon(); | 195 return controller_->GetWindowIcon(); |
| 161 } | 196 } |
| 162 | 197 |
| 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() { | 198 void AppListViewDelegate::OpenSettings() { |
| 184 ExtensionService* service = profile_->GetExtensionService(); | 199 ExtensionService* service = profile_->GetExtensionService(); |
| 185 DCHECK(service); | 200 DCHECK(service); |
| 186 const extensions::Extension* extension = service->GetInstalledExtension( | 201 const extensions::Extension* extension = service->GetInstalledExtension( |
| 187 extension_misc::kSettingsAppId); | 202 extension_misc::kSettingsAppId); |
| 188 DCHECK(extension); | 203 DCHECK(extension); |
| 189 controller_->ActivateApp(profile_, extension, 0); | 204 controller_->ActivateApp(profile_, extension, 0); |
| 190 } | 205 } |
| 191 | 206 |
| 192 void AppListViewDelegate::OpenHelp() { | 207 void AppListViewDelegate::OpenHelp() { |
| 193 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow( | 208 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow( |
| 194 controller_->GetAppListWindow()); | 209 controller_->GetAppListWindow()); |
| 195 Browser* browser = chrome::FindOrCreateTabbedBrowser( | 210 Browser* browser = chrome::FindOrCreateTabbedBrowser( |
| 196 profile_, desktop); | 211 profile_, desktop); |
| 197 browser->OpenURL(content::OpenURLParams(GURL(chrome::kAppLauncherHelpURL), | 212 browser->OpenURL(content::OpenURLParams(GURL(chrome::kAppLauncherHelpURL), |
| 198 content::Referrer(), | 213 content::Referrer(), |
| 199 NEW_FOREGROUND_TAB, | 214 NEW_FOREGROUND_TAB, |
| 200 content::PAGE_TRANSITION_LINK, | 215 content::PAGE_TRANSITION_LINK, |
| 201 false)); | 216 false)); |
| 202 } | 217 } |
| 203 | 218 |
| 204 void AppListViewDelegate::OpenFeedback() { | 219 void AppListViewDelegate::OpenFeedback() { |
| 205 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow( | 220 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow( |
| 206 controller_->GetAppListWindow()); | 221 controller_->GetAppListWindow()); |
| 207 Browser* browser = chrome::FindOrCreateTabbedBrowser( | 222 Browser* browser = chrome::FindOrCreateTabbedBrowser( |
| 208 profile_, desktop); | 223 profile_, desktop); |
| 209 chrome::ShowFeedbackPage(browser, std::string(), | 224 chrome::ShowFeedbackPage(browser, std::string(), |
| 210 chrome::kAppLauncherCategoryTag); | 225 chrome::kAppLauncherCategoryTag); |
| 211 } | 226 } |
| 227 | |
| 228 void AppListViewDelegate::OnSigninSuccess() { | |
| 229 OnProfileChanged(); | |
| 230 } | |
| 231 | |
| 232 void AppListViewDelegate::Observe( | |
| 233 int type, | |
| 234 const content::NotificationSource& source, | |
| 235 const content::NotificationDetails& details) { | |
| 236 OnProfileChanged(); | |
| 237 } | |
| OLD | NEW |