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/scoped_ptr.h"
14 #include "base/memory/scoped_vector.h"
15 #include "base/observer_list.h"
16 #include "base/scoped_observer.h"
17 #include "chrome/browser/profiles/profile_info_cache_observer.h"
18 #include "chrome/browser/search/hotword_client.h"
19 #include "chrome/browser/signin/signin_manager_factory.h"
20 #include "chrome/browser/ui/app_list/start_page_observer.h"
21 #include "components/signin/core/browser/signin_manager_base.h"
22 #include "content/public/browser/notification_observer.h"
23 #include "content/public/browser/notification_registrar.h"
24 #include "ui/app_list/app_list_view_delegate.h"
26 class AppListControllerDelegate;
30 class CustomLauncherPageContents;
34 class SearchController;
35 class SearchResourceManager;
48 class AppSyncUIStateWatcher;
51 class AppListViewDelegate : public app_list::AppListViewDelegate,
52 public app_list::StartPageObserver,
54 public ProfileInfoCacheObserver,
55 public SigninManagerBase::Observer,
56 public SigninManagerFactory::Observer,
57 public content::NotificationObserver {
59 // Constructs Chrome's AppListViewDelegate with a NULL Profile.
60 // Does not take ownership of |controller|. TODO(tapted): It should.
61 explicit AppListViewDelegate(AppListControllerDelegate* controller);
62 ~AppListViewDelegate() override;
64 // Configure the AppList for the given |profile|.
65 void SetProfile(Profile* profile);
66 Profile* profile() { return profile_; }
68 // Overridden from app_list::AppListViewDelegate:
69 bool ForceNativeDesktop() const override;
70 void SetProfileByPath(const base::FilePath& profile_path) override;
71 app_list::AppListModel* GetModel() override;
72 app_list::SpeechUIModel* GetSpeechUI() override;
73 void GetShortcutPathForApp(
74 const std::string& app_id,
75 const base::Callback<void(const base::FilePath&)>& callback) override;
76 void StartSearch() override;
77 void StopSearch() override;
78 void OpenSearchResult(app_list::SearchResult* result,
80 int event_flags) override;
81 void InvokeSearchResultAction(app_list::SearchResult* result,
83 int event_flags) override;
84 base::TimeDelta GetAutoLaunchTimeout() override;
85 void AutoLaunchCanceled() override;
86 void ViewInitialized() override;
87 void Dismiss() override;
88 void ViewClosing() override;
89 gfx::ImageSkia GetWindowIcon() override;
90 void OpenSettings() override;
91 void OpenHelp() override;
92 void OpenFeedback() override;
93 void ToggleSpeechRecognition() override;
94 void ShowForProfileByPath(const base::FilePath& profile_path) override;
95 #if defined(TOOLKIT_VIEWS)
96 views::View* CreateStartPageWebView(const gfx::Size& size) override;
97 std::vector<views::View*> CreateCustomPageWebViews(
98 const gfx::Size& size) override;
100 bool IsSpeechRecognitionEnabled() override;
101 const Users& GetUsers() const override;
102 bool ShouldCenterWindow() const override;
103 void AddObserver(app_list::AppListViewDelegateObserver* observer) override;
104 void RemoveObserver(app_list::AppListViewDelegateObserver* observer) override;
107 // Updates the speech webview and start page for the current |profile_|.
108 void SetUpSearchUI();
110 // Updates the app list's ProfileMenuItems for the current |profile_|.
111 void SetUpProfileSwitcher();
113 // Updates the app list's custom launcher pages for the current |profile_|.
114 void SetUpCustomLauncherPages();
116 // Overridden from app_list::StartPageObserver:
117 void OnSpeechResult(const base::string16& result, bool is_final) override;
118 void OnSpeechSoundLevelChanged(int16 level) override;
119 void OnSpeechRecognitionStateChanged(
120 app_list::SpeechRecognitionState new_state) override;
122 // Overridden from HotwordClient:
123 void OnHotwordStateChanged(bool started) override;
124 void OnHotwordRecognized() override;
126 // Overridden from SigninManagerFactory::Observer:
127 void SigninManagerCreated(SigninManagerBase* manager) override;
128 void SigninManagerShutdown(SigninManagerBase* manager) override;
130 // Overridden from SigninManagerBase::Observer:
131 void GoogleSigninFailed(const GoogleServiceAuthError& error) override;
132 void GoogleSigninSucceeded(const std::string& account_id,
133 const std::string& username,
134 const std::string& password) override;
135 void GoogleSignedOut(const std::string& account_id,
136 const std::string& username) override;
138 // Overridden from ProfileInfoCacheObserver:
139 void OnProfileAdded(const base::FilePath& profile_path) override;
140 void OnProfileWasRemoved(const base::FilePath& profile_path,
141 const base::string16& profile_name) override;
142 void OnProfileNameChanged(const base::FilePath& profile_path,
143 const base::string16& old_profile_name) override;
145 // Overridden from content::NotificationObserver:
146 void Observe(int type,
147 const content::NotificationSource& source,
148 const content::NotificationDetails& details) override;
150 // Unowned pointer to the controller.
151 AppListControllerDelegate* controller_;
152 // Unowned pointer to the associated profile. May change if SetProfileByPath
155 // Unowned pointer to the model owned by AppListSyncableService. Will change
156 // if |profile_| changes.
157 app_list::AppListModel* model_;
159 // Note: order ensures |search_resource_manager_| is destroyed before
161 scoped_ptr<app_list::SpeechUIModel> speech_ui_;
162 scoped_ptr<app_list::SearchResourceManager> search_resource_manager_;
163 scoped_ptr<app_list::SearchController> search_controller_;
165 base::TimeDelta auto_launch_timeout_;
170 scoped_ptr<AppSyncUIStateWatcher> app_sync_ui_state_watcher_;
173 ObserverList<app_list::AppListViewDelegateObserver> observers_;
175 // Used to track the SigninManagers that this instance is observing so that
176 // this instance can be removed as an observer on its destruction.
177 ScopedObserver<SigninManagerBase, AppListViewDelegate> scoped_observer_;
179 // Window contents of additional custom launcher pages.
180 ScopedVector<apps::CustomLauncherPageContents> custom_page_contents_;
182 // Registers for NOTIFICATION_APP_TERMINATING to unload custom launcher pages.
183 content::NotificationRegistrar registrar_;
185 DISALLOW_COPY_AND_ASSIGN(AppListViewDelegate);
188 #endif // CHROME_BROWSER_UI_APP_LIST_APP_LIST_VIEW_DELEGATE_H_