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.
5 #ifndef CONTENT_PUBLIC_CHILD_REQUEST_PEER_H_
6 #define CONTENT_PUBLIC_CHILD_REQUEST_PEER_H_
10 #include "base/basictypes.h"
11 #include "content/common/content_export.h"
25 struct ResourceResponseInfo
;
27 // This is implemented by our custom resource loader within content. The Peer
28 // and it's bridge should have identical lifetimes as they represent each end of
29 // a communication channel.
31 // These callbacks mirror net::URLRequest::Delegate and the order and
32 // conditions in which they will be called are identical. See url_request.h
33 // for more information.
34 class CONTENT_EXPORT RequestPeer
{
36 // Called as upload progress is made.
37 // note: only for requests with upload progress enabled.
38 virtual void OnUploadProgress(uint64 position
, uint64 size
) = 0;
40 // Called when a redirect occurs. The implementation may return false to
41 // suppress the redirect. The ResourceResponseInfo provides information about
42 // the redirect response and the RedirectInfo includes information about the
43 // request to be made if the method returns true.
44 virtual bool OnReceivedRedirect(const net::RedirectInfo
& redirect_info
,
45 const ResourceResponseInfo
& info
) = 0;
47 // Called when response headers are available (after all redirects have
49 virtual void OnReceivedResponse(const ResourceResponseInfo
& info
) = 0;
51 // Called when a chunk of response data is downloaded. This method may be
52 // called multiple times or not at all if an error occurs. This method is
53 // only called if RequestInfo::download_to_file was set to true, and in
54 // that case, OnReceivedData will not be called.
55 // The encoded_data_length is the length of the encoded data transferred
56 // over the network, which could be different from data length (e.g. for
58 virtual void OnDownloadedData(int len
, int encoded_data_length
) = 0;
60 // Called when a chunk of response data is available. This method may
61 // be called multiple times or not at all if an error occurs.
62 // The encoded_data_length is the length of the encoded data transferred
63 // over the network, which could be different from data length (e.g. for
65 virtual void OnReceivedData(const char* data
,
67 int encoded_data_length
) = 0;
69 // Called when metadata generated by the renderer is retrieved from the
70 // cache. This method may be called zero or one times.
71 virtual void OnReceivedCachedMetadata(const char* data
, int len
) {}
73 // Called when the response is complete. This method signals completion of
75 virtual void OnCompletedRequest(int error_code
,
76 bool was_ignored_by_handler
,
77 bool stale_copy_in_cache
,
78 const std::string
& security_info
,
79 const base::TimeTicks
& completion_time
,
80 int64 total_transfer_size
) = 0;
83 virtual ~RequestPeer() {}
86 } // namespace content
88 #endif // CONTENT_PUBLIC_CHILD_REQUEST_PEER_H_