| 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 #ifndef CHROME_BROWSER_UI_APP_LIST_APP_LIST_VIEW_DELEGATE_H_ | 5 #ifndef CHROME_BROWSER_UI_APP_LIST_APP_LIST_VIEW_DELEGATE_H_ |
| 6 #define CHROME_BROWSER_UI_APP_LIST_APP_LIST_VIEW_DELEGATE_H_ | 6 #define CHROME_BROWSER_UI_APP_LIST_APP_LIST_VIEW_DELEGATE_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/callback_forward.h" | |
| 15 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 16 #include "base/macros.h" | 15 #include "base/macros.h" |
| 17 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 18 #include "base/scoped_observer.h" | 17 #include "base/scoped_observer.h" |
| 19 #include "chrome/browser/profiles/profile_attributes_storage.h" | |
| 20 #include "chrome/browser/search/hotword_client.h" | 18 #include "chrome/browser/search/hotword_client.h" |
| 21 #include "chrome/browser/signin/signin_manager_factory.h" | |
| 22 #include "chrome/browser/ui/app_list/start_page_observer.h" | 19 #include "chrome/browser/ui/app_list/start_page_observer.h" |
| 23 #include "components/search_engines/template_url_service.h" | 20 #include "components/search_engines/template_url_service.h" |
| 24 #include "components/search_engines/template_url_service_observer.h" | 21 #include "components/search_engines/template_url_service_observer.h" |
| 25 #include "components/signin/core/browser/signin_manager_base.h" | |
| 26 #include "content/public/browser/notification_observer.h" | 22 #include "content/public/browser/notification_observer.h" |
| 27 #include "content/public/browser/notification_registrar.h" | 23 #include "content/public/browser/notification_registrar.h" |
| 28 #include "ui/app_list/app_list_view_delegate.h" | 24 #include "ui/app_list/app_list_view_delegate.h" |
| 29 | 25 |
| 30 class AppListControllerDelegate; | |
| 31 class Profile; | |
| 32 | |
| 33 namespace app_list { | 26 namespace app_list { |
| 34 class CustomLauncherPageContents; | 27 class CustomLauncherPageContents; |
| 35 class LauncherPageEventDispatcher; | 28 class LauncherPageEventDispatcher; |
| 36 class SearchController; | 29 class SearchController; |
| 37 class SearchResourceManager; | 30 class SearchResourceManager; |
| 38 class SpeechUIModel; | 31 class SpeechUIModel; |
| 39 } | 32 } |
| 40 | 33 |
| 41 namespace base { | |
| 42 class FilePath; | |
| 43 } | |
| 44 | |
| 45 namespace content { | 34 namespace content { |
| 46 struct SpeechRecognitionSessionPreamble; | 35 struct SpeechRecognitionSessionPreamble; |
| 47 } | 36 } |
| 48 | 37 |
| 49 #if defined(USE_ASH) | 38 class AppListControllerDelegate; |
| 50 class AppSyncUIStateWatcher; | 39 class AppSyncUIStateWatcher; |
| 51 #endif | 40 class Profile; |
| 52 | 41 |
| 53 class AppListViewDelegate : public app_list::AppListViewDelegate, | 42 class AppListViewDelegate : public app_list::AppListViewDelegate, |
| 54 public app_list::StartPageObserver, | 43 public app_list::StartPageObserver, |
| 55 public HotwordClient, | 44 public HotwordClient, |
| 56 public ProfileAttributesStorage::Observer, | |
| 57 public SigninManagerBase::Observer, | |
| 58 public SigninManagerFactory::Observer, | |
| 59 public content::NotificationObserver, | 45 public content::NotificationObserver, |
| 60 public TemplateURLServiceObserver { | 46 public TemplateURLServiceObserver { |
| 61 public: | 47 public: |
| 62 // Constructs Chrome's AppListViewDelegate with a NULL Profile. | 48 // Constructs Chrome's AppListViewDelegate with a NULL Profile. |
| 63 // Does not take ownership of |controller|. TODO(tapted): It should. | 49 // Does not take ownership of |controller|. TODO(tapted): It should. |
| 64 explicit AppListViewDelegate(AppListControllerDelegate* controller); | 50 explicit AppListViewDelegate(AppListControllerDelegate* controller); |
| 65 ~AppListViewDelegate() override; | 51 ~AppListViewDelegate() override; |
| 66 | 52 |
| 67 // Configure the AppList for the given |profile|. | 53 // Configure the AppList for the given |profile|. |
| 68 void SetProfile(Profile* profile); | 54 void SetProfile(Profile* profile); |
| 69 Profile* profile() { return profile_; } | 55 Profile* profile() { return profile_; } |
| 70 | 56 |
| 71 // Invoked to start speech recognition based on a hotword trigger. | 57 // Invoked to start speech recognition based on a hotword trigger. |
| 72 void StartSpeechRecognitionForHotword( | 58 void StartSpeechRecognitionForHotword( |
| 73 const scoped_refptr<content::SpeechRecognitionSessionPreamble>& preamble); | 59 const scoped_refptr<content::SpeechRecognitionSessionPreamble>& preamble); |
| 74 | 60 |
| 75 // Overridden from app_list::AppListViewDelegate: | 61 // Overridden from app_list::AppListViewDelegate: |
| 76 bool ForceNativeDesktop() const override; | |
| 77 void SetProfileByPath(const base::FilePath& profile_path) override; | |
| 78 app_list::AppListModel* GetModel() override; | 62 app_list::AppListModel* GetModel() override; |
| 79 app_list::SpeechUIModel* GetSpeechUI() override; | 63 app_list::SpeechUIModel* GetSpeechUI() override; |
| 80 void StartSearch() override; | 64 void StartSearch() override; |
| 81 void StopSearch() override; | 65 void StopSearch() override; |
| 82 void OpenSearchResult(app_list::SearchResult* result, | 66 void OpenSearchResult(app_list::SearchResult* result, |
| 83 bool auto_launch, | 67 bool auto_launch, |
| 84 int event_flags) override; | 68 int event_flags) override; |
| 85 void InvokeSearchResultAction(app_list::SearchResult* result, | 69 void InvokeSearchResultAction(app_list::SearchResult* result, |
| 86 int action_index, | 70 int action_index, |
| 87 int event_flags) override; | 71 int event_flags) override; |
| 88 base::TimeDelta GetAutoLaunchTimeout() override; | 72 base::TimeDelta GetAutoLaunchTimeout() override; |
| 89 void AutoLaunchCanceled() override; | 73 void AutoLaunchCanceled() override; |
| 90 void ViewInitialized() override; | 74 void ViewInitialized() override; |
| 91 void Dismiss() override; | 75 void Dismiss() override; |
| 92 void ViewClosing() override; | 76 void ViewClosing() override; |
| 93 void OpenHelp() override; | |
| 94 void OpenFeedback() override; | |
| 95 void StartSpeechRecognition() override; | 77 void StartSpeechRecognition() override; |
| 96 void StopSpeechRecognition() override; | 78 void StopSpeechRecognition() override; |
| 97 void ShowForProfileByPath(const base::FilePath& profile_path) override; | |
| 98 #if defined(TOOLKIT_VIEWS) | |
| 99 views::View* CreateStartPageWebView(const gfx::Size& size) override; | 79 views::View* CreateStartPageWebView(const gfx::Size& size) override; |
| 100 std::vector<views::View*> CreateCustomPageWebViews( | 80 std::vector<views::View*> CreateCustomPageWebViews( |
| 101 const gfx::Size& size) override; | 81 const gfx::Size& size) override; |
| 102 void CustomLauncherPageAnimationChanged(double progress) override; | 82 void CustomLauncherPageAnimationChanged(double progress) override; |
| 103 void CustomLauncherPagePopSubpage() override; | 83 void CustomLauncherPagePopSubpage() override; |
| 104 #endif | |
| 105 bool IsSpeechRecognitionEnabled() override; | 84 bool IsSpeechRecognitionEnabled() override; |
| 106 const Users& GetUsers() const override; | |
| 107 | 85 |
| 108 // Overridden from TemplateURLServiceObserver: | 86 // Overridden from TemplateURLServiceObserver: |
| 109 void OnTemplateURLServiceChanged() override; | 87 void OnTemplateURLServiceChanged() override; |
| 110 | 88 |
| 111 private: | 89 private: |
| 112 // Updates the speech webview and start page for the current |profile_|. | 90 // Updates the speech webview and start page for the current |profile_|. |
| 113 void SetUpSearchUI(); | 91 void SetUpSearchUI(); |
| 114 | 92 |
| 115 // Updates the app list's ProfileMenuItems for the current |profile_|. | |
| 116 void SetUpProfileSwitcher(); | |
| 117 | |
| 118 // Updates the app list's custom launcher pages for the current |profile_|. | 93 // Updates the app list's custom launcher pages for the current |profile_|. |
| 119 void SetUpCustomLauncherPages(); | 94 void SetUpCustomLauncherPages(); |
| 120 | 95 |
| 121 // Overridden from app_list::StartPageObserver: | 96 // Overridden from app_list::StartPageObserver: |
| 122 void OnSpeechResult(const base::string16& result, bool is_final) override; | 97 void OnSpeechResult(const base::string16& result, bool is_final) override; |
| 123 void OnSpeechSoundLevelChanged(int16_t level) override; | 98 void OnSpeechSoundLevelChanged(int16_t level) override; |
| 124 void OnSpeechRecognitionStateChanged( | 99 void OnSpeechRecognitionStateChanged( |
| 125 app_list::SpeechRecognitionState new_state) override; | 100 app_list::SpeechRecognitionState new_state) override; |
| 126 | 101 |
| 127 // Overridden from HotwordClient: | 102 // Overridden from HotwordClient: |
| 128 void OnHotwordStateChanged(bool started) override; | 103 void OnHotwordStateChanged(bool started) override; |
| 129 void OnHotwordRecognized( | 104 void OnHotwordRecognized( |
| 130 const scoped_refptr<content::SpeechRecognitionSessionPreamble>& preamble) | 105 const scoped_refptr<content::SpeechRecognitionSessionPreamble>& preamble) |
| 131 override; | 106 override; |
| 132 | 107 |
| 133 // Overridden from SigninManagerFactory::Observer: | |
| 134 void SigninManagerCreated(SigninManagerBase* manager) override; | |
| 135 void SigninManagerShutdown(SigninManagerBase* manager) override; | |
| 136 | |
| 137 // Overridden from SigninManagerBase::Observer: | |
| 138 void GoogleSigninFailed(const GoogleServiceAuthError& error) override; | |
| 139 void GoogleSigninSucceeded(const std::string& account_id, | |
| 140 const std::string& username, | |
| 141 const std::string& password) override; | |
| 142 void GoogleSignedOut(const std::string& account_id, | |
| 143 const std::string& username) override; | |
| 144 | |
| 145 // Overridden from ProfileAttributesStorage::Observer: | |
| 146 void OnProfileAdded(const base::FilePath& profile_path) override; | |
| 147 void OnProfileWasRemoved(const base::FilePath& profile_path, | |
| 148 const base::string16& profile_name) override; | |
| 149 void OnProfileNameChanged(const base::FilePath& profile_path, | |
| 150 const base::string16& old_profile_name) override; | |
| 151 | |
| 152 // Overridden from content::NotificationObserver: | 108 // Overridden from content::NotificationObserver: |
| 153 void Observe(int type, | 109 void Observe(int type, |
| 154 const content::NotificationSource& source, | 110 const content::NotificationSource& source, |
| 155 const content::NotificationDetails& details) override; | 111 const content::NotificationDetails& details) override; |
| 156 | 112 |
| 157 // Unowned pointer to the controller. | 113 // Unowned pointer to the controller. |
| 158 AppListControllerDelegate* controller_; | 114 AppListControllerDelegate* controller_; |
| 159 // Unowned pointer to the associated profile. May change if SetProfileByPath | 115 // Unowned pointer to the associated profile. May change if SetProfileByPath |
| 160 // is called. | 116 // is called. |
| 161 Profile* profile_; | 117 Profile* profile_; |
| 162 // Unowned pointer to the model owned by AppListSyncableService. Will change | 118 // Unowned pointer to the model owned by AppListSyncableService. Will change |
| 163 // if |profile_| changes. | 119 // if |profile_| changes. |
| 164 app_list::AppListModel* model_; | 120 app_list::AppListModel* model_; |
| 165 | 121 |
| 166 // Note: order ensures |search_resource_manager_| is destroyed before | 122 // Note: order ensures |search_resource_manager_| is destroyed before |
| 167 // |speech_ui_|. | 123 // |speech_ui_|. |
| 168 std::unique_ptr<app_list::SpeechUIModel> speech_ui_; | 124 std::unique_ptr<app_list::SpeechUIModel> speech_ui_; |
| 169 std::unique_ptr<app_list::SearchResourceManager> search_resource_manager_; | 125 std::unique_ptr<app_list::SearchResourceManager> search_resource_manager_; |
| 170 std::unique_ptr<app_list::SearchController> search_controller_; | 126 std::unique_ptr<app_list::SearchController> search_controller_; |
| 171 | 127 |
| 172 std::unique_ptr<app_list::LauncherPageEventDispatcher> | 128 std::unique_ptr<app_list::LauncherPageEventDispatcher> |
| 173 launcher_page_event_dispatcher_; | 129 launcher_page_event_dispatcher_; |
| 174 | 130 |
| 175 base::TimeDelta auto_launch_timeout_; | 131 base::TimeDelta auto_launch_timeout_; |
| 176 // Determines whether the current search was initiated by speech. | 132 // Determines whether the current search was initiated by speech. |
| 177 bool is_voice_query_; | 133 bool is_voice_query_; |
| 178 | 134 |
| 179 Users users_; | |
| 180 | |
| 181 #if defined(USE_ASH) | |
| 182 std::unique_ptr<AppSyncUIStateWatcher> app_sync_ui_state_watcher_; | 135 std::unique_ptr<AppSyncUIStateWatcher> app_sync_ui_state_watcher_; |
| 183 #endif | |
| 184 | 136 |
| 185 ScopedObserver<TemplateURLService, AppListViewDelegate> | 137 ScopedObserver<TemplateURLService, AppListViewDelegate> |
| 186 template_url_service_observer_; | 138 template_url_service_observer_; |
| 187 | 139 |
| 188 // Used to track the SigninManagers that this instance is observing so that | |
| 189 // this instance can be removed as an observer on its destruction. | |
| 190 ScopedObserver<SigninManagerBase, AppListViewDelegate> scoped_observer_; | |
| 191 | |
| 192 // Window contents of additional custom launcher pages. | 140 // Window contents of additional custom launcher pages. |
| 193 std::vector<std::unique_ptr<app_list::CustomLauncherPageContents>> | 141 std::vector<std::unique_ptr<app_list::CustomLauncherPageContents>> |
| 194 custom_page_contents_; | 142 custom_page_contents_; |
| 195 | 143 |
| 196 // Registers for NOTIFICATION_APP_TERMINATING to unload custom launcher pages. | 144 // Registers for NOTIFICATION_APP_TERMINATING to unload custom launcher pages. |
| 197 content::NotificationRegistrar registrar_; | 145 content::NotificationRegistrar registrar_; |
| 198 | 146 |
| 199 DISALLOW_COPY_AND_ASSIGN(AppListViewDelegate); | 147 DISALLOW_COPY_AND_ASSIGN(AppListViewDelegate); |
| 200 }; | 148 }; |
| 201 | 149 |
| 202 #endif // CHROME_BROWSER_UI_APP_LIST_APP_LIST_VIEW_DELEGATE_H_ | 150 #endif // CHROME_BROWSER_UI_APP_LIST_APP_LIST_VIEW_DELEGATE_H_ |
| OLD | NEW |