Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: chrome/browser/extensions/webstore_install_helper.h

Issue 7741019: Move SafeBeginInstallHelper to be a top-level class (WebstoreInstallHelper). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review feedback Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 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.
4
5 #ifndef CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALL_HELPER_H_
6 #define CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALL_HELPER_H_
7 #pragma once
8
9 #include "content/browser/utility_process_host.h"
10 #include "content/common/url_fetcher.h"
11 #include "googleurl/src/gurl.h"
12 #include "third_party/skia/include/core/SkBitmap.h"
13
14 class UtilityProcessHost;
15 class SkBitmap;
16
17 namespace base {
18 class DictionaryValue;
19 class ListValue;
20 }
21
22 // This is a class to help dealing with webstore-provided data. It manages
23 // sending work to the utility process for parsing manifests and
24 // fetching/decoding icon data. Clients must implement the
25 // WebstoreInstallHelper::Delegate interface to receive the parsed data.
26 class WebstoreInstallHelper : public UtilityProcessHost::Client,
27 public URLFetcher::Delegate {
28 public:
29 class Delegate {
30 public:
31 enum InstallHelperResultCode {
32 UNKNOWN_ERROR,
33 ICON_ERROR,
34 MANIFEST_ERROR
35 };
36
37 // Called when we've successfully parsed the manifest and decoded the icon
38 // in the utility process. Ownership of parsed_manifest is transferred.
39 virtual void OnWebstoreParseSuccess(
40 const SkBitmap& icon,
41 base::DictionaryValue* parsed_manifest) = 0;
42
43 // Called to indicate a parse failure. The |result_code| parameter should
44 // indicate whether the problem was with the manifest or icon.
45 virtual void OnWebstoreParseFailure(
46 InstallHelperResultCode result_code,
47 const std::string& error_message) = 0;
48 };
49
50 // Only one of |icon_data| (based64-encoded icon data) or |icon_url| can be
51 // specified, but it is legal for both to be empty.
52 WebstoreInstallHelper(Delegate* delegate,
53 const std::string& manifest,
54 const std::string& icon_data,
55 const GURL& icon_url,
56 net::URLRequestContextGetter* context_getter);
57 void Start();
58
59 private:
60 ~WebstoreInstallHelper();
61
62 void StartWorkOnIOThread();
63 void StartFetchedImageDecode();
64 void ReportResultsIfComplete();
65 void ReportResultFromUIThread();
66
67 // Implementing the URLFetcher::Delegate interface.
68 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE;
69
70 // Implementing pieces of the UtilityProcessHost::Client interface.
71 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
72
73 // Message handlers.
74 void OnDecodeImageSucceeded(const SkBitmap& decoded_image);
75 void OnDecodeImageFailed();
76 void OnJSONParseSucceeded(const base::ListValue& wrapper);
77 void OnJSONParseFailed(const std::string& error_message);
78
79 // The client who we'll report results back to.
80 Delegate* delegate_;
81
82 // The manifest to parse.
83 std::string manifest_;
84
85 // Only one of these should be non-empty. If |icon_base64_data_| is non-emtpy,
86 // it's a base64-encoded string that needs to be parsed into an SkBitmap. If
87 // |icon_url_| is non-empty, it needs to be fetched and decoded into an
88 // SkBitmap.
89 std::string icon_base64_data_;
90 GURL icon_url_;
91 std::vector<unsigned char> fetched_icon_data_;
92
93 // For fetching the icon, if needed.
94 scoped_ptr<URLFetcher> url_fetcher_;
95 net::URLRequestContextGetter* context_getter_; // Only usable on UI thread.
96
97 UtilityProcessHost* utility_host_;
98
99 // Flags for whether we're done doing icon decoding and manifest parsing.
100 bool icon_decode_complete_;
101 bool manifest_parse_complete_;
102
103 // The results of succesful decoding/parsing.
104 SkBitmap icon_;
105 scoped_ptr<base::DictionaryValue> parsed_manifest_;
106
107 // A details string for keeping track of any errors.
108 std::string error_;
109
110 // A code to distinguish between an error with the icon, and an error with the
111 // manifest.
112 Delegate::InstallHelperResultCode parse_error_;
113 };
114
115 #endif // CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALL_HELPER_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_webstore_private_api.cc ('k') | chrome/browser/extensions/webstore_install_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698