OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_CHROMEOS_APP_MODE_KIOSK_APP_DATA_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_APP_MODE_KIOSK_APP_DATA_H_ |
6 #define CHROME_BROWSER_CHROMEOS_APP_MODE_KIOSK_APP_DATA_H_ | 6 #define CHROME_BROWSER_CHROMEOS_APP_MODE_KIOSK_APP_DATA_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ref_counted.h" | |
14 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "chrome/browser/chromeos/app_mode/kiosk_app_data_base.h" |
15 #include "chrome/browser/extensions/webstore_data_fetcher_delegate.h" | 15 #include "chrome/browser/extensions/webstore_data_fetcher_delegate.h" |
16 #include "components/signin/core/account_id/account_id.h" | 16 #include "components/signin/core/account_id/account_id.h" |
17 #include "ui/gfx/image/image_skia.h" | |
18 #include "url/gurl.h" | 17 #include "url/gurl.h" |
19 | 18 |
20 class Profile; | 19 class Profile; |
21 | 20 |
22 namespace extensions { | 21 namespace extensions { |
23 class Extension; | 22 class Extension; |
24 class WebstoreDataFetcher; | 23 class WebstoreDataFetcher; |
25 } | 24 } |
26 | 25 |
27 namespace gfx { | 26 namespace gfx { |
28 class Image; | 27 class Image; |
29 } | 28 } |
30 | 29 |
31 namespace net { | 30 namespace net { |
32 class URLRequestContextGetter; | 31 class URLRequestContextGetter; |
33 } | 32 } |
34 | 33 |
35 namespace chromeos { | 34 namespace chromeos { |
36 | 35 |
37 class KioskAppDataDelegate; | 36 class KioskAppDataDelegate; |
38 | 37 |
39 // Fetches an app's web store data and manages the cached info such as name | 38 // Fetches an app's web store data and manages the cached info such as name |
40 // and icon. | 39 // and icon. |
41 class KioskAppData : public base::SupportsWeakPtr<KioskAppData>, | 40 class KioskAppData : public KioskAppDataBase, |
42 public extensions::WebstoreDataFetcherDelegate { | 41 public extensions::WebstoreDataFetcherDelegate { |
43 public: | 42 public: |
44 enum Status { | 43 enum Status { |
45 STATUS_INIT, // Data initialized with app id. | 44 STATUS_INIT, // Data initialized with app id. |
46 STATUS_LOADING, // Loading data from cache or web store. | 45 STATUS_LOADING, // Loading data from cache or web store. |
47 STATUS_LOADED, // Data loaded. | 46 STATUS_LOADED, // Data loaded. |
48 STATUS_ERROR, // Failed to load data. | 47 STATUS_ERROR, // Failed to load data. |
49 }; | 48 }; |
50 | 49 |
51 KioskAppData(KioskAppDataDelegate* delegate, | 50 KioskAppData(KioskAppDataDelegate* delegate, |
52 const std::string& app_id, | 51 const std::string& app_id, |
53 const AccountId& account_id, | 52 const AccountId& account_id, |
54 const GURL& update_url, | 53 const GURL& update_url, |
55 const base::FilePath& cached_crx); | 54 const base::FilePath& cached_crx); |
56 ~KioskAppData() override; | 55 ~KioskAppData() override; |
57 | 56 |
58 // Loads app data from cache. If there is no cached data, fetches it | 57 // Loads app data from cache. If there is no cached data, fetches it |
59 // from web store. | 58 // from web store. |
60 void Load(); | 59 void Load(); |
61 | 60 |
62 // Clears locally cached data. | |
63 void ClearCache(); | |
64 | |
65 // Loads app data from the app installed in the given profile. | 61 // Loads app data from the app installed in the given profile. |
66 void LoadFromInstalledApp(Profile* profile, const extensions::Extension* app); | 62 void LoadFromInstalledApp(Profile* profile, const extensions::Extension* app); |
67 | 63 |
68 // Sets full path of the cache crx. The crx would be used to extract meta | 64 // Sets full path of the cache crx. The crx would be used to extract meta |
69 // data for private apps. | 65 // data for private apps. |
70 void SetCachedCrx(const base::FilePath& crx_file); | 66 void SetCachedCrx(const base::FilePath& crx_file); |
71 | 67 |
72 // Returns true if web store data fetching is in progress. | 68 // Returns true if web store data fetching is in progress. |
73 bool IsLoading() const; | 69 bool IsLoading() const; |
74 | 70 |
75 // Returns true if the update url points to Webstore. | 71 // Returns true if the update url points to Webstore. |
76 bool IsFromWebStore() const; | 72 bool IsFromWebStore() const; |
77 | 73 |
78 const std::string& app_id() const { return app_id_; } | |
79 const AccountId& account_id() const { return account_id_; } | |
80 const std::string& name() const { return name_; } | |
81 const GURL& update_url() const { return update_url_; } | 74 const GURL& update_url() const { return update_url_; } |
82 const gfx::ImageSkia& icon() const { return icon_; } | |
83 const std::string& required_platform_version() const { | 75 const std::string& required_platform_version() const { |
84 return required_platform_version_; | 76 return required_platform_version_; |
85 } | 77 } |
86 Status status() const { return status_; } | 78 Status status() const { return status_; } |
87 | 79 |
88 void SetStatusForTest(Status status); | 80 void SetStatusForTest(Status status); |
89 | 81 |
90 static std::unique_ptr<KioskAppData> CreateForTest( | 82 static std::unique_ptr<KioskAppData> CreateForTest( |
91 KioskAppDataDelegate* delegate, | 83 KioskAppDataDelegate* delegate, |
92 const std::string& app_id, | 84 const std::string& app_id, |
93 const AccountId& account_id, | 85 const AccountId& account_id, |
94 const GURL& update_url, | 86 const GURL& update_url, |
95 const std::string& required_platform_version); | 87 const std::string& required_platform_version); |
96 | 88 |
| 89 // Callbacks for KioskAppIconLoader. |
| 90 void OnIconLoadSuccess(const gfx::ImageSkia& icon) override; |
| 91 void OnIconLoadFailure() override; |
| 92 |
97 private: | 93 private: |
98 class CrxLoader; | 94 class CrxLoader; |
99 class IconLoader; | |
100 class WebstoreDataParser; | 95 class WebstoreDataParser; |
101 | 96 |
102 void SetStatus(Status status); | 97 void SetStatus(Status status); |
103 | 98 |
104 // Returns URLRequestContextGetter to use for fetching web store data. | 99 // Returns URLRequestContextGetter to use for fetching web store data. |
105 net::URLRequestContextGetter* GetRequestContextGetter(); | 100 net::URLRequestContextGetter* GetRequestContextGetter(); |
106 | 101 |
107 // Loads the locally cached data. Return false if there is none. | 102 // Loads the locally cached data. Return false if there is none. |
108 bool LoadFromCache(); | 103 bool LoadFromCache(); |
109 | 104 |
110 // Sets the cached data. | 105 // Sets the cached data. |
111 void SetCache(const std::string& name, | 106 void SetCache(const std::string& name, |
112 const base::FilePath& icon_path, | |
113 const std::string& required_platform_version); | |
114 | |
115 // Helper to set the cached data using a SkBitmap icon. | |
116 void SetCache(const std::string& name, | |
117 const SkBitmap& icon, | 107 const SkBitmap& icon, |
118 const std::string& required_platform_version); | 108 const std::string& required_platform_version); |
119 | 109 |
120 // Callback for extensions::ImageLoader. | 110 // Callback for extensions::ImageLoader. |
121 void OnExtensionIconLoaded(const gfx::Image& icon); | 111 void OnExtensionIconLoaded(const gfx::Image& icon); |
122 | 112 |
123 // Callbacks for IconLoader. | |
124 void OnIconLoadSuccess(const gfx::ImageSkia& icon); | |
125 void OnIconLoadFailure(); | |
126 | |
127 // Callbacks for WebstoreDataParser | 113 // Callbacks for WebstoreDataParser |
128 void OnWebstoreParseSuccess(const SkBitmap& icon, | 114 void OnWebstoreParseSuccess(const SkBitmap& icon, |
129 const std::string& required_platform_version); | 115 const std::string& required_platform_version); |
130 void OnWebstoreParseFailure(); | 116 void OnWebstoreParseFailure(); |
131 | 117 |
132 // Starts to fetch data from web store. | 118 // Starts to fetch data from web store. |
133 void StartFetch(); | 119 void StartFetch(); |
134 | 120 |
135 // extensions::WebstoreDataFetcherDelegate overrides: | 121 // extensions::WebstoreDataFetcherDelegate overrides: |
136 void OnWebstoreRequestFailure() override; | 122 void OnWebstoreRequestFailure() override; |
(...skipping 10 matching lines...) Expand all Loading... |
147 | 133 |
148 // Extracts meta data from crx file when loading from Webstore and local | 134 // Extracts meta data from crx file when loading from Webstore and local |
149 // cache fails. | 135 // cache fails. |
150 void LoadFromCrx(); | 136 void LoadFromCrx(); |
151 | 137 |
152 void OnCrxLoadFinished(const CrxLoader* crx_loader); | 138 void OnCrxLoadFinished(const CrxLoader* crx_loader); |
153 | 139 |
154 KioskAppDataDelegate* delegate_; // not owned. | 140 KioskAppDataDelegate* delegate_; // not owned. |
155 Status status_; | 141 Status status_; |
156 | 142 |
157 std::string app_id_; | |
158 AccountId account_id_; | |
159 std::string name_; | |
160 GURL update_url_; | 143 GURL update_url_; |
161 gfx::ImageSkia icon_; | |
162 std::string required_platform_version_; | 144 std::string required_platform_version_; |
163 | 145 |
164 std::unique_ptr<extensions::WebstoreDataFetcher> webstore_fetcher_; | 146 std::unique_ptr<extensions::WebstoreDataFetcher> webstore_fetcher_; |
165 base::FilePath icon_path_; | |
166 | 147 |
167 base::FilePath crx_file_; | 148 base::FilePath crx_file_; |
168 | 149 |
| 150 base::WeakPtrFactory<KioskAppData> weak_factory_; |
| 151 |
169 DISALLOW_COPY_AND_ASSIGN(KioskAppData); | 152 DISALLOW_COPY_AND_ASSIGN(KioskAppData); |
170 }; | 153 }; |
171 | 154 |
172 } // namespace chromeos | 155 } // namespace chromeos |
173 | 156 |
174 #endif // CHROME_BROWSER_CHROMEOS_APP_MODE_KIOSK_APP_DATA_H_ | 157 #endif // CHROME_BROWSER_CHROMEOS_APP_MODE_KIOSK_APP_DATA_H_ |
OLD | NEW |