Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(767)

Side by Side Diff: chrome/browser/ui/app_list/arc_app_list_prefs.h

Issue 1413153007: arc-app-launcher: Minimal support for ARC app launcher. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: revert wrongly update chrome/chrome_browser_ui.gypi Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_LIST_PREFS_H_
6 #define CHROME_BROWSER_UI_APP_LIST_ARC_APP_LIST_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 ARC apps.
35 class ArcAppListPrefs : public KeyedService,
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 ArcAppListPrefs* Create(const base::FilePath& base_path,
58 PrefService* prefs);
59
60 // Convenience function to get the ArcAppListPrefs for a BrowserContext.
61 static ArcAppListPrefs* 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 ~ArcAppListPrefs() 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,
100 const std::vector<std::string>& activities) override;
101 void OnAppIcon(const std::string& package,
102 const std::string& activity,
103 int scale_factor,
104 const std::vector<uint8_t>& icon_png_data) override;
105
106 private:
107 // See the Create methods.
108 ArcAppListPrefs(const base::FilePath& base_path, PrefService* prefs);
109
110 void OnAppReady(const std::string& name,
111 const std::string& package,
112 const std::string& activity);
113 void DisableAllApps();
114
115 // Installs an icon to file system in the special folder of the profile
116 // directory.
117 void InstallIcon(const std::string& app_id,
118 ui::ScaleFactor scale_factor,
119 const std::vector<uint8>& contentPng);
120 void InstallIconFromFileThread(const std::string& app_id,
121 ui::ScaleFactor scale_factor,
122 const std::vector<uint8>& contentPng);
123 void OnIconInstalled(const std::string& app_id,
124 ui::ScaleFactor scale_factor);
125
126 // Owned by the BrowserContext.
127 PrefService* prefs_;
128
129 // List of observers.
130 base::ObserverList<Observer> observer_list_;
131 // Keeps root folder where ARC app icons for different scale factor are
132 // stored.
133 base::FilePath base_path_;
134 // Contains set of ARC apps that are currently ready.
135 std::set<std::string> ready_apps_;
136 // Keeps deferred icon load requests. Each app may contain several requests
137 // for different scale factor. Scale factor is defined by specific bit
138 // position.
139 std::map<std::string, uint32> request_icon_deferred_;
140
141 base::WeakPtrFactory<ArcAppListPrefs> weak_ptr_factory_;
142
143 DISALLOW_COPY_AND_ASSIGN(ArcAppListPrefs);
144 };
145
146 #endif // CHROME_BROWSER_UI_APP_LIST_ARC_APP_LIST_PREFS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698