Update V8 to version 4.6.61.
[chromium-blink-merge.git] / content / public / child / request_peer.h
blobed09c925d644f380bd339167c6ef699d7a0aa3e6
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_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "content/common/content_export.h"
14 class GURL;
16 namespace base {
17 class TimeTicks;
20 namespace net {
21 struct RedirectInfo;
24 namespace content {
26 struct ResourceResponseInfo;
28 // This is implemented by our custom resource loader within content. The Peer
29 // and it's bridge should have identical lifetimes as they represent each end of
30 // a communication channel.
32 // These callbacks mirror net::URLRequest::Delegate and the order and
33 // conditions in which they will be called are identical. See url_request.h
34 // for more information.
35 class CONTENT_EXPORT RequestPeer {
36 public:
37 // This class represents data gotten from the Browser process. Each data
38 // consists of |payload|, |length| and |encoded_length|. The payload is
39 // valid only when the data instance is valid.
40 // In order to work with Chrome resource loading IPC, it is desirable to
41 // reclaim data in FIFO order in a RequestPeer in terms of performance.
42 // |payload|, |length| and |encoded_length| functions are thread-safe, but
43 // the data object itself must be destroyed on the original thread.
44 class CONTENT_EXPORT ReceivedData {
45 public:
46 virtual ~ReceivedData() {}
47 virtual const char* payload() const = 0;
48 virtual int length() const = 0;
49 // The encoded_length is the length of the encoded data transferred
50 // over the network, which could be different from data length (e.g. for
51 // gzipped content).
52 virtual int encoded_length() const = 0;
55 // A ThreadSafeReceivedData can be deleted on ANY thread.
56 class CONTENT_EXPORT ThreadSafeReceivedData : public ReceivedData {};
58 // Called as upload progress is made.
59 // note: only for requests with upload progress enabled.
60 virtual void OnUploadProgress(uint64 position, uint64 size) = 0;
62 // Called when a redirect occurs. The implementation may return false to
63 // suppress the redirect. The ResourceResponseInfo provides information about
64 // the redirect response and the RedirectInfo includes information about the
65 // request to be made if the method returns true.
66 virtual bool OnReceivedRedirect(const net::RedirectInfo& redirect_info,
67 const ResourceResponseInfo& info) = 0;
69 // Called when response headers are available (after all redirects have
70 // been followed).
71 virtual void OnReceivedResponse(const ResourceResponseInfo& info) = 0;
73 // Called when a chunk of response data is downloaded. This method may be
74 // called multiple times or not at all if an error occurs. This method is
75 // only called if RequestInfo::download_to_file was set to true, and in
76 // that case, OnReceivedData will not be called.
77 // The encoded_data_length is the length of the encoded data transferred
78 // over the network, which could be different from data length (e.g. for
79 // gzipped content).
80 virtual void OnDownloadedData(int len, int encoded_data_length) = 0;
82 // Called when a chunk of response data is available. This method may
83 // be called multiple times or not at all if an error occurs.
84 virtual void OnReceivedData(scoped_ptr<ReceivedData> data) = 0;
86 // Called when metadata generated by the renderer is retrieved from the
87 // cache. This method may be called zero or one times.
88 virtual void OnReceivedCachedMetadata(const char* data, int len) {}
90 // Called when the response is complete. This method signals completion of
91 // the resource load.
92 virtual void OnCompletedRequest(int error_code,
93 bool was_ignored_by_handler,
94 bool stale_copy_in_cache,
95 const std::string& security_info,
96 const base::TimeTicks& completion_time,
97 int64 total_transfer_size) = 0;
99 // This is a combined notification of
100 // - OnReceivedResponse,
101 // - OnReceivedData and
102 // - OnCompletedRequest.
103 // Unlike OnReceivedData, |data| can be null.
104 // This method is introduced to avoid repetitive method calls which might
105 // lead to use-after-free issues. See https://crbug.com/485413,
106 // https://crbug.com/507170.
107 // TODO(yhirano): Fix the RequestPeer lifecycle problem and remove this
108 // function.
109 virtual void OnReceivedCompletedResponse(
110 const ResourceResponseInfo& info,
111 scoped_ptr<ReceivedData> data,
112 int error_code,
113 bool was_ignored_by_handler,
114 bool stale_copy_in_cache,
115 const std::string& security_info,
116 const base::TimeTicks& completion_time,
117 int64 total_transfer_size) = 0;
119 protected:
120 virtual ~RequestPeer() {}
123 } // namespace content
125 #endif // CONTENT_PUBLIC_CHILD_REQUEST_PEER_H_