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

Side by Side Diff: chrome/browser/plugin_process_host.cc

Issue 19004: Change URLRequest to use a ref-counted buffer for actual IO.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 10 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
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 #include "chrome/browser/plugin_process_host.h" 5 #include "chrome/browser/plugin_process_host.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 18 matching lines...) Expand all
29 #include "chrome/common/chrome_switches.h" 29 #include "chrome/common/chrome_switches.h"
30 #include "chrome/common/debug_flags.h" 30 #include "chrome/common/debug_flags.h"
31 #include "chrome/common/ipc_logging.h" 31 #include "chrome/common/ipc_logging.h"
32 #include "chrome/common/logging_chrome.h" 32 #include "chrome/common/logging_chrome.h"
33 #include "chrome/common/notification_service.h" 33 #include "chrome/common/notification_service.h"
34 #include "chrome/common/plugin_messages.h" 34 #include "chrome/common/plugin_messages.h"
35 #include "chrome/common/process_watcher.h" 35 #include "chrome/common/process_watcher.h"
36 #include "chrome/common/render_messages.h" 36 #include "chrome/common/render_messages.h"
37 #include "chrome/common/win_util.h" 37 #include "chrome/common/win_util.h"
38 #include "net/base/cookie_monster.h" 38 #include "net/base/cookie_monster.h"
39 #include "net/base/io_buffer.h"
39 #include "net/proxy/proxy_service.h" 40 #include "net/proxy/proxy_service.h"
40 #include "net/url_request/url_request.h" 41 #include "net/url_request/url_request.h"
41 #include "sandbox/src/sandbox.h" 42 #include "sandbox/src/sandbox.h"
42 #include "webkit/glue/plugins/plugin_constants_win.h" 43 #include "webkit/glue/plugins/plugin_constants_win.h"
43 44
44 static const char kDefaultPluginFinderURL[] = 45 static const char kDefaultPluginFinderURL[] =
45 "http://dl.google.com/chrome/plugins/plugins2.xml"; 46 "http://dl.google.com/chrome/plugins/plugins2.xml";
46 47
47 // The NotificationTask is used to notify about plugin process connection/ 48 // The NotificationTask is used to notify about plugin process connection/
48 // disconnection. It is needed because the notifications in the 49 // disconnection. It is needed because the notifications in the
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 protected: 121 protected:
121 void DownloadCompletedHelper(bool success); 122 void DownloadCompletedHelper(bool success);
122 123
123 // The download file request initiated by the plugin. 124 // The download file request initiated by the plugin.
124 URLRequest* download_file_request_; 125 URLRequest* download_file_request_;
125 // Handle to the downloaded file. 126 // Handle to the downloaded file.
126 HANDLE download_file_; 127 HANDLE download_file_;
127 // The full path of the downloaded file. 128 // The full path of the downloaded file.
128 std::wstring download_file_path_; 129 std::wstring download_file_path_;
129 // The buffer passed off to URLRequest::Read. 130 // The buffer passed off to URLRequest::Read.
130 char download_file_buffer_[kDownloadFileBufferSize]; 131 scoped_refptr<net::IOBuffer> download_file_buffer_;
131 // The window handle for sending the WM_COPYDATA notification, 132 // The window handle for sending the WM_COPYDATA notification,
132 // indicating that the download completed. 133 // indicating that the download completed.
133 HWND download_file_caller_window_; 134 HWND download_file_caller_window_;
134 135
135 std::string download_url_; 136 std::string download_url_;
136 int download_source_pid_; 137 int download_source_pid_;
137 138
138 DISALLOW_EVIL_CONSTRUCTORS(PluginDownloadUrlHelper); 139 DISALLOW_EVIL_CONSTRUCTORS(PluginDownloadUrlHelper);
139 }; 140 };
140 141
141 PluginDownloadUrlHelper::PluginDownloadUrlHelper( 142 PluginDownloadUrlHelper::PluginDownloadUrlHelper(
142 const std::string& download_url, 143 const std::string& download_url,
143 int source_pid, HWND caller_window) 144 int source_pid, HWND caller_window)
144 : download_url_(download_url), 145 : download_url_(download_url),
146 download_file_request_(NULL),
147 download_file_(INVALID_HANDLE_VALUE),
148 download_file_buffer_(new net::IOBuffer(kDownloadFileBufferSize)),
145 download_file_caller_window_(caller_window), 149 download_file_caller_window_(caller_window),
146 download_source_pid_(source_pid), 150 download_source_pid_(source_pid) {
147 download_file_request_(NULL),
148 download_file_(INVALID_HANDLE_VALUE) {
149 DCHECK(::IsWindow(caller_window)); 151 DCHECK(::IsWindow(caller_window));
150 memset(download_file_buffer_, 0, arraysize(download_file_buffer_)); 152 memset(download_file_buffer_->data(), 0, kDownloadFileBufferSize);
151 } 153 }
152 154
153 PluginDownloadUrlHelper::~PluginDownloadUrlHelper() { 155 PluginDownloadUrlHelper::~PluginDownloadUrlHelper() {
154 if (download_file_request_) { 156 if (download_file_request_) {
155 delete download_file_request_; 157 delete download_file_request_;
156 download_file_request_ = NULL; 158 download_file_request_ = NULL;
157 } 159 }
158 160
159 if (download_file_ != INVALID_HANDLE_VALUE) { 161 if (download_file_ != INVALID_HANDLE_VALUE) {
160 ::CloseHandle(INVALID_HANDLE_VALUE); 162 ::CloseHandle(INVALID_HANDLE_VALUE);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 NOTREACHED(); 205 NOTREACHED();
204 OnDownloadCompleted(request); 206 OnDownloadCompleted(request);
205 return; 207 return;
206 } 208 }
207 } 209 }
208 if (!request->status().is_success()) { 210 if (!request->status().is_success()) {
209 OnDownloadCompleted(request); 211 OnDownloadCompleted(request);
210 } else { 212 } else {
211 // Initiate a read. 213 // Initiate a read.
212 int bytes_read = 0; 214 int bytes_read = 0;
213 if (!request->Read(download_file_buffer_, arraysize(download_file_buffer_), 215 if (!request->Read(download_file_buffer_, kDownloadFileBufferSize,
214 &bytes_read)) { 216 &bytes_read)) {
215 // If the error is not an IO pending, then we're done 217 // If the error is not an IO pending, then we're done
216 // reading. 218 // reading.
217 if (!request->status().is_io_pending()) { 219 if (!request->status().is_io_pending()) {
218 OnDownloadCompleted(request); 220 OnDownloadCompleted(request);
219 } 221 }
220 } else if (bytes_read == 0) { 222 } else if (bytes_read == 0) {
221 OnDownloadCompleted(request); 223 OnDownloadCompleted(request);
222 } else { 224 } else {
223 OnReadCompleted(request, bytes_read); 225 OnReadCompleted(request, bytes_read);
224 } 226 }
225 } 227 }
226 } 228 }
227 229
228 void PluginDownloadUrlHelper::OnReadCompleted(URLRequest* request, 230 void PluginDownloadUrlHelper::OnReadCompleted(URLRequest* request,
229 int bytes_read) { 231 int bytes_read) {
230 DCHECK(download_file_ != INVALID_HANDLE_VALUE); 232 DCHECK(download_file_ != INVALID_HANDLE_VALUE);
231 233
232 if (bytes_read == 0) { 234 if (bytes_read == 0) {
233 OnDownloadCompleted(request); 235 OnDownloadCompleted(request);
234 return; 236 return;
235 } 237 }
236 238
237 int request_bytes_read = bytes_read; 239 int request_bytes_read = bytes_read;
238 240
239 while (request->status().is_success()) { 241 while (request->status().is_success()) {
240 unsigned long bytes_written = 0; 242 unsigned long bytes_written = 0;
241 BOOL write_result = WriteFile(download_file_, download_file_buffer_, 243 BOOL write_result = WriteFile(download_file_,
244 download_file_buffer_->data(),
242 request_bytes_read, &bytes_written, NULL); 245 request_bytes_read, &bytes_written, NULL);
243 DCHECK(!write_result || (bytes_written == request_bytes_read)); 246 DCHECK(!write_result || (bytes_written == request_bytes_read));
244 247
245 if (!write_result || (bytes_written != request_bytes_read)) { 248 if (!write_result || (bytes_written != request_bytes_read)) {
246 DownloadCompletedHelper(false); 249 DownloadCompletedHelper(false);
247 break; 250 break;
248 } 251 }
249 252
250 // Start reading 253 // Start reading
251 request_bytes_read = 0; 254 request_bytes_read = 0;
252 if (!request->Read(download_file_buffer_, arraysize(download_file_buffer_), 255 if (!request->Read(download_file_buffer_, kDownloadFileBufferSize,
253 &request_bytes_read)) { 256 &request_bytes_read)) {
254 if (!request->status().is_io_pending()) { 257 if (!request->status().is_io_pending()) {
255 // If the error is not an IO pending, then we're done 258 // If the error is not an IO pending, then we're done
256 // reading. 259 // reading.
257 OnDownloadCompleted(request); 260 OnDownloadCompleted(request);
258 } 261 }
259 break; 262 break;
260 } else if (request_bytes_read == 0) { 263 } else if (request_bytes_read == 0) {
261 OnDownloadCompleted(request); 264 OnDownloadCompleted(request);
262 break; 265 break;
(...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after
931 void PluginProcessHost::OnDestroyWindow(HWND window) { 934 void PluginProcessHost::OnDestroyWindow(HWND window) {
932 plugin_service_->main_message_loop()->PostTask(FROM_HERE, 935 plugin_service_->main_message_loop()->PostTask(FROM_HERE,
933 new DestroyWindowTask(window)); 936 new DestroyWindowTask(window));
934 } 937 }
935 938
936 void PluginProcessHost::Shutdown() { 939 void PluginProcessHost::Shutdown() {
937 940
938 Send(new PluginProcessMsg_BrowserShutdown); 941 Send(new PluginProcessMsg_BrowserShutdown);
939 } 942 }
940 943
OLDNEW
« no previous file with comments | « chrome/browser/net/url_fetcher.cc ('k') | chrome/browser/renderer_host/async_resource_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698