OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 CONTENT_BROWSER_SSL_SSL_ERROR_HANDLER_H_ | 5 #ifndef CONTENT_BROWSER_SSL_SSL_ERROR_HANDLER_H_ |
6 #define CONTENT_BROWSER_SSL_SSL_ERROR_HANDLER_H_ | 6 #define CONTENT_BROWSER_SSL_SSL_ERROR_HANDLER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "content/browser/ssl/ssl_manager.h" | |
14 #include "content/common/content_export.h" | 13 #include "content/common/content_export.h" |
15 #include "content/public/browser/global_request_id.h" | 14 #include "content/public/browser/global_request_id.h" |
16 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
17 #include "webkit/glue/resource_type.h" | 16 #include "webkit/glue/resource_type.h" |
18 | 17 |
19 class ResourceDispatcherHost; | |
20 class SSLCertErrorHandler; | 18 class SSLCertErrorHandler; |
19 class SSLManager; | |
21 | 20 |
22 namespace net { | 21 namespace net { |
22 class SSLInfo; | |
23 class URLRequest; | 23 class URLRequest; |
24 } // namespace net | 24 } // namespace net |
25 | 25 |
26 // An SSLErrorHandler carries information from the IO thread to the UI thread | 26 // An SSLErrorHandler carries information from the IO thread to the UI thread |
27 // and is dispatched to the appropriate SSLManager when it arrives on the | 27 // and is dispatched to the appropriate SSLManager when it arrives on the |
28 // UI thread. Subclasses should override the OnDispatched/OnDispatchFailed | 28 // UI thread. Subclasses should override the OnDispatched/OnDispatchFailed |
29 // methods to implement the actions that should be taken on the UI thread. | 29 // methods to implement the actions that should be taken on the UI thread. |
30 // These methods can call the different convenience methods ContinueRequest/ | 30 // These methods can call the different convenience methods ContinueRequest/ |
31 // CancelRequest to perform any required action on the net::URLRequest the | 31 // CancelRequest to perform any required action on the net::URLRequest the |
32 // ErrorHandler was created with. | 32 // ErrorHandler was created with. |
33 // | 33 // |
34 // IMPORTANT NOTE: | 34 // IMPORTANT NOTE: |
35 // | 35 // |
36 // If you are not doing anything in OnDispatched/OnDispatchFailed, make sure | 36 // If you are not doing anything in OnDispatched/OnDispatchFailed, make sure |
37 // you call TakeNoAction(). This is necessary for ensuring the instance is | 37 // you call TakeNoAction(). This is necessary for ensuring the instance is |
38 // not leaked. | 38 // not leaked. |
39 // | 39 // |
40 class SSLErrorHandler : public base::RefCountedThreadSafe<SSLErrorHandler> { | 40 class SSLErrorHandler : public base::RefCountedThreadSafe<SSLErrorHandler> { |
41 public: | 41 public: |
42 typedef std::pair<int, int> instance_id; | |
wtc
2012/02/22 00:36:23
instance_id doesn't meet the requirement of the St
Takashi Toyoshima
2012/02/22 08:15:35
Thanks.
I decide to use content::GlobalRequestID i
| |
43 // Delegate functions must be called from IO thread. | |
44 class Delegate { | |
45 public: | |
46 virtual ResourceType::Type ResourceTypeForInstance( | |
47 const instance_id& id) = 0; | |
48 virtual const GURL& URLForInstance(const instance_id& id) = 0; | |
49 virtual bool RenderViewForInstance(const instance_id& id, | |
50 int* render_process_host_id, | |
51 int* render_view_host_id) = 0; | |
52 virtual void CancelRequestForInstance(const instance_id& id, | |
53 int error, | |
54 const net::SSLInfo* ssl_info) = 0; | |
55 virtual void ContinueRequestForInstance(const instance_id& id) = 0; | |
wtc
2012/02/22 00:36:23
Please document the Delegate class and its methods
Takashi Toyoshima
2012/02/22 08:15:35
Done.
| |
56 }; | |
42 virtual SSLCertErrorHandler* AsSSLCertErrorHandler(); | 57 virtual SSLCertErrorHandler* AsSSLCertErrorHandler(); |
43 | 58 |
44 // Find the appropriate SSLManager for the net::URLRequest and begin handling | 59 // Find the appropriate SSLManager for the net::URLRequest and begin handling |
45 // this error. | 60 // this error. |
46 // | 61 // |
47 // Call on UI thread. | 62 // Call on UI thread. |
48 void Dispatch(); | 63 void Dispatch(); |
49 | 64 |
50 // Available on either thread. | 65 // Available on either thread. |
51 const GURL& request_url() const { return request_url_; } | 66 const GURL& request_url() const { return request_url_; } |
(...skipping 24 matching lines...) Expand all Loading... | |
76 // call this. | 91 // call this. |
77 void TakeNoAction(); | 92 void TakeNoAction(); |
78 | 93 |
79 int render_process_id() const { return render_process_id_; } | 94 int render_process_id() const { return render_process_id_; } |
80 int render_view_id() const { return render_view_id_; } | 95 int render_view_id() const { return render_view_id_; } |
81 | 96 |
82 protected: | 97 protected: |
83 friend class base::RefCountedThreadSafe<SSLErrorHandler>; | 98 friend class base::RefCountedThreadSafe<SSLErrorHandler>; |
84 | 99 |
85 // Construct on the IO thread. | 100 // Construct on the IO thread. |
86 SSLErrorHandler(ResourceDispatcherHost* resource_dispatcher_host, | 101 SSLErrorHandler(Delegate* delegate, |
87 net::URLRequest* request, | 102 instance_id id); |
88 ResourceType::Type resource_type); | |
89 | 103 |
90 virtual ~SSLErrorHandler(); | 104 virtual ~SSLErrorHandler(); |
91 | 105 |
92 // The following 2 methods are the methods subclasses should implement. | 106 // The following 2 methods are the methods subclasses should implement. |
93 virtual void OnDispatchFailed(); | 107 virtual void OnDispatchFailed(); |
94 | 108 |
95 // Can use the manager_ member. | 109 // Can use the manager_ member. |
96 virtual void OnDispatched(); | 110 virtual void OnDispatched(); |
97 | 111 |
98 // Should only be accessed on the UI thread. | 112 // Should only be accessed on the UI thread. |
99 SSLManager* manager_; // Our manager. | 113 SSLManager* manager_; // Our manager. |
100 | 114 |
101 // The id of the net::URLRequest associated with this object. | 115 // The id of the request associated with this object. |
wtc
2012/02/22 00:36:23
Perhaps this member (and its type) should be named
Takashi Toyoshima
2012/02/22 08:15:35
OK, I stick to the original request_id_.
| |
102 // Should only be accessed from the IO thread. | 116 // Should only be accessed from the IO thread. |
103 content::GlobalRequestID request_id_; | 117 instance_id instance_id_; |
104 | 118 |
105 // The ResourceDispatcherHost we are associated with. | 119 // The delegate we are associated with. |
106 ResourceDispatcherHost* resource_dispatcher_host_; | 120 Delegate* delegate_; |
107 | 121 |
108 private: | 122 private: |
109 // Completes the CancelRequest operation on the IO thread. | 123 // Completes the CancelRequest operation on the IO thread. |
110 // Call on the IO thread. | 124 // Call on the IO thread. |
111 void CompleteCancelRequest(int error); | 125 void CompleteCancelRequest(int error); |
112 | 126 |
113 // Completes the ContinueRequest operation on the IO thread. | 127 // Completes the ContinueRequest operation on the IO thread. |
114 // | 128 // |
115 // Call on the IO thread. | 129 // Call on the IO thread. |
116 void CompleteContinueRequest(); | 130 void CompleteContinueRequest(); |
(...skipping 17 matching lines...) Expand all Loading... | |
134 const ResourceType::Type resource_type_; | 148 const ResourceType::Type resource_type_; |
135 | 149 |
136 // A flag to make sure we notify the net::URLRequest exactly once. | 150 // A flag to make sure we notify the net::URLRequest exactly once. |
137 // Should only be accessed on the IO thread | 151 // Should only be accessed on the IO thread |
138 bool request_has_been_notified_; | 152 bool request_has_been_notified_; |
139 | 153 |
140 DISALLOW_COPY_AND_ASSIGN(SSLErrorHandler); | 154 DISALLOW_COPY_AND_ASSIGN(SSLErrorHandler); |
141 }; | 155 }; |
142 | 156 |
143 #endif // CONTENT_BROWSER_SSL_SSL_ERROR_HANDLER_H_ | 157 #endif // CONTENT_BROWSER_SSL_SSL_ERROR_HANDLER_H_ |
OLD | NEW |