Commit db8976b8 authored by Jiaquan He's avatar Jiaquan He Committed by Commit Bot

app_list: merge AppListViewDelegate into AppListClientImpl in Chrome.

This commit does a few things:

- merges the Chrome AppListViewDelegate into AppListClientImpl;
- cleans up unused references;
- updates methods to proper accesses.

Ownership of major classes:

- Each user has its own AppListSyncableService, and it holds its own
  AppListModelUpdater, ModelBuilders, etc.
- There's only one AppListClientImpl in ChromeBrowserMainExtraPartsAsh
  shared by all users, and it holds Search classes, a mojo pointer to
  the AppListControllerImpl in Ash, etc.
- There's only one singleton AppListServiceImpl shared by all users, and
  it holds AppListControllerDelegateImpl.

Their lifecycles:

- Among these classes, AppListClientImpl is the first to be initiated, in
  PreProfileInit. It binds to AppListController in Ash, and then tells
  AppListServiceImpl two pointers (AppListController*, AppListClientImpl*).
- When AppListServiceImpl receives the two pointers, it should have been
  initiated as a singleton.
- The AppListClientImpl is associated with the current active user profile
  when it's accessed from AppListServiceImpl.

Bug: 733662
Change-Id: Iac6de011185bf88c4b3c575871b69bd7a67c340b
Reviewed-on: https://chromium-review.googlesource.com/974660Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Jiaquan He <hejq@google.com>
Cr-Commit-Position: refs/heads/master@{#546247}
parent cf81f9c4
...@@ -3446,8 +3446,6 @@ split_static_library("ui") { ...@@ -3446,8 +3446,6 @@ split_static_library("ui") {
"app_list/app_list_syncable_service.h", "app_list/app_list_syncable_service.h",
"app_list/app_list_syncable_service_factory.cc", "app_list/app_list_syncable_service_factory.cc",
"app_list/app_list_syncable_service_factory.h", "app_list/app_list_syncable_service_factory.h",
"app_list/app_list_view_delegate.cc",
"app_list/app_list_view_delegate.h",
"app_list/chrome_app_list_item.cc", "app_list/chrome_app_list_item.cc",
"app_list/chrome_app_list_item.h", "app_list/chrome_app_list_item.h",
"app_list/chrome_app_list_model_updater.cc", "app_list/chrome_app_list_model_updater.cc",
......
...@@ -4,30 +4,48 @@ ...@@ -4,30 +4,48 @@
#include "chrome/browser/ui/app_list/app_list_client_impl.h" #include "chrome/browser/ui/app_list/app_list_client_impl.h"
#include <stddef.h>
#include <utility> #include <utility>
#include <vector>
#include "ash/public/cpp/menu_utils.h" #include "ash/public/cpp/menu_utils.h"
#include "ash/public/interfaces/constants.mojom.h" #include "ash/public/interfaces/constants.mojom.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/user_metrics.h"
#include "chrome/browser/chromeos/arc/voice_interaction/arc_voice_interaction_framework_service.h" #include "chrome/browser/chromeos/arc/voice_interaction/arc_voice_interaction_framework_service.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/ui/app_list/app_list_controller_delegate.h" #include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
#include "chrome/browser/ui/app_list/app_list_model_updater.h" #include "chrome/browser/ui/app_list/app_list_model_updater.h"
#include "chrome/browser/ui/app_list/app_list_service_impl.h" #include "chrome/browser/ui/app_list/app_list_service_impl.h"
#include "chrome/browser/ui/app_list/app_list_view_delegate.h" #include "chrome/browser/ui/app_list/app_list_syncable_service.h"
#include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h"
#include "chrome/browser/ui/app_list/app_sync_ui_state_watcher.h"
#include "chrome/browser/ui/app_list/search/search_controller.h" #include "chrome/browser/ui/app_list/search/search_controller.h"
#include "chrome/browser/ui/app_list/search/search_controller_factory.h"
#include "chrome/browser/ui/app_list/search/search_resource_manager.h"
#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
#include "content/public/common/service_manager_connection.h" #include "content/public/common/service_manager_connection.h"
#include "services/service_manager/public/cpp/connector.h" #include "services/service_manager/public/cpp/connector.h"
#include "ui/base/models/menu_model.h" #include "ui/base/models/menu_model.h"
#include "ui/display/types/display_constants.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
AppListClientImpl::AppListClientImpl() : binding_(this) { AppListClientImpl::AppListClientImpl()
: template_url_service_observer_(this),
binding_(this),
weak_ptr_factory_(this) {
// Bind this to the AppListController in Ash.
content::ServiceManagerConnection::GetForProcess() content::ServiceManagerConnection::GetForProcess()
->GetConnector() ->GetConnector()
->BindInterface(ash::mojom::kServiceName, &app_list_controller_); ->BindInterface(ash::mojom::kServiceName, &app_list_controller_);
ash::mojom::AppListClientPtr client; ash::mojom::AppListClientPtr client;
binding_.Bind(mojo::MakeRequest(&client)); binding_.Bind(mojo::MakeRequest(&client));
app_list_controller_->SetClient(std::move(client)); app_list_controller_->SetClient(std::move(client));
AppListServiceImpl::GetInstance()->SetAppListControllerAndClient( AppListServiceImpl::GetInstance()->SetAppListControllerAndClient(
app_list_controller_.get(), this); app_list_controller_.get(), this);
} }
...@@ -35,49 +53,65 @@ AppListClientImpl::AppListClientImpl() : binding_(this) { ...@@ -35,49 +53,65 @@ AppListClientImpl::AppListClientImpl() : binding_(this) {
AppListClientImpl::~AppListClientImpl() = default; AppListClientImpl::~AppListClientImpl() = default;
void AppListClientImpl::StartSearch(const base::string16& raw_query) { void AppListClientImpl::StartSearch(const base::string16& raw_query) {
if (GetViewDelegate()->search_controller_) { if (search_controller_) {
GetViewDelegate()->search_controller_->Start(raw_query); search_controller_->Start(raw_query);
GetViewDelegate()->controller_->OnSearchStarted(); controller_delegate_->OnSearchStarted();
} }
} }
void AppListClientImpl::OpenSearchResult(const std::string& result_id, void AppListClientImpl::OpenSearchResult(const std::string& result_id,
int event_flags) { int event_flags) {
GetViewDelegate()->OpenSearchResult(result_id, event_flags); if (!model_updater_)
return;
app_list::SearchResult* result = model_updater_->FindSearchResult(result_id);
if (result)
search_controller_->OpenResult(result, event_flags);
} }
void AppListClientImpl::InvokeSearchResultAction(const std::string& result_id, void AppListClientImpl::InvokeSearchResultAction(const std::string& result_id,
int action_index, int action_index,
int event_flags) { int event_flags) {
GetViewDelegate()->InvokeSearchResultAction(result_id, action_index, if (!model_updater_)
event_flags); return;
app_list::SearchResult* result = model_updater_->FindSearchResult(result_id);
if (result)
search_controller_->InvokeResultAction(result, action_index, event_flags);
} }
void AppListClientImpl::ViewClosing() { void AppListClientImpl::ViewClosing() {
GetViewDelegate()->ViewClosing(); controller_delegate_->SetAppListDisplayId(display::kInvalidDisplayId);
} }
void AppListClientImpl::ViewShown(int64_t display_id) { void AppListClientImpl::ViewShown(int64_t display_id) {
GetViewDelegate()->ViewShown(display_id); if (model_updater_) {
base::RecordAction(base::UserMetricsAction("Launcher_Show"));
base::UmaHistogramSparse("Apps.AppListBadgedAppsCount",
model_updater_->BadgedItemCount());
}
controller_delegate_->SetAppListDisplayId(display_id);
} }
void AppListClientImpl::ActivateItem(const std::string& id, int event_flags) { void AppListClientImpl::ActivateItem(const std::string& id, int event_flags) {
GetViewDelegate()->model_updater_->ActivateChromeItem(id, event_flags); if (!model_updater_)
return;
model_updater_->ActivateChromeItem(id, event_flags);
} }
void AppListClientImpl::GetContextMenuModel( void AppListClientImpl::GetContextMenuModel(
const std::string& id, const std::string& id,
GetContextMenuModelCallback callback) { GetContextMenuModelCallback callback) {
ui::MenuModel* menu = if (!model_updater_)
GetViewDelegate()->model_updater_->GetContextMenuModel(id); return;
ui::MenuModel* menu = model_updater_->GetContextMenuModel(id);
std::move(callback).Run(ash::menu_utils::GetMojoMenuItemsFromModel(menu)); std::move(callback).Run(ash::menu_utils::GetMojoMenuItemsFromModel(menu));
} }
void AppListClientImpl::ContextMenuItemSelected(const std::string& id, void AppListClientImpl::ContextMenuItemSelected(const std::string& id,
int command_id, int command_id,
int event_flags) { int event_flags) {
GetViewDelegate()->model_updater_->ContextMenuItemSelected(id, command_id, if (!model_updater_)
event_flags); return;
model_updater_->ContextMenuItemSelected(id, command_id, event_flags);
} }
void AppListClientImpl::OnAppListTargetVisibilityChanged(bool visible) { void AppListClientImpl::OnAppListTargetVisibilityChanged(bool visible) {
...@@ -106,22 +140,102 @@ void AppListClientImpl::ToggleVoiceInteractionSession() { ...@@ -106,22 +140,102 @@ void AppListClientImpl::ToggleVoiceInteractionSession() {
void AppListClientImpl::OnFolderCreated( void AppListClientImpl::OnFolderCreated(
ash::mojom::AppListItemMetadataPtr item) { ash::mojom::AppListItemMetadataPtr item) {
if (!model_updater_)
return;
DCHECK(item->is_folder); DCHECK(item->is_folder);
GetViewDelegate()->model_updater_->OnFolderCreated(std::move(item)); model_updater_->OnFolderCreated(std::move(item));
} }
void AppListClientImpl::OnFolderDeleted( void AppListClientImpl::OnFolderDeleted(
ash::mojom::AppListItemMetadataPtr item) { ash::mojom::AppListItemMetadataPtr item) {
if (!model_updater_)
return;
DCHECK(item->is_folder); DCHECK(item->is_folder);
GetViewDelegate()->model_updater_->OnFolderDeleted(std::move(item)); model_updater_->OnFolderDeleted(std::move(item));
} }
void AppListClientImpl::OnItemUpdated(ash::mojom::AppListItemMetadataPtr item) { void AppListClientImpl::OnItemUpdated(ash::mojom::AppListItemMetadataPtr item) {
GetViewDelegate()->model_updater_->OnItemUpdated(std::move(item)); if (!model_updater_)
return;
model_updater_->OnItemUpdated(std::move(item));
} }
AppListViewDelegate* AppListClientImpl::GetViewDelegate() { void AppListClientImpl::UpdateProfile() {
return AppListServiceImpl::GetInstance()->GetViewDelegate(); Profile* profile = ProfileManager::GetActiveUserProfile();
app_list::AppListSyncableService* syncable_service =
app_list::AppListSyncableServiceFactory::GetForProfile(profile);
DCHECK(syncable_service && syncable_service->IsInitialized());
SetProfile(profile);
}
void AppListClientImpl::SetProfile(Profile* new_profile) {
if (profile_ == new_profile)
return;
if (profile_) {
DCHECK(model_updater_);
model_updater_->SetActive(false);
search_resource_manager_.reset();
search_controller_.reset();
app_sync_ui_state_watcher_.reset();
model_updater_ = nullptr;
}
template_url_service_observer_.RemoveAll();
profile_ = new_profile;
if (!profile_)
return;
// If we are in guest mode, the new profile should be an incognito profile.
// Otherwise, this may later hit a check (same condition as this one) in
// Browser::Browser when opening links in a browser window (see
// http://crbug.com/460437).
DCHECK(!profile_->IsGuestSession() || profile_->IsOffTheRecord())
<< "Guest mode must use incognito profile";
TemplateURLService* template_url_service =
TemplateURLServiceFactory::GetForProfile(profile_);
template_url_service_observer_.Add(template_url_service);
app_list::AppListSyncableService* syncable_service =
app_list::AppListSyncableServiceFactory::GetForProfile(profile_);
model_updater_ = syncable_service->GetModelUpdater();
model_updater_->SetActive(true);
app_sync_ui_state_watcher_ =
std::make_unique<AppSyncUIStateWatcher>(profile_, model_updater_);
SetUpSearchUI();
OnTemplateURLServiceChanged();
// Clear search query.
model_updater_->UpdateSearchBox(base::string16(),
false /* initiated_by_user */);
}
void AppListClientImpl::SetUpSearchUI() {
search_resource_manager_.reset(
new app_list::SearchResourceManager(profile_, model_updater_));
search_controller_ = app_list::CreateSearchController(
profile_, model_updater_, controller_delegate_);
}
void AppListClientImpl::OnTemplateURLServiceChanged() {
DCHECK(model_updater_);
TemplateURLService* template_url_service =
TemplateURLServiceFactory::GetForProfile(profile_);
const TemplateURL* default_provider =
template_url_service->GetDefaultSearchProvider();
const bool is_google =
default_provider &&
default_provider->GetEngineType(
template_url_service->search_terms_data()) == SEARCH_ENGINE_GOOGLE;
model_updater_->SetSearchEngineIsGoogle(is_google);
} }
void AppListClientImpl::FlushMojoForTesting() { void AppListClientImpl::FlushMojoForTesting() {
......
...@@ -5,16 +5,33 @@ ...@@ -5,16 +5,33 @@
#ifndef CHROME_BROWSER_UI_APP_LIST_APP_LIST_CLIENT_IMPL_H_ #ifndef CHROME_BROWSER_UI_APP_LIST_APP_LIST_CLIENT_IMPL_H_
#define CHROME_BROWSER_UI_APP_LIST_APP_LIST_CLIENT_IMPL_H_ #define CHROME_BROWSER_UI_APP_LIST_APP_LIST_CLIENT_IMPL_H_
#include <stdint.h>
#include <memory>
#include <string> #include <string>
#include "ash/public/interfaces/app_list.mojom.h" #include "ash/public/interfaces/app_list.mojom.h"
#include "ash/public/interfaces/shelf.mojom.h" #include "base/compiler_specific.h"
#include "chrome/browser/ui/app_list/chrome_app_list_model_updater.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/scoped_observer.h"
#include "components/search_engines/template_url_service.h"
#include "components/search_engines/template_url_service_observer.h"
#include "mojo/public/cpp/bindings/associated_binding.h"
#include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/binding.h"
class AppListViewDelegate; namespace app_list {
class SearchController;
class SearchResourceManager;
} // namespace app_list
class AppListControllerDelegate;
class AppListModelUpdater;
class AppSyncUIStateWatcher;
class Profile;
class AppListClientImpl : public ash::mojom::AppListClient { class AppListClientImpl : public ash::mojom::AppListClient,
public TemplateURLServiceObserver {
public: public:
AppListClientImpl(); AppListClientImpl();
~AppListClientImpl() override; ~AppListClientImpl() override;
...@@ -43,15 +60,48 @@ class AppListClientImpl : public ash::mojom::AppListClient { ...@@ -43,15 +60,48 @@ class AppListClientImpl : public ash::mojom::AppListClient {
void OnFolderDeleted(ash::mojom::AppListItemMetadataPtr item) override; void OnFolderDeleted(ash::mojom::AppListItemMetadataPtr item) override;
void OnItemUpdated(ash::mojom::AppListItemMetadataPtr item) override; void OnItemUpdated(ash::mojom::AppListItemMetadataPtr item) override;
// Associates this client with the current active user, called when this
// client is accessed.
void UpdateProfile();
void set_controller_delegate(AppListControllerDelegate* controller_delegate) {
controller_delegate_ = controller_delegate;
}
// Flushes all pending mojo call to Ash for testing. // Flushes all pending mojo call to Ash for testing.
void FlushMojoForTesting(); void FlushMojoForTesting();
private: private:
AppListViewDelegate* GetViewDelegate(); // Overridden from TemplateURLServiceObserver:
void OnTemplateURLServiceChanged() override;
// Configures the AppList for the given |profile|.
void SetProfile(Profile* profile);
// Updates the speech webview and start page for the current |profile_|.
void SetUpSearchUI();
// Unowned pointer to the controller delegate.
AppListControllerDelegate* controller_delegate_ = nullptr;
// Unowned pointer to the associated profile. May change if SetProfile is
// called.
Profile* profile_ = nullptr;
// Unowned pointer to the model updater owned by AppListSyncableService.
// Will change if |profile_| changes.
AppListModelUpdater* model_updater_ = nullptr;
std::unique_ptr<app_list::SearchResourceManager> search_resource_manager_;
std::unique_ptr<app_list::SearchController> search_controller_;
std::unique_ptr<AppSyncUIStateWatcher> app_sync_ui_state_watcher_;
ScopedObserver<TemplateURLService, AppListClientImpl>
template_url_service_observer_;
mojo::Binding<ash::mojom::AppListClient> binding_; mojo::Binding<ash::mojom::AppListClient> binding_;
ash::mojom::AppListControllerPtr app_list_controller_; ash::mojom::AppListControllerPtr app_list_controller_;
base::WeakPtrFactory<AppListClientImpl> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(AppListClientImpl); DISALLOW_COPY_AND_ASSIGN(AppListClientImpl);
}; };
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/app_list/app_list_controller_delegate.h" #include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
#include "chrome/browser/ui/app_list/app_list_model_updater.h" #include "chrome/browser/ui/app_list/app_list_model_updater.h"
#include "chrome/browser/ui/app_list/app_list_service.h" #include "chrome/browser/ui/app_list/app_list_service_impl.h"
#include "chrome/browser/ui/app_list/test/chrome_app_list_test_support.h" #include "chrome/browser/ui/app_list/test/chrome_app_list_test_support.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h" #include "chrome/browser/ui/browser_finder.h"
...@@ -60,10 +60,12 @@ IN_PROC_BROWSER_TEST_F(AppListControllerSearchResultsBrowserTest, ...@@ -60,10 +60,12 @@ IN_PROC_BROWSER_TEST_F(AppListControllerSearchResultsBrowserTest,
.AppendASCII("platform_apps") .AppendASCII("platform_apps")
.AppendASCII("minimal"); .AppendASCII("minimal");
AppListService* service = AppListService::Get(); AppListServiceImpl* service = AppListServiceImpl::GetInstance();
ASSERT_TRUE(service); ASSERT_TRUE(service);
AppListModelUpdater* model_updater = test::GetModelUpdater(service); AppListModelUpdater* model_updater = test::GetModelUpdater(service);
ASSERT_TRUE(model_updater); ASSERT_TRUE(model_updater);
// Getting the AppListClient to associate it with the current profile.
ASSERT_TRUE(service->GetAppListClient());
// Install the extension. // Install the extension.
const extensions::Extension* extension = InstallExtension( const extensions::Extension* extension = InstallExtension(
......
...@@ -17,8 +17,10 @@ ...@@ -17,8 +17,10 @@
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/app_list/app_list_client_impl.h" #include "chrome/browser/ui/app_list/app_list_client_impl.h"
#include "chrome/browser/ui/app_list/app_list_view_delegate.h" #include "chrome/browser/ui/app_list/app_list_syncable_service.h"
#include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h"
#include "chrome/browser/ui/ash/ash_util.h" #include "chrome/browser/ui/ash/ash_util.h"
#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
#include "chrome/browser/ui/ash/session_util.h" #include "chrome/browser/ui/ash/session_util.h"
...@@ -32,7 +34,7 @@ AppListServiceImpl* AppListServiceImpl::GetInstance() { ...@@ -32,7 +34,7 @@ AppListServiceImpl* AppListServiceImpl::GetInstance() {
AppListServiceImpl::AppListServiceImpl() AppListServiceImpl::AppListServiceImpl()
: local_state_(g_browser_process->local_state()), weak_factory_(this) {} : local_state_(g_browser_process->local_state()), weak_factory_(this) {}
AppListServiceImpl::~AppListServiceImpl() = default; AppListServiceImpl::~AppListServiceImpl() {}
void AppListServiceImpl::SetAppListControllerAndClient( void AppListServiceImpl::SetAppListControllerAndClient(
ash::mojom::AppListController* app_list_controller, ash::mojom::AppListController* app_list_controller,
...@@ -40,6 +42,7 @@ void AppListServiceImpl::SetAppListControllerAndClient( ...@@ -40,6 +42,7 @@ void AppListServiceImpl::SetAppListControllerAndClient(
app_list_controller_ = app_list_controller; app_list_controller_ = app_list_controller;
controller_delegate_.SetAppListController(app_list_controller); controller_delegate_.SetAppListController(app_list_controller);
app_list_client_ = app_list_client; app_list_client_ = app_list_client;
app_list_client_->set_controller_delegate(&controller_delegate_);
} }
ash::mojom::AppListController* AppListServiceImpl::GetAppListController() { ash::mojom::AppListController* AppListServiceImpl::GetAppListController() {
...@@ -53,12 +56,9 @@ app_list::SearchModel* AppListServiceImpl::GetSearchModelFromAsh() { ...@@ -53,12 +56,9 @@ app_list::SearchModel* AppListServiceImpl::GetSearchModelFromAsh() {
: nullptr; : nullptr;
} }
AppListViewDelegate* AppListServiceImpl::GetViewDelegate() { AppListClientImpl* AppListServiceImpl::GetAppListClient() {
if (!view_delegate_) app_list_client_->UpdateProfile();
view_delegate_.reset(new AppListViewDelegate(GetControllerDelegate())); return app_list_client_;
Profile* profile = Profile::FromBrowserContext(GetActiveBrowserContext());
view_delegate_->SetProfile(profile);
return view_delegate_.get();
} }
AppListControllerDelegate* AppListServiceImpl::GetControllerDelegate() { AppListControllerDelegate* AppListServiceImpl::GetControllerDelegate() {
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
class AppListClientImpl; class AppListClientImpl;
class AppListControllerDelegateImpl; class AppListControllerDelegateImpl;
class AppListViewDelegate;
namespace app_list { namespace app_list {
class SearchModel; class SearchModel;
...@@ -35,11 +34,6 @@ class AppListServiceImpl : public AppListService { ...@@ -35,11 +34,6 @@ class AppListServiceImpl : public AppListService {
static AppListServiceImpl* GetInstance(); static AppListServiceImpl* GetInstance();
AppListViewDelegate* GetViewDelegate();
void RecordAppListLaunch();
static void RecordAppListAppLaunch();
// AppListService overrides: // AppListService overrides:
Profile* GetCurrentAppListProfile() override; Profile* GetCurrentAppListProfile() override;
void Show() override; void Show() override;
...@@ -67,6 +61,7 @@ class AppListServiceImpl : public AppListService { ...@@ -67,6 +61,7 @@ class AppListServiceImpl : public AppListService {
// Returns a pointer to control the app list views in ash. // Returns a pointer to control the app list views in ash.
ash::mojom::AppListController* GetAppListController(); ash::mojom::AppListController* GetAppListController();
AppListClientImpl* GetAppListClient();
// TODO(hejq): Search model migration is not done yet. Chrome still accesses // TODO(hejq): Search model migration is not done yet. Chrome still accesses
// it directly in non-mus+ash mode. // it directly in non-mus+ash mode.
...@@ -79,7 +74,6 @@ class AppListServiceImpl : public AppListService { ...@@ -79,7 +74,6 @@ class AppListServiceImpl : public AppListService {
std::string GetProfileName(); std::string GetProfileName();
PrefService* local_state_; PrefService* local_state_;
std::unique_ptr<AppListViewDelegate> view_delegate_;
AppListControllerDelegateImpl controller_delegate_; AppListControllerDelegateImpl controller_delegate_;
ash::mojom::AppListController* app_list_controller_ = nullptr; ash::mojom::AppListController* app_list_controller_ = nullptr;
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
#include "chrome/browser/ui/app_list/app_list_service.h" #include "chrome/browser/ui/app_list/app_list_service.h"
#include "chrome/browser/ui/app_list/app_list_client_impl.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/in_process_browser_test.h"
...@@ -15,13 +14,12 @@ using AppListServiceInteractiveTest = InProcessBrowserTest; ...@@ -15,13 +14,12 @@ using AppListServiceInteractiveTest = InProcessBrowserTest;
// Show the app list, then dismiss it. // Show the app list, then dismiss it.
IN_PROC_BROWSER_TEST_F(AppListServiceInteractiveTest, ShowAndDismiss) { IN_PROC_BROWSER_TEST_F(AppListServiceInteractiveTest, ShowAndDismiss) {
AppListClientImpl app_list_client;
AppListService* service = AppListService::Get(); AppListService* service = AppListService::Get();
ASSERT_FALSE(service->IsAppListVisible()); ASSERT_FALSE(service->IsAppListVisible());
service->Show(); service->Show();
app_list_client.FlushMojoForTesting(); service->FlushForTesting();
ASSERT_TRUE(service->IsAppListVisible()); ASSERT_TRUE(service->IsAppListVisible());
service->DismissAppList(); service->DismissAppList();
app_list_client.FlushMojoForTesting(); service->FlushForTesting();
ASSERT_FALSE(service->IsAppListVisible()); ASSERT_FALSE(service->IsAppListVisible());
} }
// 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.
#include "chrome/browser/ui/app_list/app_list_view_delegate.h"
#include <stddef.h>
#include <utility>
#include <vector>
#include "ash/app_list/model/app_list_model.h"
#include "ash/app_list/model/search/search_model.h"
#include "ash/public/cpp/menu_utils.h"
#include "base/command_line.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/user_metrics.h"
#include "build/build_config.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
#include "chrome/browser/ui/app_list/app_list_model_updater.h"
#include "chrome/browser/ui/app_list/app_list_syncable_service.h"
#include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h"
#include "chrome/browser/ui/app_list/app_sync_ui_state_watcher.h"
#include "chrome/browser/ui/app_list/search/search_controller.h"
#include "chrome/browser/ui/app_list/search/search_controller_factory.h"
#include "chrome/browser/ui/app_list/search/search_resource_manager.h"
#include "chrome/browser/ui/apps/chrome_app_delegate.h"
#include "chrome/browser/ui/ash/wallpaper_controller_client.h"
#include "chrome/browser/ui/chrome_pages.h"
#include "chrome/common/pref_names.h"
#include "chrome/grit/theme_resources.h"
#include "components/prefs/pref_service.h"
#include "components/user_prefs/user_prefs.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/speech_recognition_session_preamble.h"
#include "content/public/browser/web_contents.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension_set.h"
#include "extensions/common/manifest_constants.h"
#include "ui/app_list/app_list_switches.h"
#include "ui/app_list/app_list_view_delegate_observer.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/display/types/display_constants.h"
#include "ui/keyboard/keyboard_util.h"
#include "ui/views/controls/webview/webview.h"
AppListViewDelegate::AppListViewDelegate(AppListControllerDelegate* controller)
: controller_(controller),
profile_(nullptr),
model_updater_(nullptr),
template_url_service_observer_(this),
observer_binding_(this),
weak_ptr_factory_(this) {
CHECK(controller_);
registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING,
content::NotificationService::AllSources());
ash::mojom::WallpaperObserverAssociatedPtrInfo ptr_info;
observer_binding_.Bind(mojo::MakeRequest(&ptr_info));
WallpaperControllerClient::Get()->AddObserver(std::move(ptr_info));
}
AppListViewDelegate::~AppListViewDelegate() {
// The destructor might not be called since the delegate is owned by a leaky
// singleton. This matches the shutdown work done in Observe() in response to
// chrome::NOTIFICATION_APP_TERMINATING, which may happen before this.
SetProfile(nullptr);
}
void AppListViewDelegate::SetProfile(Profile* new_profile) {
if (profile_ == new_profile)
return;
if (profile_) {
DCHECK(model_updater_);
model_updater_->SetActive(false);
search_resource_manager_.reset();
search_controller_.reset();
app_sync_ui_state_watcher_.reset();
model_updater_ = nullptr;
}
template_url_service_observer_.RemoveAll();
profile_ = new_profile;
if (!profile_)
return;
// If we are in guest mode, the new profile should be an incognito profile.
// Otherwise, this may later hit a check (same condition as this one) in
// Browser::Browser when opening links in a browser window (see
// http://crbug.com/460437).
DCHECK(!profile_->IsGuestSession() || profile_->IsOffTheRecord())
<< "Guest mode must use incognito profile";
TemplateURLService* template_url_service =
TemplateURLServiceFactory::GetForProfile(profile_);
template_url_service_observer_.Add(template_url_service);
app_list::AppListSyncableService* syncable_service =
app_list::AppListSyncableServiceFactory::GetForProfile(profile_);
model_updater_ = syncable_service->GetModelUpdater();
model_updater_->SetActive(true);
// After |model_updater_| is initialized, make a GetWallpaperColors mojo call
// to set wallpaper colors for |model_updater_|.
WallpaperControllerClient::Get()->GetWallpaperColors(
base::Bind(&AppListViewDelegate::OnGetWallpaperColorsCallback,
weak_ptr_factory_.GetWeakPtr()));
app_sync_ui_state_watcher_ =
std::make_unique<AppSyncUIStateWatcher>(profile_, model_updater_);
SetUpSearchUI();
OnTemplateURLServiceChanged();
// Clear search query.
model_updater_->UpdateSearchBox(base::string16(),
false /* initiated_by_user */);
}
void AppListViewDelegate::OnGetWallpaperColorsCallback(
const std::vector<SkColor>& colors) {
OnWallpaperColorsChanged(colors);
}
void AppListViewDelegate::SetUpSearchUI() {
search_resource_manager_.reset(
new app_list::SearchResourceManager(profile_, model_updater_));
search_controller_ =
app_list::CreateSearchController(profile_, model_updater_, controller_);
}
void AppListViewDelegate::OnWallpaperChanged(uint32_t image_id) {}
void AppListViewDelegate::OnWallpaperColorsChanged(
const std::vector<SkColor>& prominent_colors) {
if (wallpaper_prominent_colors_ == prominent_colors)
return;
wallpaper_prominent_colors_ = prominent_colors;
for (auto& observer : observers_)
observer.OnWallpaperColorsChanged();
}
AppListModelUpdater* AppListViewDelegate::GetModelUpdater() {
return model_updater_;
}
app_list::AppListModel* AppListViewDelegate::GetModel() {
NOTREACHED();
return nullptr;
}
app_list::SearchModel* AppListViewDelegate::GetSearchModel() {
NOTREACHED();
return nullptr;
}
void AppListViewDelegate::StartSearch(const base::string16& raw_query) {
if (search_controller_) {
search_controller_->Start(raw_query);
controller_->OnSearchStarted();
}
}
void AppListViewDelegate::OpenSearchResult(const std::string& result_id,
int event_flags) {
app_list::SearchResult* result = model_updater_->FindSearchResult(result_id);
if (result)
search_controller_->OpenResult(result, event_flags);
}
void AppListViewDelegate::InvokeSearchResultAction(const std::string& result_id,
int action_index,
int event_flags) {
app_list::SearchResult* result = model_updater_->FindSearchResult(result_id);
if (result)
search_controller_->InvokeResultAction(result, action_index, event_flags);
}
void AppListViewDelegate::ViewShown(int64_t display_id) {
base::RecordAction(base::UserMetricsAction("Launcher_Show"));
base::UmaHistogramSparse("Apps.AppListBadgedAppsCount",
model_updater_->BadgedItemCount());
controller_->SetAppListDisplayId(display_id);
}
void AppListViewDelegate::Dismiss() {
controller_->DismissView();
}
void AppListViewDelegate::ViewClosing() {
controller_->SetAppListDisplayId(display::kInvalidDisplayId);
}
void AppListViewDelegate::GetWallpaperProminentColors(
GetWallpaperProminentColorsCallback callback) {
std::move(callback).Run(wallpaper_prominent_colors_);
}
void AppListViewDelegate::ActivateItem(const std::string& id, int event_flags) {
model_updater_->ActivateChromeItem(id, event_flags);
}
void AppListViewDelegate::GetContextMenuModel(
const std::string& id,
GetContextMenuModelCallback callback) {
ui::MenuModel* menu = model_updater_->GetContextMenuModel(id);
std::move(callback).Run(ash::menu_utils::GetMojoMenuItemsFromModel(menu));
}
void AppListViewDelegate::ContextMenuItemSelected(const std::string& id,
int command_id,
int event_flags) {
model_updater_->ContextMenuItemSelected(id, command_id, event_flags);
}
void AppListViewDelegate::AddObserver(
app_list::AppListViewDelegateObserver* observer) {
observers_.AddObserver(observer);
}
void AppListViewDelegate::RemoveObserver(
app_list::AppListViewDelegateObserver* observer) {
observers_.RemoveObserver(observer);
}
void AppListViewDelegate::OnTemplateURLServiceChanged() {
TemplateURLService* template_url_service =
TemplateURLServiceFactory::GetForProfile(profile_);
const TemplateURL* default_provider =
template_url_service->GetDefaultSearchProvider();
const bool is_google =
default_provider->GetEngineType(
template_url_service->search_terms_data()) == SEARCH_ENGINE_GOOGLE;
model_updater_->SetSearchEngineIsGoogle(is_google);
}
void AppListViewDelegate::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
DCHECK_EQ(chrome::NOTIFICATION_APP_TERMINATING, type);
SetProfile(nullptr); // Ensures launcher page web contents are torn down.
}
// 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 "ash/public/interfaces/wallpaper.mojom.h"
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/scoped_observer.h"
#include "chrome/browser/ui/app_list/app_list_model_updater.h"
#include "components/search_engines/template_url_service.h"
#include "components/search_engines/template_url_service_observer.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "mojo/public/cpp/bindings/associated_binding.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "ui/app_list/app_list_view_delegate.h"
#include "ui/app_list/app_list_view_delegate_observer.h"
class AppListClientImpl;
namespace app_list {
class SearchController;
class SearchResourceManager;
}
namespace content {
struct SpeechRecognitionSessionPreamble;
}
class AppListControllerDelegate;
class AppSyncUIStateWatcher;
class Profile;
class AppListViewDelegate : public app_list::AppListViewDelegate,
public ash::mojom::WallpaperObserver,
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_; }
// Gets the model updater.
AppListModelUpdater* GetModelUpdater();
// Overridden from app_list::AppListViewDelegate:
app_list::AppListModel* GetModel() override;
app_list::SearchModel* GetSearchModel() override;
void StartSearch(const base::string16& raw_query) override;
void OpenSearchResult(const std::string& result_id, int event_flags) override;
void InvokeSearchResultAction(const std::string& result_id,
int action_index,
int event_flags) override;
void ViewShown(int64_t display_id) override;
void Dismiss() override;
void ViewClosing() override;
void GetWallpaperProminentColors(
GetWallpaperProminentColorsCallback callback) override;
void ActivateItem(const std::string& id, int event_flags) override;
void GetContextMenuModel(const std::string& id,
GetContextMenuModelCallback callback) override;
void ContextMenuItemSelected(const std::string& id,
int command_id,
int event_flags) override;
void AddObserver(app_list::AppListViewDelegateObserver* observer) override;
void RemoveObserver(app_list::AppListViewDelegateObserver* observer) override;
// Overridden from TemplateURLServiceObserver:
void OnTemplateURLServiceChanged() override;
private:
// TODO(hejq): We'll merge AppListClientImpl and AppListViewDelegate, but not
// now, since that'll change all interface calls.
friend AppListClientImpl;
// Callback for ash::mojom::GetWallpaperColors.
void OnGetWallpaperColorsCallback(const std::vector<SkColor>& colors);
// Updates the speech webview and start page for the current |profile_|.
void SetUpSearchUI();
// Overridden from ash::mojom::WallpaperObserver:
void OnWallpaperChanged(uint32_t image_id) override;
void OnWallpaperColorsChanged(
const std::vector<SkColor>& prominent_colors) 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 updater owned by AppListSyncableService.
// Will change if |profile_| changes.
AppListModelUpdater* model_updater_;
std::unique_ptr<app_list::SearchResourceManager> search_resource_manager_;
std::unique_ptr<app_list::SearchController> search_controller_;
std::unique_ptr<AppSyncUIStateWatcher> app_sync_ui_state_watcher_;
ScopedObserver<TemplateURLService, AppListViewDelegate>
template_url_service_observer_;
// Registers for NOTIFICATION_APP_TERMINATING to unload custom launcher pages.
content::NotificationRegistrar registrar_;
// The binding this instance uses to implement mojom::WallpaperObserver.
mojo::AssociatedBinding<ash::mojom::WallpaperObserver> observer_binding_;
std::vector<SkColor> wallpaper_prominent_colors_;
base::ObserverList<app_list::AppListViewDelegateObserver> observers_;
base::WeakPtrFactory<AppListViewDelegate> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(AppListViewDelegate);
};
#endif // CHROME_BROWSER_UI_APP_LIST_APP_LIST_VIEW_DELEGATE_H_
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "chrome/browser/ui/app_list/app_list_client_impl.h"
#include "chrome/browser/ui/app_list/app_list_service_impl.h" #include "chrome/browser/ui/app_list/app_list_service_impl.h"
#include "chrome/browser/ui/app_list/app_list_view_delegate.h"
#include "chrome/browser/ui/app_list/crostini/crostini_app_model_builder.h" #include "chrome/browser/ui/app_list/crostini/crostini_app_model_builder.h"
#include "chrome/browser/ui/app_list/crostini/crostini_util.h" #include "chrome/browser/ui/app_list/crostini/crostini_util.h"
#include "chrome/browser/ui/app_list/test/chrome_app_list_test_support.h" #include "chrome/browser/ui/app_list/test/chrome_app_list_test_support.h"
...@@ -29,10 +29,10 @@ class CrostiniInstallerViewBrowserTest : public DialogBrowserTest { ...@@ -29,10 +29,10 @@ class CrostiniInstallerViewBrowserTest : public DialogBrowserTest {
// DialogBrowserTest: // DialogBrowserTest:
void ShowUi(const std::string& name) override { void ShowUi(const std::string& name) override {
AppListServiceImpl* service = test::GetAppListServiceImpl(); AppListServiceImpl* service = test::GetAppListServiceImpl();
AppListViewDelegate* view_delegate = service->GetViewDelegate(); AppListClientImpl* client = service->GetAppListClient();
const std::string kCrostiniTerminalId = const std::string kCrostiniTerminalId =
crx_file::id_util::GenerateId(kCrostiniTerminalAppName); crx_file::id_util::GenerateId(kCrostiniTerminalAppName);
view_delegate->ActivateItem(kCrostiniTerminalId, 0); client->ActivateItem(kCrostiniTerminalId, 0);
} }
void SetUp() override { void SetUp() override {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment