Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(215)

Side by Side Diff: net/cert/cert_net_fetcher.h

Issue 2595723002: Allow CertNetFetcher to be shutdown from the network thread (Closed)
Patch Set: tweak comments Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_CERT_CERT_NET_FETCHER_H_ 5 #ifndef NET_CERT_CERT_NET_FETCHER_H_
6 #define NET_CERT_CERT_NET_FETCHER_H_ 6 #define NET_CERT_CERT_NET_FETCHER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "net/base/net_errors.h" 15 #include "net/base/net_errors.h"
16 #include "net/base/net_export.h" 16 #include "net/base/net_export.h"
17 17
18 class GURL; 18 class GURL;
19 19
20 namespace net { 20 namespace net {
21 21
22 // CertNetFetcher is a synchronous interface for fetching AIA URLs and CRL 22 // CertNetFetcher is a synchronous interface for fetching AIA URLs and CRL
23 // URLs. 23 // URLs. It is shared between a caller thread (which starts and waits for
24 // fetches), and a network thread (which does the actual fetches). It can be
25 // shutdown from the network thread to cancel outstanding requests.
24 // 26 //
25 // A Request object is returned when starting a fetch. The consumer can 27 // A Request object is returned when starting a fetch. The consumer can
26 // use this as a handle for aborting the request (by freeing it), or reading 28 // use this as a handle for aborting the request (by freeing it), or reading
27 // the result of the request (WaitForResult) 29 // the result of the request (WaitForResult)
28 // 30 class NET_EXPORT CertNetFetcher
29 // This interface is expected to be operated from a single thread. 31 : public base::RefCountedThreadSafe<CertNetFetcher> {
30 //
31 // The CertNetFetcher must outlive all Request objects it creates.
32 class NET_EXPORT CertNetFetcher {
33 public: 32 public:
34 class Request { 33 class Request {
35 public: 34 public:
36 virtual ~Request() {} 35 virtual ~Request() {}
37 36
38 // WaitForResult() can be called at most once. 37 // WaitForResult() can be called at most once.
39 // 38 //
40 // It will block and wait for the (network) request to complete, and 39 // It will block and wait for the (network) request to complete, and
41 // then write the result into the provided out-parameters. 40 // then write the result into the provided out-parameters.
42 virtual void WaitForResult(Error* error, std::vector<uint8_t>* bytes) = 0; 41 virtual void WaitForResult(Error* error, std::vector<uint8_t>* bytes) = 0;
43 }; 42 };
44 43
45 // This value can be used in place of timeout or max size limits. 44 // This value can be used in place of timeout or max size limits.
46 enum { DEFAULT = -1 }; 45 enum { DEFAULT = -1 };
47 46
48 CertNetFetcher() {} 47 CertNetFetcher() {}
49 48
50 virtual ~CertNetFetcher() {} 49 // Shuts down the CertNetFetcher and cancels outstanding requests.
eroman 2017/01/03 20:42:37 Please document what the expectation is for outsta
estark 2017/01/05 19:08:39 Done. We can't guarantee the completion of request
50 virtual void Shutdown() = 0;
51 51
52 // The Fetch*() methods start a request which can be cancelled by 52 // The Fetch*() methods start a request which can be cancelled by
53 // deleting the returned Request. Here is the meaning of the common 53 // deleting the returned Request. Here is the meaning of the common
54 // parameters: 54 // parameters:
55 // 55 //
56 // * url -- The http:// URL to fetch. 56 // * url -- The http:// URL to fetch.
57 // * timeout_seconds -- The maximum allowed duration for the fetch job. If 57 // * timeout_seconds -- The maximum allowed duration for the fetch job. If
58 // this delay is exceeded then the request will fail. To use a default 58 // this delay is exceeded then the request will fail. To use a default
59 // timeout pass DEFAULT. 59 // timeout pass DEFAULT.
60 // * max_response_bytes -- The maximum size of the response body. If this 60 // * max_response_bytes -- The maximum size of the response body. If this
61 // size is exceeded then the request will fail. To use a default timeout 61 // size is exceeded then the request will fail. To use a default timeout
62 // pass DEFAULT. 62 // pass DEFAULT.
63 //
64 // These methods may return nullptr if a request couldn't be started,
eroman 2017/01/03 20:42:37 I am not sure this is the best interface. Because
estark 2017/01/05 19:08:39 Done. Now if the fetcher has already been shutdown
65 // e.g. because the fetcher has already been shutdown.
63 66
64 virtual WARN_UNUSED_RESULT std::unique_ptr<Request> FetchCaIssuers( 67 virtual WARN_UNUSED_RESULT std::unique_ptr<Request> FetchCaIssuers(
65 const GURL& url, 68 const GURL& url,
66 int timeout_milliseconds, 69 int timeout_milliseconds,
67 int max_response_bytes) = 0; 70 int max_response_bytes) = 0;
68 71
69 virtual WARN_UNUSED_RESULT std::unique_ptr<Request> FetchCrl( 72 virtual WARN_UNUSED_RESULT std::unique_ptr<Request> FetchCrl(
70 const GURL& url, 73 const GURL& url,
71 int timeout_milliseconds, 74 int timeout_milliseconds,
72 int max_response_bytes) = 0; 75 int max_response_bytes) = 0;
73 76
74 virtual WARN_UNUSED_RESULT std::unique_ptr<Request> FetchOcsp( 77 virtual WARN_UNUSED_RESULT std::unique_ptr<Request> FetchOcsp(
75 const GURL& url, 78 const GURL& url,
76 int timeout_milliseconds, 79 int timeout_milliseconds,
77 int max_response_bytes) = 0; 80 int max_response_bytes) = 0;
78 81
82 protected:
83 virtual ~CertNetFetcher() {}
84
79 private: 85 private:
86 friend class base::RefCountedThreadSafe<CertNetFetcher>;
80 DISALLOW_COPY_AND_ASSIGN(CertNetFetcher); 87 DISALLOW_COPY_AND_ASSIGN(CertNetFetcher);
81 }; 88 };
82 89
83 } // namespace net 90 } // namespace net
84 91
85 #endif // NET_CERT_CERT_NET_FETCHER_H_ 92 #endif // NET_CERT_CERT_NET_FETCHER_H_
OLDNEW
« no previous file with comments | « no previous file | net/cert/internal/cert_issuer_source_aia.cc » ('j') | net/cert/internal/cert_issuer_source_aia.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698