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 3 // found in the LICENSE file. 4 5 #ifndef CONTENT_BROWSER_LOADER_SYNC_RESOURCE_HANDLER_H_ 6 #define CONTENT_BROWSER_LOADER_SYNC_RESOURCE_HANDLER_H_ 7 8 #include <string> 9 10 #include "content/browser/loader/resource_handler.h" 11 #include "content/public/common/resource_response.h" 12 13 namespace IPC { 14 class Message; 15 } 16 17 namespace net { 18 class IOBuffer; 19 class URLRequest; 20 } 21 22 namespace content { 23 class ResourceDispatcherHostImpl; 24 class ResourceMessageFilter; 25 26 // Used to complete a synchronous resource request in response to resource load 27 // events from the resource dispatcher host. 28 class SyncResourceHandler : public ResourceHandler { 29 public: 30 SyncResourceHandler(ResourceMessageFilter* filter, 31 net::URLRequest* request, 32 IPC::Message* result_message, 33 ResourceDispatcherHostImpl* resource_dispatcher_host); 34 virtual ~SyncResourceHandler(); 35 36 virtual bool OnUploadProgress(int request_id, 37 uint64 position, 38 uint64 size) OVERRIDE; 39 virtual bool OnRequestRedirected(int request_id, 40 const GURL& new_url, 41 ResourceResponse* response, 42 bool* defer) OVERRIDE; 43 virtual bool OnResponseStarted(int request_id, 44 ResourceResponse* response, 45 bool* defer) OVERRIDE; 46 virtual bool OnWillStart(int request_id, 47 const GURL& url, 48 bool* defer) OVERRIDE; 49 virtual bool OnWillRead(int request_id, 50 net::IOBuffer** buf, 51 int* buf_size, 52 int min_size) OVERRIDE; 53 virtual bool OnReadCompleted(int request_id, 54 int bytes_read, 55 bool* defer) OVERRIDE; 56 virtual bool OnResponseCompleted(int request_id, 57 const net::URLRequestStatus& status, 58 const std::string& security_info) OVERRIDE; 59 virtual void OnDataDownloaded(int request_id, int bytes_downloaded) OVERRIDE; 60 61 private: 62 enum { kReadBufSize = 3840 }; 63 64 scoped_refptr<net::IOBuffer> read_buffer_; 65 66 SyncLoadResult result_; 67 scoped_refptr<ResourceMessageFilter> filter_; 68 net::URLRequest* request_; 69 IPC::Message* result_message_; 70 ResourceDispatcherHostImpl* rdh_; 71 }; 72 73 } // namespace content 74 75 #endif // CONTENT_BROWSER_LOADER_SYNC_RESOURCE_HANDLER_H_ 76