1 // Copyright 2014 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_PUBLIC_CHILD_REQUEST_PEER_H_ 6 #define CONTENT_PUBLIC_CHILD_REQUEST_PEER_H_ 7 8 #include <string> 9 10 #include "base/basictypes.h" 11 #include "content/common/content_export.h" 12 13 class GURL; 14 15 namespace base { 16 class TimeTicks; 17 } 18 19 namespace content { 20 21 struct ResourceResponseInfo; 22 23 // This is implemented by our custom resource loader within content. The Peer 24 // and it's bridge should have identical lifetimes as they represent each end of 25 // a communication channel. 26 // 27 // These callbacks mirror net::URLRequest::Delegate and the order and 28 // conditions in which they will be called are identical. See url_request.h 29 // for more information. 30 class CONTENT_EXPORT RequestPeer { 31 public: 32 // Called as upload progress is made. 33 // note: only for requests with LOAD_ENABLE_UPLOAD_PROGRESS set 34 virtual void OnUploadProgress(uint64 position, uint64 size) = 0; 35 36 // Called when a redirect occurs. The implementation may return false to 37 // suppress the redirect. The given ResponseInfo provides complete 38 // information about the redirect, and new_url is the URL that will be loaded 39 // if this method returns true. new_first_party_for_cookies is the new 40 // first-party URL for cookies should that have changed. 41 virtual bool OnReceivedRedirect(const GURL& new_url, 42 const GURL& new_first_party_for_cookies, 43 const ResourceResponseInfo& info) = 0; 44 45 // Called when response headers are available (after all redirects have 46 // been followed). 47 virtual void OnReceivedResponse(const ResourceResponseInfo& info) = 0; 48 49 // Called when a chunk of response data is downloaded. This method may be 50 // called multiple times or not at all if an error occurs. This method is 51 // only called if RequestInfo::download_to_file was set to true, and in 52 // that case, OnReceivedData will not be called. 53 // The encoded_data_length is the length of the encoded data transferred 54 // over the network, which could be different from data length (e.g. for 55 // gzipped content). 56 virtual void OnDownloadedData(int len, int encoded_data_length) = 0; 57 58 // Called when a chunk of response data is available. This method may 59 // be called multiple times or not at all if an error occurs. 60 // The encoded_data_length is the length of the encoded data transferred 61 // over the network, which could be different from data length (e.g. for 62 // gzipped content). 63 virtual void OnReceivedData(const char* data, 64 int data_length, 65 int encoded_data_length) = 0; 66 67 // Called when metadata generated by the renderer is retrieved from the 68 // cache. This method may be called zero or one times. 69 virtual void OnReceivedCachedMetadata(const char* data, int len) {} 70 71 // Called when the response is complete. This method signals completion of 72 // the resource load. 73 virtual void OnCompletedRequest(int error_code, 74 bool was_ignored_by_handler, 75 bool stale_copy_in_cache, 76 const std::string& security_info, 77 const base::TimeTicks& completion_time, 78 int64 total_transfer_size) = 0; 79 80 protected: 81 virtual ~RequestPeer() {} 82 }; 83 84 } // namespace content 85 86 #endif // CONTENT_PUBLIC_CHILD_REQUEST_PEER_H_ 87