Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / app_list / app_list_view_delegate.h
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
26 class AppListControllerDelegate;
27 class Profile;
28
29 namespace apps {
30 class CustomLauncherPageContents;
31 }
32
33 namespace app_list {
34 class SearchController;
35 class SearchResourceManager;
36 class SpeechUIModel;
37 }
38
39 namespace base {
40 class FilePath;
41 }
42
43 namespace gfx {
44 class ImageSkia;
45 }
46
47 #if defined(USE_ASH)
48 class AppSyncUIStateWatcher;
49 #endif
50
51 class AppListViewDelegate : public app_list::AppListViewDelegate,
52                             public app_list::StartPageObserver,
53                             public HotwordClient,
54                             public ProfileInfoCacheObserver,
55                             public SigninManagerBase::Observer,
56                             public SigninManagerFactory::Observer,
57                             public content::NotificationObserver {
58  public:
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;
63
64   // Configure the AppList for the given |profile|.
65   void SetProfile(Profile* profile);
66   Profile* profile() { return profile_; }
67
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,
79                         bool auto_launch,
80                         int event_flags) override;
81   void InvokeSearchResultAction(app_list::SearchResult* result,
82                                 int action_index,
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;
99 #endif
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;
105
106  private:
107   // Updates the speech webview and start page for the current |profile_|.
108   void SetUpSearchUI();
109
110   // Updates the app list's ProfileMenuItems for the current |profile_|.
111   void SetUpProfileSwitcher();
112
113   // Updates the app list's custom launcher pages for the current |profile_|.
114   void SetUpCustomLauncherPages();
115
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;
121
122   // Overridden from HotwordClient:
123   void OnHotwordStateChanged(bool started) override;
124   void OnHotwordRecognized() override;
125
126   // Overridden from SigninManagerFactory::Observer:
127   void SigninManagerCreated(SigninManagerBase* manager) override;
128   void SigninManagerShutdown(SigninManagerBase* manager) override;
129
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;
137
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;
144
145   // Overridden from content::NotificationObserver:
146   void Observe(int type,
147                const content::NotificationSource& source,
148                const content::NotificationDetails& details) override;
149
150   // Unowned pointer to the controller.
151   AppListControllerDelegate* controller_;
152   // Unowned pointer to the associated profile. May change if SetProfileByPath
153   // is called.
154   Profile* profile_;
155   // Unowned pointer to the model owned by AppListSyncableService. Will change
156   // if |profile_| changes.
157   app_list::AppListModel* model_;
158
159   // Note: order ensures |search_resource_manager_| is destroyed before
160   // |speech_ui_|.
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_;
164
165   base::TimeDelta auto_launch_timeout_;
166
167   Users users_;
168
169 #if defined(USE_ASH)
170   scoped_ptr<AppSyncUIStateWatcher> app_sync_ui_state_watcher_;
171 #endif
172
173   ObserverList<app_list::AppListViewDelegateObserver> observers_;
174
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_;
178
179   // Window contents of additional custom launcher pages.
180   ScopedVector<apps::CustomLauncherPageContents> custom_page_contents_;
181
182   // Registers for NOTIFICATION_APP_TERMINATING to unload custom launcher pages.
183   content::NotificationRegistrar registrar_;
184
185   DISALLOW_COPY_AND_ASSIGN(AppListViewDelegate);
186 };
187
188 #endif  // CHROME_BROWSER_UI_APP_LIST_APP_LIST_VIEW_DELEGATE_H_