Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_UI_APP_LIST_ARC_APP_PREFS_H_ | |
| 6 #define CHROME_BROWSER_UI_APP_LIST_ARC_APP_PREFS_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <set> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/files/file_path.h" | |
| 13 #include "base/macros.h" | |
| 14 #include "base/memory/scoped_ptr.h" | |
| 15 #include "base/memory/weak_ptr.h" | |
| 16 #include "base/observer_list.h" | |
| 17 #include "components/arc/arc_bridge_service.h" | |
| 18 #include "components/keyed_service/core/keyed_service.h" | |
| 19 #include "ui/base/layout.h" | |
| 20 | |
| 21 class PrefService; | |
| 22 | |
| 23 namespace content { | |
| 24 class BrowserContext; | |
| 25 } | |
| 26 | |
| 27 namespace user_prefs { | |
| 28 class PrefRegistrySyncable; | |
| 29 } | |
| 30 | |
| 31 // Declares shareable arc app specific preferences, that keep information | |
| 32 // about app attributes (name, package, activity) and its state. This | |
| 33 // information is used to pre-create non-ready app items while Arc bridge | |
| 34 // service is not ready to provide information about available Android apps. | |
| 35 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
| |
| 36 public arc::ArcBridgeService::Observer { | |
| 37 public: | |
| 38 struct AppInfo { | |
| 39 std::string name; | |
| 40 std::string package; | |
| 41 std::string activity; | |
| 42 bool ready; | |
| 43 }; | |
| 44 | |
| 45 class Observer { | |
| 46 public: | |
| 47 // Notifies an observer that new app is registered. | |
| 48 virtual void OnAppRegistered(const std::string& app_id, | |
| 49 const AppInfo& app_info) = 0; | |
| 50 // Notifies an observer that app ready state has been changed. | |
| 51 virtual void OnAppReadyChanged(const std::string& id, bool ready) = 0; | |
| 52 // Notifies an observer that app icon has been installed or updated. | |
| 53 virtual void OnAppIconUpdated(const std::string& id, | |
| 54 ui::ScaleFactor scale_factor) = 0; | |
| 55 }; | |
| 56 | |
| 57 static ArcAppPrefs* Create(const base::FilePath& base_path, | |
| 58 PrefService* prefs); | |
| 59 | |
| 60 // Convenience function to get the ArcAppPrefs for a BrowserContext. | |
| 61 static ArcAppPrefs* Get(content::BrowserContext* context); | |
| 62 | |
| 63 // Constructs unique id based on package and activity information. This id | |
| 64 // is safe to use at file paths and as preference keys. | |
| 65 static std::string GetAppId(const std::string& package, | |
| 66 const std::string& activity); | |
| 67 | |
| 68 // It is called from chrome/browser/prefs/browser_prefs.cc. | |
| 69 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | |
| 70 | |
| 71 ~ArcAppPrefs() override; | |
| 72 | |
| 73 // Returns a list of all app ids, including ready and non-ready apps. | |
| 74 std::vector<std::string> GetAppIds() const; | |
| 75 | |
| 76 // Extracts attributes of an app based on its id. Returns NULL if the app is | |
| 77 // not found. | |
| 78 scoped_ptr<AppInfo> GetApp(const std::string& app_id) const; | |
| 79 | |
| 80 // Constructs path to app icon for specific scale factor. | |
| 81 base::FilePath GetIconPath(const std::string& app_id, | |
| 82 ui::ScaleFactor scale_factor) const; | |
| 83 | |
| 84 // Requests to load an app icon for specific scale factor. If the app or Arc | |
| 85 // bridge service is not ready, then defer this request until the app gets | |
| 86 // available. Once new icon is installed notifies an observer | |
| 87 // OnAppIconUpdated. | |
| 88 void RequestIcon(const std::string& app_id, ui::ScaleFactor scale_factor); | |
| 89 | |
| 90 // Returns true if app is registered. | |
| 91 bool IsRegistered(const std::string& app_id); | |
| 92 | |
| 93 void AddObserver(Observer* observer); | |
| 94 void RemoveObserver(Observer* observer); | |
| 95 | |
| 96 // arc::ArcBridgeService::Observer | |
| 97 void OnStateChanged(arc::ArcBridgeService::State state) override; | |
| 98 void OnAppsRefreshed(const std::vector<std::string>& name, | |
| 99 const std::vector<std::string>& packages) override; | |
| 100 void OnAppIcon(const std::string& package, | |
| 101 const std::string& activity, | |
| 102 int density, | |
| 103 const std::vector<uint8_t>& icon_png_data) override; | |
| 104 | |
| 105 private: | |
| 106 // See the Create methods. | |
| 107 ArcAppPrefs(const base::FilePath& base_path, PrefService* prefs); | |
| 108 | |
| 109 void OnAppReady(const std::string& name, const std::string& package); | |
| 110 void DisableAllApps(); | |
| 111 | |
| 112 // Installs an icon to file system in the special folder of the profile | |
| 113 // directory. | |
| 114 void InstallIcon(const std::string& app_id, | |
| 115 ui::ScaleFactor scale_factor, | |
| 116 const std::vector<uint8>& contentPng); | |
| 117 void InstallIconFromFileThread(const std::string& app_id, | |
| 118 ui::ScaleFactor scale_factor, | |
| 119 const std::vector<uint8>& contentPng); | |
| 120 void OnIconInstalled(const std::string& app_id, | |
| 121 ui::ScaleFactor scale_factor); | |
| 122 | |
| 123 content::BrowserContext* browser_context_; | |
|
xiyuan
2015/11/12 17:32:45
remove?
khmel1
2015/11/13 15:00:56
Done.
| |
| 124 // Owned by the BrowserContext. | |
| 125 PrefService* prefs_; | |
| 126 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.
| |
| 127 base::FilePath base_path_; | |
| 128 std::set<std::string> ready_apps_; | |
| 129 // Keeps deferred icon load requests. Each app may contain several requests | |
| 130 // for different scale factor. Scale factor is defined by specific bit | |
| 131 // position. | |
| 132 std::map<std::string, uint32> request_icon_deferred_; | |
| 133 | |
| 134 base::WeakPtrFactory<ArcAppPrefs> weak_ptr_factory_; | |
| 135 | |
| 136 DISALLOW_COPY_AND_ASSIGN(ArcAppPrefs); | |
| 137 }; | |
| 138 | |
| 139 #endif // CHROME_BROWSER_UI_APP_LIST_ARC_APP_PREFS_H_ | |
| OLD | NEW |