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.
4
5#ifndef CHROME_BROWSER_UI_APP_LIST_APP_LIST_VIEW_DELEGATE_H_
6#define CHROME_BROWSER_UI_APP_LIST_APP_LIST_VIEW_DELEGATE_H_
7
8#include <string>
9
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"
25
26class AppListControllerDelegate;
27class Profile;
28
29namespace apps {
30class CustomLauncherPageContents;
31}
32
33namespace app_list {
34class SearchController;
35class SpeechUIModel;
36}
37
38namespace base {
39class FilePath;
40}
41
42namespace gfx {
43class ImageSkia;
44}
45
46#if defined(USE_ASH)
47class AppSyncUIStateWatcher;
48#endif
49
50class AppListViewDelegate : public app_list::AppListViewDelegate,
51                            public app_list::StartPageObserver,
52                            public HotwordClient,
53                            public ProfileInfoCacheObserver,
54                            public SigninManagerBase::Observer,
55                            public SigninManagerFactory::Observer,
56                            public content::NotificationObserver {
57 public:
58  // Constructs Chrome's AppListViewDelegate with a NULL Profile.
59  // Does not take ownership of |controller|. TODO(tapted): It should.
60  explicit AppListViewDelegate(AppListControllerDelegate* controller);
61  virtual ~AppListViewDelegate();
62
63  // Configure the AppList for the given |profile|.
64  void SetProfile(Profile* profile);
65  Profile* profile() { return profile_; }
66
67 private:
68  // Updates the speech webview and start page for the current |profile_|.
69  void SetUpSearchUI();
70
71  // Updates the app list's ProfileMenuItems for the current |profile_|.
72  void SetUpProfileSwitcher();
73
74  // Updates the app list's custom launcher pages for the current |profile_|.
75  void SetUpCustomLauncherPages();
76
77  // Overridden from app_list::AppListViewDelegate:
78  virtual bool ForceNativeDesktop() const OVERRIDE;
79  virtual void SetProfileByPath(const base::FilePath& profile_path) OVERRIDE;
80  virtual app_list::AppListModel* GetModel() OVERRIDE;
81  virtual app_list::SpeechUIModel* GetSpeechUI() OVERRIDE;
82  virtual void GetShortcutPathForApp(
83      const std::string& app_id,
84      const base::Callback<void(const base::FilePath&)>& callback) OVERRIDE;
85  virtual void StartSearch() OVERRIDE;
86  virtual void StopSearch() OVERRIDE;
87  virtual void OpenSearchResult(app_list::SearchResult* result,
88                                bool auto_launch,
89                                int event_flags) OVERRIDE;
90  virtual void InvokeSearchResultAction(app_list::SearchResult* result,
91                                        int action_index,
92                                        int event_flags) OVERRIDE;
93  virtual base::TimeDelta GetAutoLaunchTimeout() OVERRIDE;
94  virtual void AutoLaunchCanceled() OVERRIDE;
95  virtual void ViewInitialized() OVERRIDE;
96  virtual void Dismiss() OVERRIDE;
97  virtual void ViewClosing() OVERRIDE;
98  virtual gfx::ImageSkia GetWindowIcon() OVERRIDE;
99  virtual void OpenSettings() OVERRIDE;
100  virtual void OpenHelp() OVERRIDE;
101  virtual void OpenFeedback() OVERRIDE;
102  virtual void ToggleSpeechRecognition() OVERRIDE;
103  virtual void ShowForProfileByPath(
104      const base::FilePath& profile_path) OVERRIDE;
105#if defined(TOOLKIT_VIEWS)
106  virtual views::View* CreateStartPageWebView(const gfx::Size& size) OVERRIDE;
107  virtual std::vector<views::View*> CreateCustomPageWebViews(
108      const gfx::Size& size) OVERRIDE;
109#endif
110  virtual bool IsSpeechRecognitionEnabled() OVERRIDE;
111  virtual const Users& GetUsers() const OVERRIDE;
112  virtual bool ShouldCenterWindow() const OVERRIDE;
113  virtual void AddObserver(
114      app_list::AppListViewDelegateObserver* observer) OVERRIDE;
115  virtual void RemoveObserver(
116      app_list::AppListViewDelegateObserver* observer) OVERRIDE;
117
118  // Overridden from app_list::StartPageObserver:
119  virtual void OnSpeechResult(const base::string16& result,
120                              bool is_final) OVERRIDE;
121  virtual void OnSpeechSoundLevelChanged(int16 level) OVERRIDE;
122  virtual void OnSpeechRecognitionStateChanged(
123      app_list::SpeechRecognitionState new_state) OVERRIDE;
124
125  // Overridden from HotwordClient:
126  virtual void OnHotwordStateChanged(bool started) OVERRIDE;
127  virtual void OnHotwordRecognized() OVERRIDE;
128
129  // Overridden from SigninManagerFactory::Observer:
130  virtual void SigninManagerCreated(SigninManagerBase* manager) OVERRIDE;
131  virtual void SigninManagerShutdown(SigninManagerBase* manager) OVERRIDE;
132
133  // Overridden from SigninManagerBase::Observer:
134  virtual void GoogleSigninFailed(const GoogleServiceAuthError& error) OVERRIDE;
135  virtual void GoogleSigninSucceeded(const std::string& account_id,
136                                     const std::string& username,
137                                     const std::string& password) OVERRIDE;
138  virtual void GoogleSignedOut(const std::string& account_id,
139                               const std::string& username) OVERRIDE;
140
141  // Overridden from ProfileInfoCacheObserver:
142  virtual void OnProfileAdded(const base::FilePath& profile_path) OVERRIDE;
143  virtual void OnProfileWasRemoved(const base::FilePath& profile_path,
144                                   const base::string16& profile_name) OVERRIDE;
145  virtual void OnProfileNameChanged(
146      const base::FilePath& profile_path,
147      const base::string16& old_profile_name) OVERRIDE;
148
149  // Overridden from content::NotificationObserver:
150  virtual void Observe(int type,
151                       const content::NotificationSource& source,
152                       const content::NotificationDetails& details) OVERRIDE;
153
154  // Unowned pointer to the controller.
155  AppListControllerDelegate* controller_;
156  // Unowned pointer to the associated profile. May change if SetProfileByPath
157  // is called.
158  Profile* profile_;
159  // Unowned pointer to the model owned by AppListSyncableService. Will change
160  // if |profile_| changes.
161  app_list::AppListModel* model_;
162
163  // Note: order ensures |search_controller_| is destroyed before |speech_ui_|.
164  scoped_ptr<app_list::SpeechUIModel> speech_ui_;
165  scoped_ptr<app_list::SearchController> search_controller_;
166
167  base::TimeDelta auto_launch_timeout_;
168
169  Users users_;
170
171#if defined(USE_ASH)
172  scoped_ptr<AppSyncUIStateWatcher> app_sync_ui_state_watcher_;
173#endif
174
175  ObserverList<app_list::AppListViewDelegateObserver> observers_;
176
177  // Used to track the SigninManagers that this instance is observing so that
178  // this instance can be removed as an observer on its destruction.
179  ScopedObserver<SigninManagerBase, AppListViewDelegate> scoped_observer_;
180
181  // Window contents of additional custom launcher pages.
182  ScopedVector<apps::CustomLauncherPageContents> custom_page_contents_;
183
184  // Registers for NOTIFICATION_APP_TERMINATING to unload custom launcher pages.
185  content::NotificationRegistrar registrar_;
186
187  DISALLOW_COPY_AND_ASSIGN(AppListViewDelegate);
188};
189
190#endif  // CHROME_BROWSER_UI_APP_LIST_APP_LIST_VIEW_DELEGATE_H_
191