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..70f4dc7c7468c2e4326625f7a027740e65113a81 |
--- /dev/null |
+++ b/chrome/browser/ui/app_list/arc_app_prefs.h |
@@ -0,0 +1,136 @@ |
+// 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 <set> |
+#include <vector> |
+ |
+#include "base/files/file_path.h" |
+#include "base/macros.h" |
+#include "base/memory/scoped_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; |
+} |
+ |
+class ArcAppPrefs : public KeyedService, |
xiyuan
2015/11/11 22:15:51
nit: document the class?
khmel1
2015/11/12 08:05:31
Done.
|
+ private arc::ArcBridgeService::Observer { |
xiyuan
2015/11/11 22:15:51
no private inheritance.
khmel1
2015/11/12 08:05:31
Done.
|
+ 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 OnAppReady(const std::string& id, bool ready) = 0; |
xiyuan
2015/11/11 22:15:51
Can an app change from ready to not ready? If so,
khmel1
2015/11/12 08:05:31
Yes, it may and this name sounds better
|
+ // 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(content::BrowserContext* browser_context, |
+ const base::FilePath& base_path, |
+ PrefService* prefs); |
+ // Convenience function to get the ArcAppPrefs for a BrowserContext. |
xiyuan
2015/11/11 22:15:51
nit: insert an empty line above to separate
khmel1
2015/11/12 08:05:31
Done.
|
+ static ArcAppPrefs* Get(content::BrowserContext* context); |
+ // Constructs unique id based on package and activity information. This id |
xiyuan
2015/11/11 22:15:51
nit: insert an empty line before
khmel1
2015/11/12 08:05:31
Done.
|
+ // is safe to use at file paths and as preference keys. |
+ static std::string GetAppId(const std::string& package, |
+ const std::string& activity); |
+ |
+ // Declares shareable arc app specific preferences, that keep information |
+ // about app attributes (name, package, activity). 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. 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); |
+ |
+ private: |
+ content::BrowserContext* browser_context_; |
+ // Owned by the BrowserContext. |
+ PrefService* prefs_; |
+ base::ObserverList<Observer> observer_list_; |
+ 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_; |
xiyuan
2015/11/11 22:15:51
Move data members down.
xiyuan
2015/11/11 22:15:51
nit: #include <map>
khmel1
2015/11/12 08:05:31
Done.
khmel1
2015/11/12 08:05:31
Done.
khmel1
2015/11/12 08:05:31
Done.
khmel1
2015/11/12 08:05:31
Done.
|
+ |
+ // See the Create methods. |
+ ArcAppPrefs(content::BrowserContext* browser_context, |
+ const base::FilePath& base_path, |
+ PrefService* prefs); |
+ |
+ // 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; |
+ |
+ 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); |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ArcAppPrefs); |
+}; |
+ |
+#endif // CHROME_BROWSER_UI_APP_LIST_ARC_APP_PREFS_H_ |