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_
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"
18 class RefCountedString;
21 namespace extensions {
22 class WebstoreDataFetcher;
26 class URLRequestContextGetter;
31 class KioskAppDataDelegate;
33 // Fetches an app's web store data and manages the cached info such as name
35 class KioskAppData : public base::SupportsWeakPtr<KioskAppData>,
36 public extensions::WebstoreDataFetcherDelegate {
39 STATUS_INIT, // Data initialized with app id.
40 STATUS_LOADING, // Loading data from cache or web store.
41 STATUS_LOADED, // Data loaded.
42 STATUS_ERROR, // Failed to load data.
45 KioskAppData(KioskAppDataDelegate* delegate,
46 const std::string& app_id,
47 const std::string& user_id);
48 virtual ~KioskAppData();
50 // Loads app data from cache. If there is no cached data, fetches it
54 // Clears locally cached data.
57 // Returns true if web store data fetching is in progress.
58 bool IsLoading() const;
60 const std::string& app_id() const { return app_id_; }
61 const std::string& user_id() const { return user_id_; }
62 const std::string& name() const { return name_; }
63 const gfx::ImageSkia& icon() const { return icon_; }
64 const base::RefCountedString* raw_icon() const {
65 return raw_icon_.get();
67 Status status() const { return status_; }
71 class WebstoreDataParser;
73 void SetStatus(Status status);
75 // Returns URLRequestContextGetter to use for fetching web store data.
76 net::URLRequestContextGetter* GetRequestContextGetter();
78 // Loads the locally cached data. Return false if there is none.
81 // Sets the cached data.
82 void SetCache(const std::string& name, const base::FilePath& icon_path);
84 // Callbacks for IconLoader.
85 void OnIconLoadSuccess(const scoped_refptr<base::RefCountedString>& raw_icon,
86 const gfx::ImageSkia& icon);
87 void OnIconLoadFailure();
89 // Callbacks for WebstoreDataParser
90 void OnWebstoreParseSuccess(const SkBitmap& icon);
91 void OnWebstoreParseFailure();
93 // Starts to fetch data from web store.
96 // extensions::WebstoreDataFetcherDelegate overrides:
97 virtual void OnWebstoreRequestFailure() OVERRIDE;
98 virtual void OnWebstoreResponseParseSuccess(
99 base::DictionaryValue* webstore_data) OVERRIDE;
100 virtual void OnWebstoreResponseParseFailure(
101 const std::string& error) OVERRIDE;
103 // Helper function for testing for the existence of |key| in
104 // |response|. Passes |key|'s content via |value| and returns
105 // true when |key| is present.
106 bool CheckResponseKeyValue(const base::DictionaryValue* response,
110 KioskAppDataDelegate* delegate_; // not owned.
114 std::string user_id_;
116 gfx::ImageSkia icon_;
117 scoped_refptr<base::RefCountedString> raw_icon_;
119 scoped_ptr<extensions::WebstoreDataFetcher> webstore_fetcher_;
120 base::FilePath icon_path_;
122 DISALLOW_COPY_AND_ASSIGN(KioskAppData);
125 } // namespace chromeos
127 #endif // CHROME_BROWSER_CHROMEOS_APP_MODE_KIOSK_APP_DATA_H_