Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / chromeos / app_mode / kiosk_app_data.h
blob44104ad6d520dced6d9ba68a8a2c27eed17b8cad
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_CHROMEOS_APP_MODE_KIOSK_APP_DATA_H_
6 #define CHROME_BROWSER_CHROMEOS_APP_MODE_KIOSK_APP_DATA_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/files/file_path.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/weak_ptr.h"
14 #include "chrome/browser/extensions/webstore_data_fetcher_delegate.h"
15 #include "ui/gfx/image/image_skia.h"
16 #include "url/gurl.h"
18 class Profile;
20 namespace extensions {
21 class Extension;
22 class WebstoreDataFetcher;
25 namespace gfx {
26 class Image;
29 namespace net {
30 class URLRequestContextGetter;
33 namespace chromeos {
35 class KioskAppDataDelegate;
37 // Fetches an app's web store data and manages the cached info such as name
38 // and icon.
39 class KioskAppData : public base::SupportsWeakPtr<KioskAppData>,
40 public extensions::WebstoreDataFetcherDelegate {
41 public:
42 enum Status {
43 STATUS_INIT, // Data initialized with app id.
44 STATUS_LOADING, // Loading data from cache or web store.
45 STATUS_LOADED, // Data loaded.
46 STATUS_ERROR, // Failed to load data.
49 KioskAppData(KioskAppDataDelegate* delegate,
50 const std::string& app_id,
51 const std::string& user_id,
52 const GURL& update_url);
53 ~KioskAppData() override;
55 // Loads app data from cache. If there is no cached data, fetches it
56 // from web store.
57 void Load();
59 // Clears locally cached data.
60 void ClearCache();
62 // Loads app data from the app installed in the given profile.
63 void LoadFromInstalledApp(Profile* profile, const extensions::Extension* app);
65 // Sets full path of the cache crx. The crx would be used to extract meta
66 // data for private apps.
67 void SetCachedCrx(const base::FilePath& crx_file);
69 // Returns true if web store data fetching is in progress.
70 bool IsLoading() const;
72 // Returns true if the update url points to Webstore.
73 bool IsFromWebStore() const;
75 const std::string& app_id() const { return app_id_; }
76 const std::string& user_id() const { return user_id_; }
77 const std::string& name() const { return name_; }
78 const GURL& update_url() const { return update_url_; }
79 const gfx::ImageSkia& icon() const { return icon_; }
80 Status status() const { return status_; }
82 private:
83 class CrxLoader;
84 class IconLoader;
85 class WebstoreDataParser;
87 void SetStatus(Status status);
89 // Returns URLRequestContextGetter to use for fetching web store data.
90 net::URLRequestContextGetter* GetRequestContextGetter();
92 // Loads the locally cached data. Return false if there is none.
93 bool LoadFromCache();
95 // Sets the cached data.
96 void SetCache(const std::string& name, const base::FilePath& icon_path);
98 // Helper to set the cached data using a SkBitmap icon.
99 void SetCache(const std::string& name, const SkBitmap& icon);
101 // Callback for extensions::ImageLoader.
102 void OnExtensionIconLoaded(const gfx::Image& icon);
104 // Callbacks for IconLoader.
105 void OnIconLoadSuccess(const gfx::ImageSkia& icon);
106 void OnIconLoadFailure();
108 // Callbacks for WebstoreDataParser
109 void OnWebstoreParseSuccess(const SkBitmap& icon);
110 void OnWebstoreParseFailure();
112 // Starts to fetch data from web store.
113 void StartFetch();
115 // extensions::WebstoreDataFetcherDelegate overrides:
116 void OnWebstoreRequestFailure() override;
117 void OnWebstoreResponseParseSuccess(
118 scoped_ptr<base::DictionaryValue> webstore_data) override;
119 void OnWebstoreResponseParseFailure(const std::string& error) override;
121 // Helper function for testing for the existence of |key| in
122 // |response|. Passes |key|'s content via |value| and returns
123 // true when |key| is present.
124 bool CheckResponseKeyValue(const base::DictionaryValue* response,
125 const char* key,
126 std::string* value);
128 // Extracts meta data from crx file when loading from Webstore and local
129 // cache fails.
130 void MaybeLoadFromCrx();
132 void OnCrxLoadFinished(const CrxLoader* crx_loader);
134 KioskAppDataDelegate* delegate_; // not owned.
135 Status status_;
137 std::string app_id_;
138 std::string user_id_;
139 std::string name_;
140 GURL update_url_;
141 gfx::ImageSkia icon_;
143 scoped_ptr<extensions::WebstoreDataFetcher> webstore_fetcher_;
144 base::FilePath icon_path_;
146 base::FilePath crx_file_;
148 DISALLOW_COPY_AND_ASSIGN(KioskAppData);
151 } // namespace chromeos
153 #endif // CHROME_BROWSER_CHROMEOS_APP_MODE_KIOSK_APP_DATA_H_