| 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( |
| 141 app_list::SearchResult* result, | 177 app_list::SearchResult* result, |
| 142 int action_index, | 178 int action_index, |
| 143 int event_flags) { | 179 int event_flags) { |
| 144 search_controller_->InvokeResultAction(result, action_index, event_flags); | 180 search_controller_->InvokeResultAction(result, action_index, event_flags); |
| 145 } | 181 } |
| 146 | 182 |
| 147 void AppListViewDelegate::Dismiss() { | 183 void AppListViewDelegate::Dismiss() { |
| 148 controller_->DismissView(); | 184 controller_->DismissView(); |
| 149 } | 185 } |
| 150 | 186 |
| 151 void AppListViewDelegate::ViewClosing() { | 187 void AppListViewDelegate::ViewClosing() { |
| 152 controller_->ViewClosing(); | 188 controller_->ViewClosing(); |
| 153 } | 189 } |
| 154 | 190 |
| 155 gfx::ImageSkia AppListViewDelegate::GetWindowIcon() { | 191 gfx::ImageSkia AppListViewDelegate::GetWindowIcon() { |
| 156 return controller_->GetWindowIcon(); | 192 return controller_->GetWindowIcon(); |
| 157 } | 193 } |
| 158 | 194 |
| 159 string16 AppListViewDelegate::GetCurrentUserName() { | |
| 160 ProfileInfoCache& cache = | |
| 161 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
| 162 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); | |
| 163 if (profile_index != std::string::npos) | |
| 164 return cache.GetNameOfProfileAtIndex(profile_index); | |
| 165 | |
| 166 return string16(); | |
| 167 } | |
| 168 | |
| 169 string16 AppListViewDelegate::GetCurrentUserEmail() { | |
| 170 ProfileInfoCache& cache = | |
| 171 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
| 172 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); | |
| 173 if (profile_index != std::string::npos) | |
| 174 return cache.GetUserNameOfProfileAtIndex(profile_index); | |
| 175 | |
| 176 return string16(); | |
| 177 } | |
| 178 | |
| 179 void AppListViewDelegate::OpenSettings() { | 195 void AppListViewDelegate::OpenSettings() { |
| 180 ExtensionService* service = profile_->GetExtensionService(); | 196 ExtensionService* service = profile_->GetExtensionService(); |
| 181 DCHECK(service); | 197 DCHECK(service); |
| 182 const extensions::Extension* extension = service->GetInstalledExtension( | 198 const extensions::Extension* extension = service->GetInstalledExtension( |
| 183 extension_misc::kSettingsAppId); | 199 extension_misc::kSettingsAppId); |
| 184 DCHECK(extension); | 200 DCHECK(extension); |
| 185 controller_->ActivateApp(profile_, extension, 0); | 201 controller_->ActivateApp(profile_, extension, 0); |
| 186 } | 202 } |
| 187 | 203 |
| 188 void AppListViewDelegate::OpenHelp() { | 204 void AppListViewDelegate::OpenHelp() { |
| 189 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow( | 205 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow( |
| 190 controller_->GetAppListWindow()); | 206 controller_->GetAppListWindow()); |
| 191 Browser* browser = chrome::FindOrCreateTabbedBrowser( | 207 Browser* browser = chrome::FindOrCreateTabbedBrowser( |
| 192 profile_, desktop); | 208 profile_, desktop); |
| 193 browser->OpenURL(content::OpenURLParams(GURL(chrome::kAppLauncherHelpURL), | 209 browser->OpenURL(content::OpenURLParams(GURL(chrome::kAppLauncherHelpURL), |
| 194 content::Referrer(), | 210 content::Referrer(), |
| 195 NEW_FOREGROUND_TAB, | 211 NEW_FOREGROUND_TAB, |
| 196 content::PAGE_TRANSITION_LINK, | 212 content::PAGE_TRANSITION_LINK, |
| 197 false)); | 213 false)); |
| 198 } | 214 } |
| 199 | 215 |
| 200 void AppListViewDelegate::OpenFeedback() { | 216 void AppListViewDelegate::OpenFeedback() { |
| 201 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow( | 217 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow( |
| 202 controller_->GetAppListWindow()); | 218 controller_->GetAppListWindow()); |
| 203 Browser* browser = chrome::FindOrCreateTabbedBrowser( | 219 Browser* browser = chrome::FindOrCreateTabbedBrowser( |
| 204 profile_, desktop); | 220 profile_, desktop); |
| 205 chrome::ShowFeedbackPage(browser, std::string(), | 221 chrome::ShowFeedbackPage(browser, std::string(), |
| 206 chrome::kAppLauncherCategoryTag); | 222 chrome::kAppLauncherCategoryTag); |
| 207 } | 223 } |
| 224 |
| 225 void AppListViewDelegate::OnSigninSuccess() { |
| 226 OnProfileChanged(); |
| 227 } |
| 228 |
| 229 void AppListViewDelegate::Observe( |
| 230 int type, |
| 231 const content::NotificationSource& source, |
| 232 const content::NotificationDetails& details) { |
| 233 OnProfileChanged(); |
| 234 } |
| OLD | NEW |