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