OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_UI_APP_LIST_ARC_ARC_APP_LIST_PREFS_H_ | 5 #ifndef CHROME_BROWSER_UI_APP_LIST_ARC_ARC_APP_LIST_PREFS_H_ |
6 #define CHROME_BROWSER_UI_APP_LIST_ARC_ARC_APP_LIST_PREFS_H_ | 6 #define CHROME_BROWSER_UI_APP_LIST_ARC_ARC_APP_LIST_PREFS_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
11 #include <memory> | 11 #include <memory> |
12 #include <string> | 12 #include <string> |
13 #include <unordered_set> | 13 #include <unordered_set> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
17 #include "base/macros.h" | 17 #include "base/macros.h" |
18 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
19 #include "base/observer_list.h" | 19 #include "base/observer_list.h" |
20 #include "base/time/time.h" | 20 #include "base/time/time.h" |
21 #include "chrome/browser/chromeos/arc/arc_auth_service.h" | 21 #include "chrome/browser/chromeos/arc/arc_auth_service.h" |
| 22 #include "chrome/browser/ui/app_list/arc/arc_default_app_list.h" |
22 #include "components/arc/common/app.mojom.h" | 23 #include "components/arc/common/app.mojom.h" |
23 #include "components/arc/instance_holder.h" | 24 #include "components/arc/instance_holder.h" |
24 #include "components/keyed_service/core/keyed_service.h" | 25 #include "components/keyed_service/core/keyed_service.h" |
25 #include "mojo/public/cpp/bindings/binding.h" | 26 #include "mojo/public/cpp/bindings/binding.h" |
26 #include "ui/base/layout.h" | 27 #include "ui/base/layout.h" |
27 | 28 |
28 class PrefService; | 29 class PrefService; |
29 class Profile; | 30 class Profile; |
30 | 31 |
31 namespace arc { | 32 namespace arc { |
(...skipping 10 matching lines...) Expand all Loading... |
42 | 43 |
43 // Declares shareable ARC app specific preferences, that keep information | 44 // Declares shareable ARC app specific preferences, that keep information |
44 // about app attributes (name, package_name, activity) and its state. This | 45 // about app attributes (name, package_name, activity) and its state. This |
45 // information is used to pre-create non-ready app items while ARC bridge | 46 // information is used to pre-create non-ready app items while ARC bridge |
46 // service is not ready to provide information about available ARC apps. | 47 // service is not ready to provide information about available ARC apps. |
47 // NOTE: ArcAppListPrefs is only created for the primary user. | 48 // NOTE: ArcAppListPrefs is only created for the primary user. |
48 class ArcAppListPrefs | 49 class ArcAppListPrefs |
49 : public KeyedService, | 50 : public KeyedService, |
50 public arc::mojom::AppHost, | 51 public arc::mojom::AppHost, |
51 public arc::InstanceHolder<arc::mojom::AppInstance>::Observer, | 52 public arc::InstanceHolder<arc::mojom::AppInstance>::Observer, |
52 public arc::ArcAuthService::Observer { | 53 public arc::ArcAuthService::Observer, |
| 54 public ArcDefaultAppList::Delegate { |
53 public: | 55 public: |
54 struct AppInfo { | 56 struct AppInfo { |
55 AppInfo(const std::string& name, | 57 AppInfo(const std::string& name, |
56 const std::string& package_name, | 58 const std::string& package_name, |
57 const std::string& activity, | 59 const std::string& activity, |
58 const std::string& intent_uri, | 60 const std::string& intent_uri, |
59 const std::string& icon_resource_id, | 61 const std::string& icon_resource_id, |
60 const base::Time& last_launch_time, | 62 const base::Time& last_launch_time, |
61 const base::Time& install_time, | 63 const base::Time& install_time, |
62 bool sticky, | 64 bool sticky, |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 void RequestIcon(const std::string& app_id, ui::ScaleFactor scale_factor); | 196 void RequestIcon(const std::string& app_id, ui::ScaleFactor scale_factor); |
195 | 197 |
196 // Sets notification enabled flag for given value. If the app or Arc bridge | 198 // Sets notification enabled flag for given value. If the app or Arc bridge |
197 // service is not ready, then defer this request until the app gets | 199 // service is not ready, then defer this request until the app gets |
198 // available. Once new value is set notifies an observer | 200 // available. Once new value is set notifies an observer |
199 // OnNotificationsEnabledChanged. | 201 // OnNotificationsEnabledChanged. |
200 void SetNotificationsEnabled(const std::string& app_id, bool enabled); | 202 void SetNotificationsEnabled(const std::string& app_id, bool enabled); |
201 | 203 |
202 // Returns true if app is registered. | 204 // Returns true if app is registered. |
203 bool IsRegistered(const std::string& app_id) const; | 205 bool IsRegistered(const std::string& app_id) const; |
| 206 // Returns true if app is a default app. |
| 207 bool IsDefault(const std::string& app_id) const; |
| 208 // Returns true if app is an OEM app. |
| 209 bool IsOem(const std::string& app_id) const; |
204 // Returns true if app is a shortcut | 210 // Returns true if app is a shortcut |
205 bool IsShortcut(const std::string& app_id) const; | 211 bool IsShortcut(const std::string& app_id) const; |
206 | 212 |
207 void AddObserver(Observer* observer); | 213 void AddObserver(Observer* observer); |
208 void RemoveObserver(Observer* observer); | 214 void RemoveObserver(Observer* observer); |
209 bool HasObserver(Observer* observer); | 215 bool HasObserver(Observer* observer); |
210 | 216 |
211 // arc::ArcAuthService::Observer: | 217 // arc::ArcAuthService::Observer: |
212 void OnOptInEnabled(bool enabled) override; | 218 void OnOptInEnabled(bool enabled) override; |
213 | 219 |
| 220 // ArcDefaultAppList::Delegate: |
| 221 void OnDefaultAppsReady() override; |
| 222 |
214 // Removes app with the given app_id. | 223 // Removes app with the given app_id. |
215 void RemoveApp(const std::string& app_id); | 224 void RemoveApp(const std::string& app_id); |
216 | 225 |
217 arc::InstanceHolder<arc::mojom::AppInstance>* app_instance_holder() { | 226 arc::InstanceHolder<arc::mojom::AppInstance>* app_instance_holder() { |
218 return app_instance_holder_; | 227 return app_instance_holder_; |
219 } | 228 } |
220 | 229 |
221 std::unordered_set<std::string> GetAppsForPackage( | 230 std::unordered_set<std::string> GetAppsForPackage( |
222 const std::string& package_name) const; | 231 const std::string& package_name) const; |
223 | 232 |
| 233 void SetDefaltAppsReadyCallback(base::Closure callback); |
| 234 |
224 private: | 235 private: |
225 friend class ChromeLauncherControllerImplTest; | 236 friend class ChromeLauncherControllerImplTest; |
226 | 237 |
227 // See the Create methods. | 238 // See the Create methods. |
228 ArcAppListPrefs( | 239 ArcAppListPrefs( |
229 Profile* profile, | 240 Profile* profile, |
230 arc::InstanceHolder<arc::mojom::AppInstance>* app_instance_holder); | 241 arc::InstanceHolder<arc::mojom::AppInstance>* app_instance_holder); |
231 | 242 |
232 // arc::InstanceHolder<arc::mojom::AppInstance>::Observer: | 243 // arc::InstanceHolder<arc::mojom::AppInstance>::Observer: |
233 void OnInstanceReady() override; | 244 void OnInstanceReady() override; |
(...skipping 23 matching lines...) Expand all Loading... |
257 void OnNotificationsEnabledChanged(const mojo::String& package_name, | 268 void OnNotificationsEnabledChanged(const mojo::String& package_name, |
258 bool enabled) override; | 269 bool enabled) override; |
259 void OnPackageAdded(arc::mojom::ArcPackageInfoPtr package_info) override; | 270 void OnPackageAdded(arc::mojom::ArcPackageInfoPtr package_info) override; |
260 void OnPackageModified(arc::mojom::ArcPackageInfoPtr package_info) override; | 271 void OnPackageModified(arc::mojom::ArcPackageInfoPtr package_info) override; |
261 void OnPackageListRefreshed( | 272 void OnPackageListRefreshed( |
262 mojo::Array<arc::mojom::ArcPackageInfoPtr> packages) override; | 273 mojo::Array<arc::mojom::ArcPackageInfoPtr> packages) override; |
263 void OnTaskOrientationLockRequested( | 274 void OnTaskOrientationLockRequested( |
264 int32_t task_id, | 275 int32_t task_id, |
265 const arc::mojom::OrientationLock orientation_lock) override; | 276 const arc::mojom::OrientationLock orientation_lock) override; |
266 | 277 |
| 278 void StartPrefs(); |
| 279 |
| 280 // Returns list of packages from prefs. If |installed| is set to true then |
| 281 // returns currently installed packages. If not, returns list of packages that |
| 282 // where uninstalled. Note, we store uninstall packages only for packages of |
| 283 // default apps. |
| 284 std::vector<std::string> GetPackagesFromPrefs(bool installed) const; |
| 285 |
267 void AddApp(const arc::mojom::AppInfo& app_info); | 286 void AddApp(const arc::mojom::AppInfo& app_info); |
268 void AddAppAndShortcut(const std::string& name, | 287 void AddAppAndShortcut(const std::string& name, |
269 const std::string& package_name, | 288 const std::string& package_name, |
270 const std::string& activity, | 289 const std::string& activity, |
271 const std::string& intent_uri, | 290 const std::string& intent_uri, |
272 const std::string& icon_resource_id, | 291 const std::string& icon_resource_id, |
273 const bool sticky, | 292 const bool sticky, |
274 const bool notifications_enabled, | 293 const bool notifications_enabled, |
275 const bool shortcut, | 294 const bool shortcut, |
276 const bool launchable, | 295 const bool launchable, |
277 arc::mojom::OrientationLock orientation_lock); | 296 arc::mojom::OrientationLock orientation_lock); |
| 297 // Adds or updates local pref for given package. |
| 298 void AddOrUpdatePackagePrefs(PrefService* prefs, |
| 299 const arc::mojom::ArcPackageInfo& package); |
| 300 // Removes given package from local pref. |
| 301 void RemovePackageFromPrefs(PrefService* prefs, |
| 302 const std::string& package_name); |
| 303 |
278 void DisableAllApps(); | 304 void DisableAllApps(); |
279 void RemoveAllApps(); | 305 void RemoveAllApps(); |
280 std::vector<std::string> GetAppIdsNoArcEnabledCheck() const; | 306 std::vector<std::string> GetAppIdsNoArcEnabledCheck() const; |
281 // Enumerates apps from preferences and notifies listeners about available | 307 // Enumerates apps from preferences and notifies listeners about available |
282 // apps while Arc is not started yet. All apps in this case have disabled | 308 // apps while Arc is not started yet. All apps in this case have disabled |
283 // state. | 309 // state. |
284 void NotifyRegisteredApps(); | 310 void NotifyRegisteredApps(); |
285 base::Time GetInstallTime(const std::string& app_id) const; | 311 base::Time GetInstallTime(const std::string& app_id) const; |
286 | 312 |
287 // Installs an icon to file system in the special folder of the profile | 313 // Installs an icon to file system in the special folder of the profile |
288 // directory. | 314 // directory. |
289 void InstallIcon(const std::string& app_id, | 315 void InstallIcon(const std::string& app_id, |
290 ui::ScaleFactor scale_factor, | 316 ui::ScaleFactor scale_factor, |
291 const std::vector<uint8_t>& contentPng); | 317 const std::vector<uint8_t>& contentPng); |
292 void OnIconInstalled(const std::string& app_id, | 318 void OnIconInstalled(const std::string& app_id, |
293 ui::ScaleFactor scale_factor, | 319 ui::ScaleFactor scale_factor, |
294 bool install_succeed); | 320 bool install_succeed); |
295 | 321 |
296 // This checks if app is not registered yet and in this case creates | 322 // This checks if app is not registered yet and in this case creates |
297 // non-launchable app entry. | 323 // non-launchable app entry. |
298 void MayAddNonLaunchableApp(const std::string& name, | 324 void MaybeAddNonLaunchableApp(const std::string& name, |
299 const std::string& package_name, | 325 const std::string& package_name, |
300 const std::string& activity); | 326 const std::string& activity); |
301 | 327 |
302 // Reveals first app from provided package in app launcher if package is newly | 328 // Reveals first app from provided package in app launcher if package is newly |
303 // installed by user. If all apps in package are hidden then app list is not | 329 // installed by user. If all apps in package are hidden then app list is not |
304 // shown. | 330 // shown. |
305 void MaybeShowPackageInAppLauncher( | 331 void MaybeShowPackageInAppLauncher( |
306 const arc::mojom::ArcPackageInfo& package_info); | 332 const arc::mojom::ArcPackageInfo& package_info); |
307 | 333 |
308 Profile* const profile_; | 334 Profile* const profile_; |
309 | 335 |
310 // Owned by the BrowserContext. | 336 // Owned by the BrowserContext. |
(...skipping 14 matching lines...) Expand all Loading... |
325 std::map<std::string, uint32_t> request_icon_deferred_; | 351 std::map<std::string, uint32_t> request_icon_deferred_; |
326 // True if this preference has been initialized once. | 352 // True if this preference has been initialized once. |
327 bool is_initialized_ = false; | 353 bool is_initialized_ = false; |
328 // True if apps were restored. | 354 // True if apps were restored. |
329 bool apps_restored_ = false; | 355 bool apps_restored_ = false; |
330 | 356 |
331 arc::ArcPackageSyncableService* sync_service_; | 357 arc::ArcPackageSyncableService* sync_service_; |
332 | 358 |
333 mojo::Binding<arc::mojom::AppHost> binding_; | 359 mojo::Binding<arc::mojom::AppHost> binding_; |
334 | 360 |
| 361 bool default_apps_ready_ = false; |
| 362 ArcDefaultAppList default_apps_; |
| 363 base::Closure default_apps_ready_callback_; |
| 364 |
335 base::WeakPtrFactory<ArcAppListPrefs> weak_ptr_factory_; | 365 base::WeakPtrFactory<ArcAppListPrefs> weak_ptr_factory_; |
336 | 366 |
337 DISALLOW_COPY_AND_ASSIGN(ArcAppListPrefs); | 367 DISALLOW_COPY_AND_ASSIGN(ArcAppListPrefs); |
338 }; | 368 }; |
339 | 369 |
340 #endif // CHROME_BROWSER_UI_APP_LIST_ARC_ARC_APP_LIST_PREFS_H_ | 370 #endif // CHROME_BROWSER_UI_APP_LIST_ARC_ARC_APP_LIST_PREFS_H_ |
OLD | NEW |