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

Side by Side Diff: chrome/browser/chrome_plugin_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, 11 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/chrome_plugin_host.h" 5 #include "chrome/browser/chrome_plugin_host.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 // This class manages a network request made by the plugin, also acting as 139 // This class manages a network request made by the plugin, also acting as
140 // the URLRequest delegate. 140 // the URLRequest delegate.
141 // NOTE: All methods must be called on the IO thread. 141 // NOTE: All methods must be called on the IO thread.
142 class PluginRequestHandler : public PluginHelper, public URLRequest::Delegate { 142 class PluginRequestHandler : public PluginHelper, public URLRequest::Delegate {
143 public: 143 public:
144 static PluginRequestHandler* FromCPRequest(CPRequest* request) { 144 static PluginRequestHandler* FromCPRequest(CPRequest* request) {
145 return ScopableCPRequest::GetData<PluginRequestHandler*>(request); 145 return ScopableCPRequest::GetData<PluginRequestHandler*>(request);
146 } 146 }
147 147
148 PluginRequestHandler(ChromePluginLib* plugin, ScopableCPRequest* cprequest) 148 PluginRequestHandler(ChromePluginLib* plugin, ScopableCPRequest* cprequest)
149 : PluginHelper(plugin), cprequest_(cprequest) { 149 : PluginHelper(plugin), cprequest_(cprequest), user_buffer_(NULL) {
150 cprequest_->data = this; // see FromCPRequest(). 150 cprequest_->data = this; // see FromCPRequest().
151 151
152 URLRequestContext* context = CPBrowsingContextManager::Instance()-> 152 URLRequestContext* context = CPBrowsingContextManager::Instance()->
153 ToURLRequestContext(cprequest_->context); 153 ToURLRequestContext(cprequest_->context);
154 // TODO(mpcomplete): remove fallback case when Gears support is prevalent. 154 // TODO(mpcomplete): remove fallback case when Gears support is prevalent.
155 if (!context) 155 if (!context)
156 context = Profile::GetDefaultRequestContext(); 156 context = Profile::GetDefaultRequestContext();
157 157
158 GURL gurl(cprequest_->url); 158 GURL gurl(cprequest_->url);
159 request_.reset(new URLRequest(gurl, this)); 159 request_.reset(new URLRequest(gurl, this));
160 request_->set_context(context); 160 request_->set_context(context);
161 request_->set_method(cprequest_->method); 161 request_->set_method(cprequest_->method);
162 request_->set_load_flags(PluginResponseUtils::CPLoadFlagsToNetFlags(0)); 162 request_->set_load_flags(PluginResponseUtils::CPLoadFlagsToNetFlags(0));
163 } 163 }
164 164
165 URLRequest* request() { return request_.get(); } 165 URLRequest* request() { return request_.get(); }
166 166
167 // Wraper of URLRequest::Read()
168 bool Read(char* dest, int dest_size, int *bytes_read) {
169 CHECK(!my_buffer_.get());
170 // We'll use our own buffer until the read actually completes.
171 user_buffer_ = dest;
172 my_buffer_ = new net::IOBuffer(dest_size);
173
174 if (request_->Read(my_buffer_, dest_size, bytes_read)) {
175 memcpy(dest, my_buffer_->data(), *bytes_read);
176 my_buffer_ = NULL;
177 return true;
178 }
179
180 if (!request_->status().is_io_pending())
181 my_buffer_ = NULL;
182
183 return false;
184 }
185
167 // URLRequest::Delegate 186 // URLRequest::Delegate
168 virtual void OnReceivedRedirect(URLRequest* request, const GURL& new_url) { 187 virtual void OnReceivedRedirect(URLRequest* request, const GURL& new_url) {
169 plugin_->functions().response_funcs->received_redirect( 188 plugin_->functions().response_funcs->received_redirect(
170 cprequest_.get(), new_url.spec().c_str()); 189 cprequest_.get(), new_url.spec().c_str());
171 } 190 }
172 191
173 virtual void OnResponseStarted(URLRequest* request) { 192 virtual void OnResponseStarted(URLRequest* request) {
174 // TODO(mpcomplete): better error codes 193 // TODO(mpcomplete): better error codes
175 CPError result = 194 CPError result =
176 request_->status().is_success() ? CPERR_SUCCESS : CPERR_FAILURE; 195 request_->status().is_success() ? CPERR_SUCCESS : CPERR_FAILURE;
177 plugin_->functions().response_funcs->start_completed( 196 plugin_->functions().response_funcs->start_completed(
178 cprequest_.get(), result); 197 cprequest_.get(), result);
179 } 198 }
180 199
181 virtual void OnReadCompleted(URLRequest* request, int bytes_read) { 200 virtual void OnReadCompleted(URLRequest* request, int bytes_read) {
182 // TODO(mpcomplete): better error codes 201 CHECK(my_buffer_.get());
183 if (bytes_read < 0) 202 CHECK(user_buffer_);
203 if (bytes_read > 0) {
204 memcpy(user_buffer_, my_buffer_->data(), bytes_read);
205 } else if (bytes_read < 0) {
206 // TODO(mpcomplete): better error codes
184 bytes_read = CPERR_FAILURE; 207 bytes_read = CPERR_FAILURE;
208 }
209 my_buffer_ = NULL;
185 plugin_->functions().response_funcs->read_completed( 210 plugin_->functions().response_funcs->read_completed(
186 cprequest_.get(), bytes_read); 211 cprequest_.get(), bytes_read);
187 } 212 }
188 213
189 private: 214 private:
190 scoped_ptr<ScopableCPRequest> cprequest_; 215 scoped_ptr<ScopableCPRequest> cprequest_;
191 scoped_ptr<URLRequest> request_; 216 scoped_ptr<URLRequest> request_;
217 scoped_refptr<net::IOBuffer> my_buffer_;
218 char* user_buffer_;
192 }; 219 };
193 220
194 // This class manages plugins that want to handle UI commands. Right now, we 221 // This class manages plugins that want to handle UI commands. Right now, we
195 // only allow 1 plugin to do this, so there's only ever 1 instance of this 222 // only allow 1 plugin to do this, so there's only ever 1 instance of this
196 // class at once. 223 // class at once.
197 // NOTE: All methods must be called on the IO thread. 224 // NOTE: All methods must be called on the IO thread.
198 class PluginCommandHandler : public PluginHelper { 225 class PluginCommandHandler : public PluginHelper {
199 public: 226 public:
200 static void HandleCommand(int command, 227 static void HandleCommand(int command,
201 CPCommandInterface* data, 228 CPCommandInterface* data,
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 return PluginResponseUtils::GetResponseInfo( 635 return PluginResponseUtils::GetResponseInfo(
609 handler->request()->response_headers(), type, buf, buf_size); 636 handler->request()->response_headers(), type, buf, buf_size);
610 } 637 }
611 638
612 int STDCALL CPR_Read(CPRequest* request, void* buf, uint32 buf_size) { 639 int STDCALL CPR_Read(CPRequest* request, void* buf, uint32 buf_size) {
613 CHECK(ChromePluginLib::IsPluginThread()); 640 CHECK(ChromePluginLib::IsPluginThread());
614 PluginRequestHandler* handler = PluginRequestHandler::FromCPRequest(request); 641 PluginRequestHandler* handler = PluginRequestHandler::FromCPRequest(request);
615 CHECK(handler); 642 CHECK(handler);
616 643
617 int bytes_read; 644 int bytes_read;
618 if (handler->request()->Read(static_cast<char*>(buf), buf_size, &bytes_read)) 645 if (handler->Read(static_cast<char*>(buf), buf_size, &bytes_read))
619 return bytes_read; // 0 == CPERR_SUCESS 646 return bytes_read; // 0 == CPERR_SUCESS
620 647
621 if (handler->request()->status().is_io_pending()) 648 if (handler->request()->status().is_io_pending())
622 return CPERR_IO_PENDING; 649 return CPERR_IO_PENDING;
623 650
624 return CPERR_FAILURE; 651 return CPERR_FAILURE;
625 } 652 }
626 653
627 CPBool STDCALL CPB_IsPluginProcessRunning(CPID id) { 654 CPBool STDCALL CPB_IsPluginProcessRunning(CPID id) {
628 CHECK(ChromePluginLib::IsPluginThread()); 655 CHECK(ChromePluginLib::IsPluginThread());
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 void CPHandleCommand(int command, CPCommandInterface* data, 792 void CPHandleCommand(int command, CPCommandInterface* data,
766 CPBrowsingContext context) { 793 CPBrowsingContext context) {
767 // Sadly if we try and pass context through, we seem to break cl's little 794 // Sadly if we try and pass context through, we seem to break cl's little
768 // brain trying to compile the Tuple3 ctor. This cast works. 795 // brain trying to compile the Tuple3 ctor. This cast works.
769 int32 context_as_int32 = static_cast<int32>(context); 796 int32 context_as_int32 = static_cast<int32>(context);
770 // Plugins can only be accessed on the IO thread. 797 // Plugins can only be accessed on the IO thread.
771 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, 798 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
772 NewRunnableFunction(PluginCommandHandler::HandleCommand, 799 NewRunnableFunction(PluginCommandHandler::HandleCommand,
773 command, data, context_as_int32)); 800 command, data, context_as_int32));
774 } 801 }
OLDNEW
« no previous file with comments | « chrome/browser/automation/url_request_slow_download_job.cc ('k') | chrome/browser/dom_ui/chrome_url_data_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698