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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_APP_LIST_APP_LIST_VIEW_DELEGATE_H_
6 #define CHROME_BROWSER_UI_APP_LIST_APP_LIST_VIEW_DELEGATE_H_
10 #include "base/basictypes.h"
11 #include "base/callback_forward.h"
12 #include "base/compiler_specific.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/scoped_vector.h"
16 #include "base/observer_list.h"
17 #include "base/scoped_observer.h"
18 #include "chrome/browser/profiles/profile_info_cache_observer.h"
19 #include "chrome/browser/search/hotword_client.h"
20 #include "chrome/browser/signin/signin_manager_factory.h"
21 #include "chrome/browser/ui/app_list/start_page_observer.h"
22 #include "components/search_engines/template_url_service.h"
23 #include "components/search_engines/template_url_service_observer.h"
24 #include "components/signin/core/browser/signin_manager_base.h"
25 #include "content/public/browser/notification_observer.h"
26 #include "content/public/browser/notification_registrar.h"
27 #include "ui/app_list/app_list_view_delegate.h"
29 class AppListControllerDelegate
;
33 class CustomLauncherPageContents
;
37 class LauncherPageEventDispatcher
;
38 class SearchController
;
39 class SearchResourceManager
;
48 struct SpeechRecognitionSessionPreamble
;
56 class AppSyncUIStateWatcher
;
59 class AppListViewDelegate
: public app_list::AppListViewDelegate
,
60 public app_list::StartPageObserver
,
62 public ProfileInfoCacheObserver
,
63 public SigninManagerBase::Observer
,
64 public SigninManagerFactory::Observer
,
65 public content::NotificationObserver
,
66 public TemplateURLServiceObserver
{
68 // Constructs Chrome's AppListViewDelegate with a NULL Profile.
69 // Does not take ownership of |controller|. TODO(tapted): It should.
70 explicit AppListViewDelegate(AppListControllerDelegate
* controller
);
71 ~AppListViewDelegate() override
;
73 // Configure the AppList for the given |profile|.
74 void SetProfile(Profile
* profile
);
75 Profile
* profile() { return profile_
; }
77 // Invoked to toggle the status of speech recognition based on a hotword
79 void ToggleSpeechRecognitionForHotword(
80 const scoped_refptr
<content::SpeechRecognitionSessionPreamble
>& preamble
);
82 // Overridden from app_list::AppListViewDelegate:
83 bool ForceNativeDesktop() const override
;
84 void SetProfileByPath(const base::FilePath
& profile_path
) override
;
85 app_list::AppListModel
* GetModel() override
;
86 app_list::SpeechUIModel
* GetSpeechUI() override
;
87 void GetShortcutPathForApp(
88 const std::string
& app_id
,
89 const base::Callback
<void(const base::FilePath
&)>& callback
) override
;
90 void StartSearch() override
;
91 void StopSearch() override
;
92 void OpenSearchResult(app_list::SearchResult
* result
,
94 int event_flags
) override
;
95 void InvokeSearchResultAction(app_list::SearchResult
* result
,
97 int event_flags
) override
;
98 base::TimeDelta
GetAutoLaunchTimeout() override
;
99 void AutoLaunchCanceled() override
;
100 void ViewInitialized() override
;
101 void Dismiss() override
;
102 void ViewClosing() override
;
103 gfx::ImageSkia
GetWindowIcon() override
;
104 void OpenSettings() override
;
105 void OpenHelp() override
;
106 void OpenFeedback() override
;
107 void ToggleSpeechRecognition() override
;
108 void ShowForProfileByPath(const base::FilePath
& profile_path
) override
;
109 #if defined(TOOLKIT_VIEWS)
110 views::View
* CreateStartPageWebView(const gfx::Size
& size
) override
;
111 std::vector
<views::View
*> CreateCustomPageWebViews(
112 const gfx::Size
& size
) override
;
113 void CustomLauncherPageAnimationChanged(double progress
) override
;
114 void CustomLauncherPagePopSubpage() override
;
116 bool IsSpeechRecognitionEnabled() override
;
117 const Users
& GetUsers() const override
;
118 bool ShouldCenterWindow() const override
;
119 void AddObserver(app_list::AppListViewDelegateObserver
* observer
) override
;
120 void RemoveObserver(app_list::AppListViewDelegateObserver
* observer
) override
;
122 // Overridden from TemplateURLServiceObserver:
123 void OnTemplateURLServiceChanged() override
;
126 // Updates the speech webview and start page for the current |profile_|.
127 void SetUpSearchUI();
129 // Updates the app list's ProfileMenuItems for the current |profile_|.
130 void SetUpProfileSwitcher();
132 // Updates the app list's custom launcher pages for the current |profile_|.
133 void SetUpCustomLauncherPages();
135 // Overridden from app_list::StartPageObserver:
136 void OnSpeechResult(const base::string16
& result
, bool is_final
) override
;
137 void OnSpeechSoundLevelChanged(int16 level
) override
;
138 void OnSpeechRecognitionStateChanged(
139 app_list::SpeechRecognitionState new_state
) override
;
141 // Overridden from HotwordClient:
142 void OnHotwordStateChanged(bool started
) override
;
143 void OnHotwordRecognized(
144 const scoped_refptr
<content::SpeechRecognitionSessionPreamble
>& preamble
)
147 // Overridden from SigninManagerFactory::Observer:
148 void SigninManagerCreated(SigninManagerBase
* manager
) override
;
149 void SigninManagerShutdown(SigninManagerBase
* manager
) override
;
151 // Overridden from SigninManagerBase::Observer:
152 void GoogleSigninFailed(const GoogleServiceAuthError
& error
) override
;
153 void GoogleSigninSucceeded(const std::string
& account_id
,
154 const std::string
& username
,
155 const std::string
& password
) override
;
156 void GoogleSignedOut(const std::string
& account_id
,
157 const std::string
& username
) override
;
159 // Overridden from ProfileInfoCacheObserver:
160 void OnProfileAdded(const base::FilePath
& profile_path
) override
;
161 void OnProfileWasRemoved(const base::FilePath
& profile_path
,
162 const base::string16
& profile_name
) override
;
163 void OnProfileNameChanged(const base::FilePath
& profile_path
,
164 const base::string16
& old_profile_name
) override
;
166 // Overridden from content::NotificationObserver:
167 void Observe(int type
,
168 const content::NotificationSource
& source
,
169 const content::NotificationDetails
& details
) override
;
171 // Unowned pointer to the controller.
172 AppListControllerDelegate
* controller_
;
173 // Unowned pointer to the associated profile. May change if SetProfileByPath
176 // Unowned pointer to the model owned by AppListSyncableService. Will change
177 // if |profile_| changes.
178 app_list::AppListModel
* model_
;
180 // Note: order ensures |search_resource_manager_| is destroyed before
182 scoped_ptr
<app_list::SpeechUIModel
> speech_ui_
;
183 scoped_ptr
<app_list::SearchResourceManager
> search_resource_manager_
;
184 scoped_ptr
<app_list::SearchController
> search_controller_
;
186 scoped_ptr
<app_list::LauncherPageEventDispatcher
>
187 launcher_page_event_dispatcher_
;
189 base::TimeDelta auto_launch_timeout_
;
190 // Determines whether the current search was initiated by speech.
191 bool is_voice_query_
;
196 scoped_ptr
<AppSyncUIStateWatcher
> app_sync_ui_state_watcher_
;
199 base::ObserverList
<app_list::AppListViewDelegateObserver
> observers_
;
201 ScopedObserver
<TemplateURLService
, AppListViewDelegate
>
202 template_url_service_observer_
;
204 // Used to track the SigninManagers that this instance is observing so that
205 // this instance can be removed as an observer on its destruction.
206 ScopedObserver
<SigninManagerBase
, AppListViewDelegate
> scoped_observer_
;
208 // Window contents of additional custom launcher pages.
209 ScopedVector
<apps::CustomLauncherPageContents
> custom_page_contents_
;
211 // Registers for NOTIFICATION_APP_TERMINATING to unload custom launcher pages.
212 content::NotificationRegistrar registrar_
;
214 DISALLOW_COPY_AND_ASSIGN(AppListViewDelegate
);
217 #endif // CHROME_BROWSER_UI_APP_LIST_APP_LIST_VIEW_DELEGATE_H_