| 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_source.h" |
| 26 #include "content/public/browser/page_navigator.h" | 28 #include "content/public/browser/page_navigator.h" |
| 27 #include "content/public/browser/user_metrics.h" | 29 #include "content/public/browser/user_metrics.h" |
| 28 | 30 |
| 29 #if defined(USE_ASH) | 31 #if defined(USE_ASH) |
| 30 #include "chrome/browser/ui/ash/app_list/app_sync_ui_state_watcher.h" | 32 #include "chrome/browser/ui/ash/app_list/app_sync_ui_state_watcher.h" |
| 31 #endif | 33 #endif |
| 32 | 34 |
| 33 #if defined(OS_WIN) | 35 #if defined(OS_WIN) |
| 34 #include "chrome/browser/web_applications/web_app_win.h" | 36 #include "chrome/browser/web_applications/web_app_win.h" |
| 35 #endif | 37 #endif |
| (...skipping 11 matching lines...) Expand all Loading... |
| 47 base::Bind(web_app::CreateShortcutInWebAppDir, app_data_dir, info), | 49 base::Bind(web_app::CreateShortcutInWebAppDir, app_data_dir, info), |
| 48 callback); | 50 callback); |
| 49 } | 51 } |
| 50 #endif | 52 #endif |
| 51 | 53 |
| 52 } // namespace | 54 } // namespace |
| 53 | 55 |
| 54 AppListViewDelegate::AppListViewDelegate(AppListControllerDelegate* controller, | 56 AppListViewDelegate::AppListViewDelegate(AppListControllerDelegate* controller, |
| 55 Profile* profile) | 57 Profile* profile) |
| 56 : controller_(controller), | 58 : controller_(controller), |
| 57 profile_(profile) {} | 59 profile_(profile), |
| 60 model_(NULL) { |
| 61 DCHECK(profile_); |
| 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 } |
| 58 | 69 |
| 59 AppListViewDelegate::~AppListViewDelegate() {} | 70 AppListViewDelegate::~AppListViewDelegate() { |
| 71 if (signin_delegate_) |
| 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_) |
| 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 { |
| 112 model_ = NULL; |
| 78 apps_builder_.reset(); | 113 apps_builder_.reset(); |
| 79 search_controller_.reset(); | 114 search_controller_.reset(); |
| 115 signin_delegate_.reset(); |
| 80 #if defined(USE_ASH) | 116 #if defined(USE_ASH) |
| 81 app_sync_ui_state_watcher_.reset(); | 117 app_sync_ui_state_watcher_.reset(); |
| 82 #endif | 118 #endif |
| 83 } | 119 } |
| 84 } | 120 } |
| 85 | 121 |
| 86 app_list::SigninDelegate* AppListViewDelegate::GetSigninDelegate() { | 122 app_list::SigninDelegate* AppListViewDelegate::GetSigninDelegate() { |
| 87 return signin_delegate_.get(); | 123 return signin_delegate_.get(); |
| 88 } | 124 } |
| 89 | 125 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 115 web_app::UpdateShortcutInfoAndIconForApp( | 151 web_app::UpdateShortcutInfoAndIconForApp( |
| 116 *extension, | 152 *extension, |
| 117 profile_, | 153 profile_, |
| 118 base::Bind(CreateShortcutInWebAppDir, app_data_dir, callback)); | 154 base::Bind(CreateShortcutInWebAppDir, app_data_dir, callback)); |
| 119 #else | 155 #else |
| 120 callback.Run(base::FilePath()); | 156 callback.Run(base::FilePath()); |
| 121 #endif | 157 #endif |
| 122 } | 158 } |
| 123 | 159 |
| 124 void AppListViewDelegate::StartSearch() { | 160 void AppListViewDelegate::StartSearch() { |
| 125 if (search_controller_.get()) | 161 if (search_controller_) |
| 126 search_controller_->Start(); | 162 search_controller_->Start(); |
| 127 } | 163 } |
| 128 | 164 |
| 129 void AppListViewDelegate::StopSearch() { | 165 void AppListViewDelegate::StopSearch() { |
| 130 if (search_controller_.get()) | 166 if (search_controller_) |
| 131 search_controller_->Stop(); | 167 search_controller_->Stop(); |
| 132 } | 168 } |
| 133 | 169 |
| 134 void AppListViewDelegate::OpenSearchResult( | 170 void AppListViewDelegate::OpenSearchResult( |
| 135 app_list::SearchResult* result, | 171 app_list::SearchResult* result, |
| 136 int event_flags) { | 172 int event_flags) { |
| 137 search_controller_->OpenResult(result, event_flags); | 173 search_controller_->OpenResult(result, event_flags); |
| 138 } | 174 } |
| 139 | 175 |
| 140 void AppListViewDelegate::InvokeSearchResultAction( | 176 void AppListViewDelegate::InvokeSearchResultAction( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 153 } | 189 } |
| 154 | 190 |
| 155 void AppListViewDelegate::ViewActivationChanged(bool active) { | 191 void AppListViewDelegate::ViewActivationChanged(bool active) { |
| 156 controller_->ViewActivationChanged(active); | 192 controller_->ViewActivationChanged(active); |
| 157 } | 193 } |
| 158 | 194 |
| 159 gfx::ImageSkia AppListViewDelegate::GetWindowIcon() { | 195 gfx::ImageSkia AppListViewDelegate::GetWindowIcon() { |
| 160 return controller_->GetWindowIcon(); | 196 return controller_->GetWindowIcon(); |
| 161 } | 197 } |
| 162 | 198 |
| 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() { | 199 void AppListViewDelegate::OpenSettings() { |
| 184 ExtensionService* service = profile_->GetExtensionService(); | 200 ExtensionService* service = profile_->GetExtensionService(); |
| 185 DCHECK(service); | 201 DCHECK(service); |
| 186 const extensions::Extension* extension = service->GetInstalledExtension( | 202 const extensions::Extension* extension = service->GetInstalledExtension( |
| 187 extension_misc::kSettingsAppId); | 203 extension_misc::kSettingsAppId); |
| 188 DCHECK(extension); | 204 DCHECK(extension); |
| 189 controller_->ActivateApp(profile_, extension, 0); | 205 controller_->ActivateApp(profile_, extension, 0); |
| 190 } | 206 } |
| 191 | 207 |
| 192 void AppListViewDelegate::OpenHelp() { | 208 void AppListViewDelegate::OpenHelp() { |
| 193 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow( | 209 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow( |
| 194 controller_->GetAppListWindow()); | 210 controller_->GetAppListWindow()); |
| 195 Browser* browser = chrome::FindOrCreateTabbedBrowser( | 211 Browser* browser = chrome::FindOrCreateTabbedBrowser( |
| 196 profile_, desktop); | 212 profile_, desktop); |
| 197 browser->OpenURL(content::OpenURLParams(GURL(chrome::kAppLauncherHelpURL), | 213 browser->OpenURL(content::OpenURLParams(GURL(chrome::kAppLauncherHelpURL), |
| 198 content::Referrer(), | 214 content::Referrer(), |
| 199 NEW_FOREGROUND_TAB, | 215 NEW_FOREGROUND_TAB, |
| 200 content::PAGE_TRANSITION_LINK, | 216 content::PAGE_TRANSITION_LINK, |
| 201 false)); | 217 false)); |
| 202 } | 218 } |
| 203 | 219 |
| 204 void AppListViewDelegate::OpenFeedback() { | 220 void AppListViewDelegate::OpenFeedback() { |
| 205 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow( | 221 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow( |
| 206 controller_->GetAppListWindow()); | 222 controller_->GetAppListWindow()); |
| 207 Browser* browser = chrome::FindOrCreateTabbedBrowser( | 223 Browser* browser = chrome::FindOrCreateTabbedBrowser( |
| 208 profile_, desktop); | 224 profile_, desktop); |
| 209 chrome::ShowFeedbackPage(browser, std::string(), | 225 chrome::ShowFeedbackPage(browser, std::string(), |
| 210 chrome::kAppLauncherCategoryTag); | 226 chrome::kAppLauncherCategoryTag); |
| 211 } | 227 } |
| 228 |
| 229 void AppListViewDelegate::OnSigninSuccess() { |
| 230 OnProfileChanged(); |
| 231 } |
| 232 |
| 233 void AppListViewDelegate::Observe( |
| 234 int type, |
| 235 const content::NotificationSource& source, |
| 236 const content::NotificationDetails& details) { |
| 237 OnProfileChanged(); |
| 238 } |
| OLD | NEW |