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