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

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

Issue 1153143002: Fix race condition in WebstoreInstallHelper (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix memleak Created 5 years, 6 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
« no previous file with comments | « no previous file | chrome/browser/extensions/webstore_install_helper.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 : public base::RefCounted<WebstoreInstallHelper>,
41 public chrome::BitmapFetcherDelegate { 38 public chrome::BitmapFetcherDelegate {
42 public: 39 public:
43 class Delegate { 40 class Delegate {
44 public: 41 public:
45 enum InstallHelperResultCode { 42 enum InstallHelperResultCode {
46 UNKNOWN_ERROR, 43 UNKNOWN_ERROR,
47 ICON_ERROR, 44 ICON_ERROR,
48 MANIFEST_ERROR 45 MANIFEST_ERROR
49 }; 46 };
50 47
(...skipping 17 matching lines...) Expand all
68 65
69 // It is legal for |icon_url| to be empty. 66 // It is legal for |icon_url| to be empty.
70 WebstoreInstallHelper(Delegate* delegate, 67 WebstoreInstallHelper(Delegate* delegate,
71 const std::string& id, 68 const std::string& id,
72 const std::string& manifest, 69 const std::string& manifest,
73 const GURL& icon_url, 70 const GURL& icon_url,
74 net::URLRequestContextGetter* context_getter); 71 net::URLRequestContextGetter* context_getter);
75 void Start(); 72 void Start();
76 73
77 private: 74 private:
75 friend class base::RefCounted<WebstoreInstallHelper>;
76
78 ~WebstoreInstallHelper() override; 77 ~WebstoreInstallHelper() override;
79 78
80 void StartWorkOnIOThread(); 79 // Callbacks for the SafeJsonParser.
81 void ReportResultsIfComplete(); 80 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); 81 void OnJSONParseFailed(const std::string& error_message);
90 82
91 // Implementing the chrome::BitmapFetcherDelegate interface. 83 // Implementing the chrome::BitmapFetcherDelegate interface.
92 void OnFetchComplete(const GURL& url, const SkBitmap* image) override; 84 void OnFetchComplete(const GURL& url, const SkBitmap* image) override;
93 85
86 void ReportResultsIfComplete();
87
94 // The client who we'll report results back to. 88 // The client who we'll report results back to.
95 Delegate* delegate_; 89 Delegate* delegate_;
96 90
97 // The extension id of the manifest we're parsing. 91 // The extension id of the manifest we're parsing.
98 std::string id_; 92 std::string id_;
99 93
100 // The manifest to parse. 94 // The manifest to parse.
101 std::string manifest_; 95 std::string manifest_;
102 96
97 scoped_refptr<SafeJsonParser> json_parser_;
98
103 // If |icon_url_| is non-empty, it needs to be fetched and decoded into an 99 // If |icon_url_| is non-empty, it needs to be fetched and decoded into an
104 // SkBitmap. 100 // SkBitmap.
105 GURL icon_url_; 101 GURL icon_url_;
106 net::URLRequestContextGetter* context_getter_; // Only usable on UI thread. 102 net::URLRequestContextGetter* context_getter_; // Only usable on UI thread.
107 scoped_ptr<chrome::BitmapFetcher> icon_fetcher_; 103 scoped_ptr<chrome::BitmapFetcher> icon_fetcher_;
108 104
109 base::WeakPtr<content::UtilityProcessHost> utility_host_;
110
111 // Flags for whether we're done doing icon decoding and manifest parsing. 105 // Flags for whether we're done doing icon decoding and manifest parsing.
112 bool icon_decode_complete_; 106 bool icon_decode_complete_;
113 bool manifest_parse_complete_; 107 bool manifest_parse_complete_;
114 108
115 // The results of successful decoding/parsing. 109 // The results of successful decoding/parsing.
116 SkBitmap icon_; 110 SkBitmap icon_;
117 scoped_ptr<base::DictionaryValue> parsed_manifest_; 111 scoped_ptr<base::DictionaryValue> parsed_manifest_;
118 112
119 // A details string for keeping track of any errors. 113 // A details string for keeping track of any errors.
120 std::string error_; 114 std::string error_;
121 115
122 // A code to distinguish between an error with the icon, and an error with the 116 // A code to distinguish between an error with the icon, and an error with the
123 // manifest. 117 // manifest.
124 Delegate::InstallHelperResultCode parse_error_; 118 Delegate::InstallHelperResultCode parse_error_;
125 }; 119 };
126 120
127 } // namespace extensions 121 } // namespace extensions
128 122
129 #endif // CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALL_HELPER_H_ 123 #endif // CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALL_HELPER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/webstore_install_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698