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