OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALL_HELPER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALL_HELPER_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALL_HELPER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALL_HELPER_H_ |
7 | 7 |
8 #include <vector> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/ref_counted.h" | |
10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
11 #include "base/memory/weak_ptr.h" | |
12 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher_delegate.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" | 13 #include "third_party/skia/include/core/SkBitmap.h" |
15 #include "url/gurl.h" | 14 #include "url/gurl.h" |
16 | 15 |
17 namespace base { | 16 namespace base { |
18 class DictionaryValue; | 17 class DictionaryValue; |
19 class ListValue; | 18 class Value; |
20 } | 19 } |
21 | 20 |
22 namespace chrome { | 21 namespace chrome { |
23 class BitmapFetcher; | 22 class BitmapFetcher; |
24 } | 23 } |
25 | 24 |
26 namespace content { | |
27 class UtilityProcessHost; | |
28 } | |
29 | |
30 namespace net { | 25 namespace net { |
31 class URLRequestContextGetter; | 26 class URLRequestContextGetter; |
32 } | 27 } |
33 | 28 |
29 class SafeJsonParser; | |
30 | |
34 namespace extensions { | 31 namespace extensions { |
35 | 32 |
36 // This is a class to help dealing with webstore-provided data. It manages | 33 // This is a class to help dealing with webstore-provided data. It manages |
37 // sending work to the utility process for parsing manifests and | 34 // sending work to the utility process for parsing manifests and |
38 // fetching/decoding icon data. Clients must implement the | 35 // fetching/decoding icon data. Clients must implement the |
39 // WebstoreInstallHelper::Delegate interface to receive the parsed data. | 36 // WebstoreInstallHelper::Delegate interface to receive the parsed data. |
40 class WebstoreInstallHelper : public content::UtilityProcessHostClient, | 37 class WebstoreInstallHelper |
41 public chrome::BitmapFetcherDelegate { | 38 : public base::RefCountedThreadSafe<WebstoreInstallHelper>, |
Marc Treib
2015/05/28 10:03:49
Before, we inherited that via UtilityProcessHostCl
asargent_no_longer_on_chrome
2015/05/28 17:08:47
Agreed - feel free to switch to plain RefCounted.
Marc Treib
2015/05/29 07:48:49
Done.
| |
39 public chrome::BitmapFetcherDelegate { | |
42 public: | 40 public: |
43 class Delegate { | 41 class Delegate { |
44 public: | 42 public: |
45 enum InstallHelperResultCode { | 43 enum InstallHelperResultCode { |
46 UNKNOWN_ERROR, | 44 UNKNOWN_ERROR, |
47 ICON_ERROR, | 45 ICON_ERROR, |
48 MANIFEST_ERROR | 46 MANIFEST_ERROR |
49 }; | 47 }; |
50 | 48 |
51 // Called when we've successfully parsed the manifest and decoded the icon | 49 // Called when we've successfully parsed the manifest and decoded the icon |
(...skipping 16 matching lines...) Expand all Loading... | |
68 | 66 |
69 // It is legal for |icon_url| to be empty. | 67 // It is legal for |icon_url| to be empty. |
70 WebstoreInstallHelper(Delegate* delegate, | 68 WebstoreInstallHelper(Delegate* delegate, |
71 const std::string& id, | 69 const std::string& id, |
72 const std::string& manifest, | 70 const std::string& manifest, |
73 const GURL& icon_url, | 71 const GURL& icon_url, |
74 net::URLRequestContextGetter* context_getter); | 72 net::URLRequestContextGetter* context_getter); |
75 void Start(); | 73 void Start(); |
76 | 74 |
77 private: | 75 private: |
76 friend class base::RefCountedThreadSafe<WebstoreInstallHelper>; | |
77 | |
78 ~WebstoreInstallHelper() override; | 78 ~WebstoreInstallHelper() override; |
79 | 79 |
80 void StartWorkOnIOThread(); | 80 // Callbacks for the SafeJsonParser. |
81 void ReportResultsIfComplete(); | 81 void OnJSONParseSucceeded(scoped_ptr<base::Value> result); |
82 void ReportResultFromUIThread(); | |
83 | |
84 // Implementing pieces of the UtilityProcessHostClient interface. | |
85 bool OnMessageReceived(const IPC::Message& message) override; | |
86 | |
87 // Message handlers. | |
88 void OnJSONParseSucceeded(const base::ListValue& wrapper); | |
89 void OnJSONParseFailed(const std::string& error_message); | 82 void OnJSONParseFailed(const std::string& error_message); |
90 | 83 |
91 // Implementing the chrome::BitmapFetcherDelegate interface. | 84 // Implementing the chrome::BitmapFetcherDelegate interface. |
92 void OnFetchComplete(const GURL& url, const SkBitmap* image) override; | 85 void OnFetchComplete(const GURL& url, const SkBitmap* image) override; |
93 | 86 |
87 void ReportResultsIfComplete(); | |
88 | |
94 // The client who we'll report results back to. | 89 // The client who we'll report results back to. |
95 Delegate* delegate_; | 90 Delegate* delegate_; |
96 | 91 |
97 // The extension id of the manifest we're parsing. | 92 // The extension id of the manifest we're parsing. |
98 std::string id_; | 93 std::string id_; |
99 | 94 |
100 // The manifest to parse. | 95 // The manifest to parse. |
101 std::string manifest_; | 96 std::string manifest_; |
102 | 97 |
98 scoped_refptr<SafeJsonParser> json_parser_; | |
99 | |
103 // If |icon_url_| is non-empty, it needs to be fetched and decoded into an | 100 // If |icon_url_| is non-empty, it needs to be fetched and decoded into an |
104 // SkBitmap. | 101 // SkBitmap. |
105 GURL icon_url_; | 102 GURL icon_url_; |
106 net::URLRequestContextGetter* context_getter_; // Only usable on UI thread. | 103 net::URLRequestContextGetter* context_getter_; // Only usable on UI thread. |
107 scoped_ptr<chrome::BitmapFetcher> icon_fetcher_; | 104 scoped_ptr<chrome::BitmapFetcher> icon_fetcher_; |
108 | 105 |
109 base::WeakPtr<content::UtilityProcessHost> utility_host_; | |
110 | |
111 // Flags for whether we're done doing icon decoding and manifest parsing. | 106 // Flags for whether we're done doing icon decoding and manifest parsing. |
112 bool icon_decode_complete_; | 107 bool icon_decode_complete_; |
113 bool manifest_parse_complete_; | 108 bool manifest_parse_complete_; |
114 | 109 |
115 // The results of successful decoding/parsing. | 110 // The results of successful decoding/parsing. |
116 SkBitmap icon_; | 111 SkBitmap icon_; |
117 scoped_ptr<base::DictionaryValue> parsed_manifest_; | 112 scoped_ptr<base::DictionaryValue> parsed_manifest_; |
118 | 113 |
119 // A details string for keeping track of any errors. | 114 // A details string for keeping track of any errors. |
120 std::string error_; | 115 std::string error_; |
121 | 116 |
122 // A code to distinguish between an error with the icon, and an error with the | 117 // A code to distinguish between an error with the icon, and an error with the |
123 // manifest. | 118 // manifest. |
124 Delegate::InstallHelperResultCode parse_error_; | 119 Delegate::InstallHelperResultCode parse_error_; |
125 }; | 120 }; |
126 | 121 |
127 } // namespace extensions | 122 } // namespace extensions |
128 | 123 |
129 #endif // CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALL_HELPER_H_ | 124 #endif // CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALL_HELPER_H_ |
OLD | NEW |