File: app_list_view_delegate.h

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (202 lines) | stat: -rw-r--r-- 7,885 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_APP_LIST_APP_LIST_VIEW_DELEGATE_H_
#define CHROME_BROWSER_UI_APP_LIST_APP_LIST_VIEW_DELEGATE_H_

#include <stdint.h>

#include <memory>
#include <string>
#include <vector>

#include "base/callback_forward.h"
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/scoped_observer.h"
#include "chrome/browser/profiles/profile_attributes_storage.h"
#include "chrome/browser/search/hotword_client.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/ui/app_list/start_page_observer.h"
#include "components/search_engines/template_url_service.h"
#include "components/search_engines/template_url_service_observer.h"
#include "components/signin/core/browser/signin_manager_base.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "ui/app_list/app_list_view_delegate.h"

class AppListControllerDelegate;
class Profile;

namespace app_list {
class CustomLauncherPageContents;
class LauncherPageEventDispatcher;
class SearchController;
class SearchResourceManager;
class SpeechUIModel;
}

namespace base {
class FilePath;
}

namespace content {
struct SpeechRecognitionSessionPreamble;
}

#if defined(USE_ASH)
class AppSyncUIStateWatcher;
#endif

class AppListViewDelegate : public app_list::AppListViewDelegate,
                            public app_list::StartPageObserver,
                            public HotwordClient,
                            public ProfileAttributesStorage::Observer,
                            public SigninManagerBase::Observer,
                            public SigninManagerFactory::Observer,
                            public content::NotificationObserver,
                            public TemplateURLServiceObserver {
 public:
  // Constructs Chrome's AppListViewDelegate with a NULL Profile.
  // Does not take ownership of |controller|. TODO(tapted): It should.
  explicit AppListViewDelegate(AppListControllerDelegate* controller);
  ~AppListViewDelegate() override;

  // Configure the AppList for the given |profile|.
  void SetProfile(Profile* profile);
  Profile* profile() { return profile_; }

  // Invoked to start speech recognition based on a hotword trigger.
  void StartSpeechRecognitionForHotword(
      const scoped_refptr<content::SpeechRecognitionSessionPreamble>& preamble);

  // Overridden from app_list::AppListViewDelegate:
  bool ForceNativeDesktop() const override;
  void SetProfileByPath(const base::FilePath& profile_path) override;
  app_list::AppListModel* GetModel() override;
  app_list::SpeechUIModel* GetSpeechUI() override;
  void StartSearch() override;
  void StopSearch() override;
  void OpenSearchResult(app_list::SearchResult* result,
                        bool auto_launch,
                        int event_flags) override;
  void InvokeSearchResultAction(app_list::SearchResult* result,
                                int action_index,
                                int event_flags) override;
  base::TimeDelta GetAutoLaunchTimeout() override;
  void AutoLaunchCanceled() override;
  void ViewInitialized() override;
  void Dismiss() override;
  void ViewClosing() override;
  void OpenHelp() override;
  void OpenFeedback() override;
  void StartSpeechRecognition() override;
  void StopSpeechRecognition() override;
  void ShowForProfileByPath(const base::FilePath& profile_path) override;
#if defined(TOOLKIT_VIEWS)
  views::View* CreateStartPageWebView(const gfx::Size& size) override;
  std::vector<views::View*> CreateCustomPageWebViews(
      const gfx::Size& size) override;
  void CustomLauncherPageAnimationChanged(double progress) override;
  void CustomLauncherPagePopSubpage() override;
#endif
  bool IsSpeechRecognitionEnabled() override;
  const Users& GetUsers() const override;

  // Overridden from TemplateURLServiceObserver:
  void OnTemplateURLServiceChanged() override;

 private:
  // Updates the speech webview and start page for the current |profile_|.
  void SetUpSearchUI();

  // Updates the app list's ProfileMenuItems for the current |profile_|.
  void SetUpProfileSwitcher();

  // Updates the app list's custom launcher pages for the current |profile_|.
  void SetUpCustomLauncherPages();

  // Overridden from app_list::StartPageObserver:
  void OnSpeechResult(const base::string16& result, bool is_final) override;
  void OnSpeechSoundLevelChanged(int16_t level) override;
  void OnSpeechRecognitionStateChanged(
      app_list::SpeechRecognitionState new_state) override;

  // Overridden from HotwordClient:
  void OnHotwordStateChanged(bool started) override;
  void OnHotwordRecognized(
      const scoped_refptr<content::SpeechRecognitionSessionPreamble>& preamble)
      override;

  // Overridden from SigninManagerFactory::Observer:
  void SigninManagerCreated(SigninManagerBase* manager) override;
  void SigninManagerShutdown(SigninManagerBase* manager) override;

  // Overridden from SigninManagerBase::Observer:
  void GoogleSigninFailed(const GoogleServiceAuthError& error) override;
  void GoogleSigninSucceeded(const std::string& account_id,
                             const std::string& username,
                             const std::string& password) override;
  void GoogleSignedOut(const std::string& account_id,
                       const std::string& username) override;

  // Overridden from ProfileAttributesStorage::Observer:
  void OnProfileAdded(const base::FilePath& profile_path) override;
  void OnProfileWasRemoved(const base::FilePath& profile_path,
                           const base::string16& profile_name) override;
  void OnProfileNameChanged(const base::FilePath& profile_path,
                            const base::string16& old_profile_name) override;

  // Overridden from content::NotificationObserver:
  void Observe(int type,
               const content::NotificationSource& source,
               const content::NotificationDetails& details) override;

  // Unowned pointer to the controller.
  AppListControllerDelegate* controller_;
  // Unowned pointer to the associated profile. May change if SetProfileByPath
  // is called.
  Profile* profile_;
  // Unowned pointer to the model owned by AppListSyncableService. Will change
  // if |profile_| changes.
  app_list::AppListModel* model_;

  // Note: order ensures |search_resource_manager_| is destroyed before
  // |speech_ui_|.
  std::unique_ptr<app_list::SpeechUIModel> speech_ui_;
  std::unique_ptr<app_list::SearchResourceManager> search_resource_manager_;
  std::unique_ptr<app_list::SearchController> search_controller_;

  std::unique_ptr<app_list::LauncherPageEventDispatcher>
      launcher_page_event_dispatcher_;

  base::TimeDelta auto_launch_timeout_;
  // Determines whether the current search was initiated by speech.
  bool is_voice_query_;

  Users users_;

#if defined(USE_ASH)
  std::unique_ptr<AppSyncUIStateWatcher> app_sync_ui_state_watcher_;
#endif

  ScopedObserver<TemplateURLService, AppListViewDelegate>
      template_url_service_observer_;

  // Used to track the SigninManagers that this instance is observing so that
  // this instance can be removed as an observer on its destruction.
  ScopedObserver<SigninManagerBase, AppListViewDelegate> scoped_observer_;

  // Window contents of additional custom launcher pages.
  std::vector<std::unique_ptr<app_list::CustomLauncherPageContents>>
      custom_page_contents_;

  // Registers for NOTIFICATION_APP_TERMINATING to unload custom launcher pages.
  content::NotificationRegistrar registrar_;

  DISALLOW_COPY_AND_ASSIGN(AppListViewDelegate);
};

#endif  // CHROME_BROWSER_UI_APP_LIST_APP_LIST_VIEW_DELEGATE_H_