Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / chromeos / app_mode / kiosk_app_data.h
blob4bf061c4ae1e604bcf1b97f157882a98e4626c99
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"
17 class Profile;
19 namespace base {
20 class RefCountedString;
23 namespace extensions {
24 class Extension;
25 class WebstoreDataFetcher;
28 namespace gfx {
29 class Image;
32 namespace net {
33 class URLRequestContextGetter;
36 namespace chromeos {
38 class KioskAppDataDelegate;
40 // Fetches an app's web store data and manages the cached info such as name
41 // and icon.
42 class KioskAppData : public base::SupportsWeakPtr<KioskAppData>,
43 public extensions::WebstoreDataFetcherDelegate {
44 public:
45 enum Status {
46 STATUS_INIT, // Data initialized with app id.
47 STATUS_LOADING, // Loading data from cache or web store.
48 STATUS_LOADED, // Data loaded.
49 STATUS_ERROR, // Failed to load data.
52 KioskAppData(KioskAppDataDelegate* delegate,
53 const std::string& app_id,
54 const std::string& user_id);
55 virtual ~KioskAppData();
57 // Loads app data from cache. If there is no cached data, fetches it
58 // from web store.
59 void Load();
61 // Clears locally cached data.
62 void ClearCache();
64 // Loads app data from the app installed in the given profile.
65 void LoadFromInstalledApp(Profile* profile, const extensions::Extension* app);
67 // Returns true if web store data fetching is in progress.
68 bool IsLoading() const;
70 const std::string& app_id() const { return app_id_; }
71 const std::string& user_id() const { return user_id_; }
72 const std::string& name() const { return name_; }
73 const gfx::ImageSkia& icon() const { return icon_; }
74 const base::RefCountedString* raw_icon() const {
75 return raw_icon_.get();
77 Status status() const { return status_; }
79 private:
80 class IconLoader;
81 class WebstoreDataParser;
83 void SetStatus(Status status);
85 // Returns URLRequestContextGetter to use for fetching web store data.
86 net::URLRequestContextGetter* GetRequestContextGetter();
88 // Loads the locally cached data. Return false if there is none.
89 bool LoadFromCache();
91 // Sets the cached data.
92 void SetCache(const std::string& name, const base::FilePath& icon_path);
94 // Helper to set the cached data using a SkBitmap icon.
95 void SetCache(const std::string& name, const SkBitmap& icon);
97 // Callback for extensions::ImageLoader.
98 void OnExtensionIconLoaded(const gfx::Image& icon);
100 // Callbacks for IconLoader.
101 void OnIconLoadSuccess(const scoped_refptr<base::RefCountedString>& raw_icon,
102 const gfx::ImageSkia& icon);
103 void OnIconLoadFailure();
105 // Callbacks for WebstoreDataParser
106 void OnWebstoreParseSuccess(const SkBitmap& icon);
107 void OnWebstoreParseFailure();
109 // Starts to fetch data from web store.
110 void StartFetch();
112 // extensions::WebstoreDataFetcherDelegate overrides:
113 virtual void OnWebstoreRequestFailure() OVERRIDE;
114 virtual void OnWebstoreResponseParseSuccess(
115 scoped_ptr<base::DictionaryValue> webstore_data) OVERRIDE;
116 virtual void OnWebstoreResponseParseFailure(
117 const std::string& error) OVERRIDE;
119 // Helper function for testing for the existence of |key| in
120 // |response|. Passes |key|'s content via |value| and returns
121 // true when |key| is present.
122 bool CheckResponseKeyValue(const base::DictionaryValue* response,
123 const char* key,
124 std::string* value);
126 KioskAppDataDelegate* delegate_; // not owned.
127 Status status_;
129 std::string app_id_;
130 std::string user_id_;
131 std::string name_;
132 gfx::ImageSkia icon_;
133 scoped_refptr<base::RefCountedString> raw_icon_;
135 scoped_ptr<extensions::WebstoreDataFetcher> webstore_fetcher_;
136 base::FilePath icon_path_;
138 DISALLOW_COPY_AND_ASSIGN(KioskAppData);
141 } // namespace chromeos
143 #endif // CHROME_BROWSER_CHROMEOS_APP_MODE_KIOSK_APP_DATA_H_