| 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_icon_loader.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" |
| 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 base::SupportsWeakPtr<KioskAppData>, |
| 42 public extensions::WebstoreDataFetcherDelegate { | 42 public extensions::WebstoreDataFetcherDelegate, |
| 43 public KioskAppIconLoader::Delegate { |
| 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, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 | 88 |
| 88 void SetStatusForTest(Status status); | 89 void SetStatusForTest(Status status); |
| 89 | 90 |
| 90 static std::unique_ptr<KioskAppData> CreateForTest( | 91 static std::unique_ptr<KioskAppData> CreateForTest( |
| 91 KioskAppDataDelegate* delegate, | 92 KioskAppDataDelegate* delegate, |
| 92 const std::string& app_id, | 93 const std::string& app_id, |
| 93 const AccountId& account_id, | 94 const AccountId& account_id, |
| 94 const GURL& update_url, | 95 const GURL& update_url, |
| 95 const std::string& required_platform_version); | 96 const std::string& required_platform_version); |
| 96 | 97 |
| 98 // Callbacks for KioskAppIconLoader. |
| 99 void OnIconLoadSuccess(const gfx::ImageSkia& icon) override; |
| 100 void OnIconLoadFailure() override; |
| 101 |
| 97 private: | 102 private: |
| 98 class CrxLoader; | 103 class CrxLoader; |
| 99 class IconLoader; | |
| 100 class WebstoreDataParser; | 104 class WebstoreDataParser; |
| 101 | 105 |
| 102 void SetStatus(Status status); | 106 void SetStatus(Status status); |
| 103 | 107 |
| 104 // Returns URLRequestContextGetter to use for fetching web store data. | 108 // Returns URLRequestContextGetter to use for fetching web store data. |
| 105 net::URLRequestContextGetter* GetRequestContextGetter(); | 109 net::URLRequestContextGetter* GetRequestContextGetter(); |
| 106 | 110 |
| 107 // Loads the locally cached data. Return false if there is none. | 111 // Loads the locally cached data. Return false if there is none. |
| 108 bool LoadFromCache(); | 112 bool LoadFromCache(); |
| 109 | 113 |
| 110 // Sets the cached data. | 114 // Sets the cached data. |
| 111 void SetCache(const std::string& name, | 115 void SetCache(const std::string& name, |
| 112 const base::FilePath& icon_path, | 116 const base::FilePath& icon_path, |
| 113 const std::string& required_platform_version); | 117 const std::string& required_platform_version); |
| 114 | 118 |
| 115 // Helper to set the cached data using a SkBitmap icon. | 119 // Helper to set the cached data using a SkBitmap icon. |
| 116 void SetCache(const std::string& name, | 120 void SetCache(const std::string& name, |
| 117 const SkBitmap& icon, | 121 const SkBitmap& icon, |
| 118 const std::string& required_platform_version); | 122 const std::string& required_platform_version); |
| 119 | 123 |
| 120 // Callback for extensions::ImageLoader. | 124 // Callback for extensions::ImageLoader. |
| 121 void OnExtensionIconLoaded(const gfx::Image& icon); | 125 void OnExtensionIconLoaded(const gfx::Image& icon); |
| 122 | 126 |
| 123 // Callbacks for IconLoader. | |
| 124 void OnIconLoadSuccess(const gfx::ImageSkia& icon); | |
| 125 void OnIconLoadFailure(); | |
| 126 | |
| 127 // Callbacks for WebstoreDataParser | 127 // Callbacks for WebstoreDataParser |
| 128 void OnWebstoreParseSuccess(const SkBitmap& icon, | 128 void OnWebstoreParseSuccess(const SkBitmap& icon, |
| 129 const std::string& required_platform_version); | 129 const std::string& required_platform_version); |
| 130 void OnWebstoreParseFailure(); | 130 void OnWebstoreParseFailure(); |
| 131 | 131 |
| 132 // Starts to fetch data from web store. | 132 // Starts to fetch data from web store. |
| 133 void StartFetch(); | 133 void StartFetch(); |
| 134 | 134 |
| 135 // extensions::WebstoreDataFetcherDelegate overrides: | 135 // extensions::WebstoreDataFetcherDelegate overrides: |
| 136 void OnWebstoreRequestFailure() override; | 136 void OnWebstoreRequestFailure() override; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 165 base::FilePath icon_path_; | 165 base::FilePath icon_path_; |
| 166 | 166 |
| 167 base::FilePath crx_file_; | 167 base::FilePath crx_file_; |
| 168 | 168 |
| 169 DISALLOW_COPY_AND_ASSIGN(KioskAppData); | 169 DISALLOW_COPY_AND_ASSIGN(KioskAppData); |
| 170 }; | 170 }; |
| 171 | 171 |
| 172 } // namespace chromeos | 172 } // namespace chromeos |
| 173 | 173 |
| 174 #endif // CHROME_BROWSER_CHROMEOS_APP_MODE_KIOSK_APP_DATA_H_ | 174 #endif // CHROME_BROWSER_CHROMEOS_APP_MODE_KIOSK_APP_DATA_H_ |
| OLD | NEW |