OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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_ARC_DEFAULT_APP_LIST_H_ |
| 6 #define CHROME_BROWSER_UI_APP_LIST_ARC_ARC_DEFAULT_APP_LIST_H_ |
| 7 |
| 8 #include <stdint.h> |
| 9 |
| 10 #include <map> |
| 11 #include <memory> |
| 12 #include <string> |
| 13 |
| 14 #include "base/files/file_path.h" |
| 15 #include "base/macros.h" |
| 16 #include "base/memory/weak_ptr.h" |
| 17 |
| 18 // Contains map of default pre-installed apps and packages. |
| 19 class ArcDefaultAppList { |
| 20 public: |
| 21 class Delegate { |
| 22 public: |
| 23 virtual void OnDefaultAppsReady() = 0; |
| 24 |
| 25 protected: |
| 26 virtual ~Delegate() {} |
| 27 }; |
| 28 |
| 29 struct AppInfo { |
| 30 AppInfo(const std::string& name, |
| 31 const std::string& package_name, |
| 32 const std::string& activity, |
| 33 bool oem, |
| 34 const base::FilePath app_path); |
| 35 ~AppInfo(); |
| 36 |
| 37 std::string name; |
| 38 std::string package_name; |
| 39 std::string activity; |
| 40 bool oem; |
| 41 base::FilePath app_path; // App folder that contains pre-installed icons. |
| 42 }; |
| 43 |
| 44 // Defines App id to default AppInfo mapping. |
| 45 using AppInfoMap = std::map<std::string, std::unique_ptr<AppInfo>>; |
| 46 |
| 47 explicit ArcDefaultAppList(Delegate* delegate); |
| 48 ~ArcDefaultAppList(); |
| 49 |
| 50 static void UseTestAppsDirectory(); |
| 51 |
| 52 // Returns default app info if it is found in defaults and its package is not |
| 53 // marked as uninstalled. |
| 54 const AppInfo* GetApp(const std::string& app_id) const; |
| 55 // Returns true if app is found in defaults and its package is not marked as |
| 56 // uninstalled. |
| 57 bool HasApp(const std::string& app_id) const; |
| 58 // Returns true if package exists in default packages list. Note it may be |
| 59 // marked as uninstalled. |
| 60 bool HasPackage(const std::string& package_name) const; |
| 61 // Sets uninstalled flag for default package if it exists in default packages |
| 62 // list. |
| 63 void MaybeMarkPackageUninstalled(const std::string& package_name, |
| 64 bool uninstalled); |
| 65 |
| 66 const AppInfoMap& app_map() const { return apps_; } |
| 67 |
| 68 private: |
| 69 // Defines mapping package name to uninstalled state. |
| 70 using PacakageMap = std::map<std::string, bool>; |
| 71 |
| 72 // Called when default apps are read. |
| 73 void OnAppsReady(std::unique_ptr<AppInfoMap> apps); |
| 74 |
| 75 // Unowned pointer. |
| 76 Delegate* const delegate_; |
| 77 |
| 78 AppInfoMap apps_; |
| 79 PacakageMap packages_; |
| 80 |
| 81 base::WeakPtrFactory<ArcDefaultAppList> weak_ptr_factory_; |
| 82 |
| 83 DISALLOW_COPY_AND_ASSIGN(ArcDefaultAppList); |
| 84 }; |
| 85 |
| 86 #endif // CHROME_BROWSER_UI_APP_LIST_ARC_ARC_DEFAULT_APP_LIST_H_ |
OLD | NEW |