| // Copyright 2019 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 ASH_PUBLIC_CPP_APP_LIST_APP_LIST_CONTROLLER_H_ |
| #define ASH_PUBLIC_CPP_APP_LIST_APP_LIST_CONTROLLER_H_ |
| |
| #include <memory> |
| #include <string> |
| |
| #include "ash/public/cpp/app_list/app_list_types.h" |
| #include "ash/public/cpp/ash_public_export.h" |
| #include "base/callback_forward.h" |
| #include "base/containers/flat_map.h" |
| #include "base/optional.h" |
| #include "base/strings/string16.h" |
| #include "ui/aura/window.h" |
| |
| namespace ash { |
| |
| class AppListClient; |
| class AppListControllerObserver; |
| |
| // An interface implemented in Ash to handle calls from Chrome. |
| // These include: |
| // - When app list data changes in Chrome, it should notifies the UI models and |
| // views in Ash to get updated. This can happen while syncing, searching, etc. |
| // - When Chrome needs real-time UI information from Ash. This can happen while |
| // calculating recommended search results based on the app list item order. |
| // - When app list states in Chrome change that require UI's response. This can |
| // happen while installing/uninstalling apps and the app list gets toggled. |
| class ASH_PUBLIC_EXPORT AppListController { |
| public: |
| // Gets the instance. |
| static AppListController* Get(); |
| |
| // Sets a client to handle calls from Ash. |
| virtual void SetClient(AppListClient* client) = 0; |
| |
| // Gets the client that handles calls from Ash. |
| virtual AppListClient* GetClient() = 0; |
| |
| virtual void AddObserver(AppListControllerObserver* observer) = 0; |
| virtual void RemoveObserver(AppListControllerObserver* obsever) = 0; |
| |
| // Adds an item to AppListModel. |
| virtual void AddItem(std::unique_ptr<AppListItemMetadata> app_item) = 0; |
| |
| // Adds an item into a certain folder in AppListModel. |
| virtual void AddItemToFolder(std::unique_ptr<AppListItemMetadata> app_item, |
| const std::string& folder_id) = 0; |
| |
| // Removes an item by its id from AppListModel. |
| virtual void RemoveItem(const std::string& id) = 0; |
| |
| // Removes an item by its id, and also cleans up if its parent folder has a |
| // single child left. |
| virtual void RemoveUninstalledItem(const std::string& id) = 0; |
| |
| // Moves the item with |id| to the folder with |folder_id|. |
| virtual void MoveItemToFolder(const std::string& id, |
| const std::string& folder_id) = 0; |
| |
| // Tells Ash what the current status of AppListModel should be, |
| // e.g. the model is under synchronization or in normal status. |
| virtual void SetStatus(AppListModelStatus status) = 0; |
| |
| // Sets whether the search engine is Google or not. |
| virtual void SetSearchEngineIsGoogle(bool is_google) = 0; |
| |
| // Sets the text for the search box's Textfield and the voice search flag. |
| virtual void UpdateSearchBox(const std::u16string& text, |
| bool initiated_by_user) = 0; |
| |
| // Publishes search results to Ash to render them. |
| virtual void PublishSearchResults( |
| std::vector<std::unique_ptr<SearchResultMetadata>> results) = 0; |
| |
| // Updates an item's metadata (e.g. name, position, etc). |
| virtual void SetItemMetadata(const std::string& id, |
| std::unique_ptr<AppListItemMetadata> data) = 0; |
| |
| // Updates an item's icon. |
| virtual void SetItemIcon(const std::string& id, |
| const gfx::ImageSkia& icon) = 0; |
| |
| virtual void SetItemNotificationBadgeColor(const std::string& id, |
| const SkColor color) = 0; |
| |
| // Update the whole model, usually when profile changes happen in Chrome. |
| virtual void SetModelData( |
| int profile_id, |
| std::vector<std::unique_ptr<AppListItemMetadata>> apps, |
| bool is_search_engine_google) = 0; |
| |
| // Updates a search rresult's metadata. |
| virtual void SetSearchResultMetadata( |
| std::unique_ptr<SearchResultMetadata> metadata) = 0; |
| |
| // Returns a map from each item's id to its shown index in the app list. |
| using GetIdToAppListIndexMapCallback = |
| base::OnceCallback<void(const base::flat_map<std::string, uint16_t>&)>; |
| virtual void GetIdToAppListIndexMap( |
| GetIdToAppListIndexMapCallback callback) = 0; |
| |
| // Finds the OEM folder or creates one if it doesn't exist. |
| // |oem_folder_name|: the expected name of the OEM folder while creating. |
| // |preferred_oem_position|: the preferred position of the OEM folder while |
| // creating; if it's invalid then the final position |
| // is determined in Ash. |
| // |oem_folder|: the meta data of the existing/created OEM folder. |
| using FindOrCreateOemFolderCallback = base::OnceClosure; |
| virtual void FindOrCreateOemFolder( |
| const std::string& oem_folder_name, |
| const syncer::StringOrdinal& preferred_oem_position, |
| FindOrCreateOemFolderCallback callback) = 0; |
| |
| // Resolves the position of the OEM folder. |
| // |preferred_oem_position|: the preferred position of the OEM folder; if it's |
| // invalid then the final position is determined in |
| // Ash. |
| // |oem_folder|: the meta data of the OEM folder, or null if it doesn't exist. |
| using ResolveOemFolderPositionCallback = |
| base::OnceCallback<void(std::unique_ptr<AppListItemMetadata>)>; |
| virtual void ResolveOemFolderPosition( |
| const syncer::StringOrdinal& preferred_oem_position, |
| ResolveOemFolderPositionCallback callback) = 0; |
| |
| // Notifies sync service has finished processing sync changes. |
| virtual void NotifyProcessSyncChangesFinished() = 0; |
| |
| // Dismisses the app list. |
| virtual void DismissAppList() = 0; |
| |
| // Returns bounds of a rectangle to show an AppInfo dialog. |
| using GetAppInfoDialogBoundsCallback = |
| base::OnceCallback<void(const gfx::Rect&)>; |
| virtual void GetAppInfoDialogBounds( |
| GetAppInfoDialogBoundsCallback callback) = 0; |
| |
| // Shows the app list. |
| virtual void ShowAppList() = 0; |
| |
| // Returns the app list window or nullptr if it is not visible. |
| virtual aura::Window* GetWindow() = 0; |
| |
| // Returns whether the AppList is visible on the provided display. |
| // If |display_id| is null, returns whether an app list is visible on any |
| // display. |
| virtual bool IsVisible(const base::Optional<int64_t>& display_id) = 0; |
| |
| protected: |
| AppListController(); |
| virtual ~AppListController(); |
| }; |
| |
| } // namespace ash |
| |
| #endif // ASH_PUBLIC_CPP_APP_LIST_APP_LIST_CONTROLLER_H_ |