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 203 204 205 206 207 208
|
// 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 <string>
#include "base/basictypes.h"
#include "base/callback_forward.h"
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
#include "base/observer_list.h"
#include "base/scoped_observer.h"
#include "chrome/browser/profiles/profile_info_cache_observer.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/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 apps {
class CustomLauncherPageContents;
}
namespace app_list {
class LauncherPageEventDispatcher;
class SearchController;
class SearchResourceManager;
class SpeechUIModel;
}
namespace base {
class FilePath;
}
namespace content {
struct SpeechRecognitionSessionPreamble;
}
namespace gfx {
class ImageSkia;
}
#if defined(USE_ASH)
class AppSyncUIStateWatcher;
#endif
class AppListViewDelegate : public app_list::AppListViewDelegate,
public app_list::StartPageObserver,
public HotwordClient,
public ProfileInfoCacheObserver,
public SigninManagerBase::Observer,
public SigninManagerFactory::Observer,
public content::NotificationObserver {
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 toggle the status of speech recognition based on a hotword
// trigger.
void ToggleSpeechRecognitionForHotword(
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 GetShortcutPathForApp(
const std::string& app_id,
const base::Callback<void(const base::FilePath&)>& callback) 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;
gfx::ImageSkia GetWindowIcon() override;
void OpenSettings() override;
void OpenHelp() override;
void OpenFeedback() override;
void ToggleSpeechRecognition() 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;
bool ShouldCenterWindow() const override;
void AddObserver(app_list::AppListViewDelegateObserver* observer) override;
void RemoveObserver(app_list::AppListViewDelegateObserver* observer) 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 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 ProfileInfoCacheObserver:
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_|.
scoped_ptr<app_list::SpeechUIModel> speech_ui_;
scoped_ptr<app_list::SearchResourceManager> search_resource_manager_;
scoped_ptr<app_list::SearchController> search_controller_;
scoped_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)
scoped_ptr<AppSyncUIStateWatcher> app_sync_ui_state_watcher_;
#endif
ObserverList<app_list::AppListViewDelegateObserver> observers_;
// 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.
ScopedVector<apps::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_
|