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