Add ENABLE_MEDIA_ROUTER define to builds other than Android and iOS.
[chromium-blink-merge.git] / chrome / browser / extensions / webstore_install_helper.h
blob08debed102e4b3eb4a076b947cdc2e0f252c9ce5
1 // Copyright (c) 2012 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_EXTENSIONS_WEBSTORE_INSTALL_HELPER_H_
6 #define CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALL_HELPER_H_
8 #include <vector>
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher_delegate.h"
13 #include "content/public/browser/utility_process_host_client.h"
14 #include "third_party/skia/include/core/SkBitmap.h"
15 #include "url/gurl.h"
17 namespace base {
18 class DictionaryValue;
19 class ListValue;
22 namespace chrome {
23 class BitmapFetcher;
26 namespace content {
27 class UtilityProcessHost;
30 namespace net {
31 class URLRequestContextGetter;
34 namespace extensions {
36 // This is a class to help dealing with webstore-provided data. It manages
37 // sending work to the utility process for parsing manifests and
38 // fetching/decoding icon data. Clients must implement the
39 // WebstoreInstallHelper::Delegate interface to receive the parsed data.
40 class WebstoreInstallHelper : public content::UtilityProcessHostClient,
41 public chrome::BitmapFetcherDelegate {
42 public:
43 class Delegate {
44 public:
45 enum InstallHelperResultCode {
46 UNKNOWN_ERROR,
47 ICON_ERROR,
48 MANIFEST_ERROR
51 // Called when we've successfully parsed the manifest and decoded the icon
52 // in the utility process. Ownership of parsed_manifest is transferred.
53 virtual void OnWebstoreParseSuccess(
54 const std::string& id,
55 const SkBitmap& icon,
56 base::DictionaryValue* parsed_manifest) = 0;
58 // Called to indicate a parse failure. The |result_code| parameter should
59 // indicate whether the problem was with the manifest or icon.
60 virtual void OnWebstoreParseFailure(
61 const std::string& id,
62 InstallHelperResultCode result_code,
63 const std::string& error_message) = 0;
65 protected:
66 virtual ~Delegate() {}
69 // It is legal for |icon_url| to be empty.
70 WebstoreInstallHelper(Delegate* delegate,
71 const std::string& id,
72 const std::string& manifest,
73 const GURL& icon_url,
74 net::URLRequestContextGetter* context_getter);
75 void Start();
77 private:
78 ~WebstoreInstallHelper() override;
80 void StartWorkOnIOThread();
81 void ReportResultsIfComplete();
82 void ReportResultFromUIThread();
84 // Implementing pieces of the UtilityProcessHostClient interface.
85 bool OnMessageReceived(const IPC::Message& message) override;
87 // Message handlers.
88 void OnJSONParseSucceeded(const base::ListValue& wrapper);
89 void OnJSONParseFailed(const std::string& error_message);
91 // Implementing the chrome::BitmapFetcherDelegate interface.
92 void OnFetchComplete(const GURL& url, const SkBitmap* image) override;
94 // The client who we'll report results back to.
95 Delegate* delegate_;
97 // The extension id of the manifest we're parsing.
98 std::string id_;
100 // The manifest to parse.
101 std::string manifest_;
103 // If |icon_url_| is non-empty, it needs to be fetched and decoded into an
104 // SkBitmap.
105 GURL icon_url_;
106 net::URLRequestContextGetter* context_getter_; // Only usable on UI thread.
107 scoped_ptr<chrome::BitmapFetcher> icon_fetcher_;
109 base::WeakPtr<content::UtilityProcessHost> utility_host_;
111 // Flags for whether we're done doing icon decoding and manifest parsing.
112 bool icon_decode_complete_;
113 bool manifest_parse_complete_;
115 // The results of successful decoding/parsing.
116 SkBitmap icon_;
117 scoped_ptr<base::DictionaryValue> parsed_manifest_;
119 // A details string for keeping track of any errors.
120 std::string error_;
122 // A code to distinguish between an error with the icon, and an error with the
123 // manifest.
124 Delegate::InstallHelperResultCode parse_error_;
127 } // namespace extensions
129 #endif // CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALL_HELPER_H_