Chromium Code Reviews| Index: chrome/browser/ui/app_list/arc_app_prefs.h |
| diff --git a/chrome/browser/ui/app_list/arc_app_prefs.h b/chrome/browser/ui/app_list/arc_app_prefs.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6e20e01fd5205d06330488830b762d2d7316196a |
| --- /dev/null |
| +++ b/chrome/browser/ui/app_list/arc_app_prefs.h |
| @@ -0,0 +1,139 @@ |
| +// Copyright 2015 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_ARC_APP_PREFS_H_ |
| +#define CHROME_BROWSER_UI_APP_LIST_ARC_APP_PREFS_H_ |
| + |
| +#include <map> |
| +#include <set> |
| +#include <vector> |
| + |
| +#include "base/files/file_path.h" |
| +#include "base/macros.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "base/observer_list.h" |
| +#include "components/arc/arc_bridge_service.h" |
| +#include "components/keyed_service/core/keyed_service.h" |
| +#include "ui/base/layout.h" |
| + |
| +class PrefService; |
| + |
| +namespace content { |
| +class BrowserContext; |
| +} |
| + |
| +namespace user_prefs { |
| +class PrefRegistrySyncable; |
| +} |
| + |
| +// Declares shareable arc app specific preferences, that keep information |
| +// about app attributes (name, package, activity) and its state. This |
| +// information is used to pre-create non-ready app items while Arc bridge |
| +// service is not ready to provide information about available Android apps. |
| +class ArcAppPrefs : public KeyedService, |
|
Luis Héctor Chávez
2015/11/12 20:49:16
Can this be called ArcAppListPrefs?
khmel1
2015/11/13 15:00:56
Yes, we already have AppListPrefs so it might soun
|
| + public arc::ArcBridgeService::Observer { |
| + public: |
| + struct AppInfo { |
| + std::string name; |
| + std::string package; |
| + std::string activity; |
| + bool ready; |
| + }; |
| + |
| + class Observer { |
| + public: |
| + // Notifies an observer that new app is registered. |
| + virtual void OnAppRegistered(const std::string& app_id, |
| + const AppInfo& app_info) = 0; |
| + // Notifies an observer that app ready state has been changed. |
| + virtual void OnAppReadyChanged(const std::string& id, bool ready) = 0; |
| + // Notifies an observer that app icon has been installed or updated. |
| + virtual void OnAppIconUpdated(const std::string& id, |
| + ui::ScaleFactor scale_factor) = 0; |
| + }; |
| + |
| + static ArcAppPrefs* Create(const base::FilePath& base_path, |
| + PrefService* prefs); |
| + |
| + // Convenience function to get the ArcAppPrefs for a BrowserContext. |
| + static ArcAppPrefs* Get(content::BrowserContext* context); |
| + |
| + // Constructs unique id based on package and activity information. This id |
| + // is safe to use at file paths and as preference keys. |
| + static std::string GetAppId(const std::string& package, |
| + const std::string& activity); |
| + |
| + // It is called from chrome/browser/prefs/browser_prefs.cc. |
| + static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
| + |
| + ~ArcAppPrefs() override; |
| + |
| + // Returns a list of all app ids, including ready and non-ready apps. |
| + std::vector<std::string> GetAppIds() const; |
| + |
| + // Extracts attributes of an app based on its id. Returns NULL if the app is |
| + // not found. |
| + scoped_ptr<AppInfo> GetApp(const std::string& app_id) const; |
| + |
| + // Constructs path to app icon for specific scale factor. |
| + base::FilePath GetIconPath(const std::string& app_id, |
| + ui::ScaleFactor scale_factor) const; |
| + |
| + // Requests to load an app icon for specific scale factor. If the app or Arc |
| + // bridge service is not ready, then defer this request until the app gets |
| + // available. Once new icon is installed notifies an observer |
| + // OnAppIconUpdated. |
| + void RequestIcon(const std::string& app_id, ui::ScaleFactor scale_factor); |
| + |
| + // Returns true if app is registered. |
| + bool IsRegistered(const std::string& app_id); |
| + |
| + void AddObserver(Observer* observer); |
| + void RemoveObserver(Observer* observer); |
| + |
| + // arc::ArcBridgeService::Observer |
| + void OnStateChanged(arc::ArcBridgeService::State state) override; |
| + void OnAppsRefreshed(const std::vector<std::string>& name, |
| + const std::vector<std::string>& packages) override; |
| + void OnAppIcon(const std::string& package, |
| + const std::string& activity, |
| + int density, |
| + const std::vector<uint8_t>& icon_png_data) override; |
| + |
| + private: |
| + // See the Create methods. |
| + ArcAppPrefs(const base::FilePath& base_path, PrefService* prefs); |
| + |
| + void OnAppReady(const std::string& name, const std::string& package); |
| + void DisableAllApps(); |
| + |
| + // Installs an icon to file system in the special folder of the profile |
| + // directory. |
| + void InstallIcon(const std::string& app_id, |
| + ui::ScaleFactor scale_factor, |
| + const std::vector<uint8>& contentPng); |
| + void InstallIconFromFileThread(const std::string& app_id, |
| + ui::ScaleFactor scale_factor, |
| + const std::vector<uint8>& contentPng); |
| + void OnIconInstalled(const std::string& app_id, |
| + ui::ScaleFactor scale_factor); |
| + |
| + content::BrowserContext* browser_context_; |
|
xiyuan
2015/11/12 17:32:45
remove?
khmel1
2015/11/13 15:00:56
Done.
|
| + // Owned by the BrowserContext. |
| + PrefService* prefs_; |
| + base::ObserverList<Observer> observer_list_; |
|
Luis Héctor Chávez
2015/11/12 20:49:16
Comments for all these fields? Also separate them
khmel1
2015/11/13 15:00:56
Done.
|
| + base::FilePath base_path_; |
| + std::set<std::string> ready_apps_; |
| + // Keeps deferred icon load requests. Each app may contain several requests |
| + // for different scale factor. Scale factor is defined by specific bit |
| + // position. |
| + std::map<std::string, uint32> request_icon_deferred_; |
| + |
| + base::WeakPtrFactory<ArcAppPrefs> weak_ptr_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ArcAppPrefs); |
| +}; |
| + |
| +#endif // CHROME_BROWSER_UI_APP_LIST_ARC_APP_PREFS_H_ |