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