OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef NET_BASE_NETWORK_DELEGATE_H_ | 5 #ifndef NET_BASE_NETWORK_DELEGATE_H_ |
6 #define NET_BASE_NETWORK_DELEGATE_H_ | 6 #define NET_BASE_NETWORK_DELEGATE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/threading/non_thread_safe.h" | 9 #include "base/threading/non_thread_safe.h" |
10 #include "net/base/completion_callback.h" | 10 #include "net/base/completion_callback.h" |
(...skipping 13 matching lines...) Expand all Loading... | |
24 class HttpRequestHeaders; | 24 class HttpRequestHeaders; |
25 class URLRequest; | 25 class URLRequest; |
26 class URLRequestJob; | 26 class URLRequestJob; |
27 | 27 |
28 class NetworkDelegate : public base::NonThreadSafe { | 28 class NetworkDelegate : public base::NonThreadSafe { |
29 public: | 29 public: |
30 virtual ~NetworkDelegate() {} | 30 virtual ~NetworkDelegate() {} |
31 | 31 |
32 // Notification interface called by the network stack. Note that these | 32 // Notification interface called by the network stack. Note that these |
33 // functions mostly forward to the private virtuals. They also add some sanity | 33 // functions mostly forward to the private virtuals. They also add some sanity |
34 // checking on parameters. | 34 // checking on parameters. See the corresponding virtuals for explanations of |
35 bool NotifyBeforeURLRequest(URLRequest* request, | 35 // the methods and their arguments. |
36 int NotifyBeforeURLRequest(URLRequest* request, | |
37 CompletionCallback* callback); | |
38 int NotifyBeforeSendHeaders(uint64 request_id, | |
39 HttpRequestHeaders* headers, | |
36 CompletionCallback* callback); | 40 CompletionCallback* callback); |
37 void NotifySendHttpRequest(HttpRequestHeaders* headers); | |
38 void NotifyResponseStarted(URLRequest* request); | 41 void NotifyResponseStarted(URLRequest* request); |
39 void NotifyReadCompleted(URLRequest* request, int bytes_read); | 42 void NotifyReadCompleted(URLRequest* request, int bytes_read); |
43 void NotifyURLRequestDestroyed(URLRequest* request); | |
40 | 44 |
41 // Returns a URLRequestJob that will be used to handle the request if | 45 // Returns a URLRequestJob that will be used to handle the request if |
42 // non-null. | 46 // non-null. |
43 // TODO(koz): Currently this is called inside registered ProtocolFactories, | 47 // TODO(koz): Currently this is called inside registered ProtocolFactories, |
44 // so that we can perform Delegate-dependent request handling from the static | 48 // so that we can perform Delegate-dependent request handling from the static |
45 // factories, but ultimately it should be called directly from | 49 // factories, but ultimately it should be called directly from |
46 // URLRequestJobManager::CreateJob() as a general override mechanism. | 50 // URLRequestJobManager::CreateJob() as a general override mechanism. |
47 URLRequestJob* MaybeCreateURLRequestJob(URLRequest* request); | 51 URLRequestJob* MaybeCreateURLRequestJob(URLRequest* request); |
48 | 52 |
49 private: | 53 private: |
50 // This is the interface for subclasses of NetworkDelegate to implement. This | 54 // This is the interface for subclasses of NetworkDelegate to implement. This |
51 // member functions will be called by the respective public notification | 55 // member functions will be called by the respective public notification |
52 // member function, which will perform basic sanity checking. | 56 // member function, which will perform basic sanity checking. |
53 | 57 |
54 // Called before a request is sent. | 58 // Called before a request is sent. The callback can be called at any time, |
55 virtual bool OnBeforeURLRequest(URLRequest* request, | 59 // but will have no effect if the request has already been cancelled or |
60 // deleted. Returns a net status code, generally either OK to continue with | |
61 // the request or ERR_IO_PENDING if the result is not ready yet. | |
62 virtual int OnBeforeURLRequest(URLRequest* request, | |
63 CompletionCallback* callback) = 0; | |
64 | |
65 // Called right before the HTTP headers are sent. Allows the delegate to | |
66 // read/write |headers| before they get sent out. The callback can be called | |
67 // at any time, but will have no effect if the transaction handling this | |
68 // request has been cancelled. Returns a net status code. | |
69 virtual int OnBeforeSendHeaders(uint64 request_id, | |
70 HttpRequestHeaders* headers, | |
56 CompletionCallback* callback) = 0; | 71 CompletionCallback* callback) = 0; |
57 | 72 |
58 // Called right before the HTTP headers are sent. Allows the delegate to | |
59 // read/write |headers| before they get sent out. | |
60 virtual void OnSendHttpRequest(HttpRequestHeaders* headers) = 0; | |
61 | |
62 // This corresponds to URLRequestDelegate::OnResponseStarted. | 73 // This corresponds to URLRequestDelegate::OnResponseStarted. |
63 virtual void OnResponseStarted(URLRequest* request) = 0; | 74 virtual void OnResponseStarted(URLRequest* request) = 0; |
64 | 75 |
65 // This corresponds to URLRequestDelegate::OnReadCompleted. | 76 // This corresponds to URLRequestDelegate::OnReadCompleted. |
66 virtual void OnReadCompleted(URLRequest* request, int bytes_read) = 0; | 77 virtual void OnReadCompleted(URLRequest* request, int bytes_read) = 0; |
67 | 78 |
79 // Called when an URLRequest is being destroyed. | |
willchan no longer on Chromium
2011/03/26 01:46:49
Please note that we're already in the destructor,
Matt Perry
2011/03/28 22:51:01
Added a comment. (calling accessors is fine, just
| |
80 virtual void OnURLRequestDestroyed(URLRequest* request) = 0; | |
81 | |
68 // Called before a request is sent and before a URLRequestJob is created to | 82 // Called before a request is sent and before a URLRequestJob is created to |
69 // handle the request. | 83 // handle the request. |
70 virtual URLRequestJob* OnMaybeCreateURLRequestJob(URLRequest* request) = 0; | 84 virtual URLRequestJob* OnMaybeCreateURLRequestJob(URLRequest* request) = 0; |
85 | |
71 }; | 86 }; |
72 | 87 |
73 } // namespace net | 88 } // namespace net |
74 | 89 |
75 #endif // NET_BASE_NETWORK_DELEGATE_H_ | 90 #endif // NET_BASE_NETWORK_DELEGATE_H_ |
OLD | NEW |