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

Side by Side Diff: net/ssl/channel_id_service.h

Issue 1149083013: Combine ChannelIDService::RequestHandle and ChannelIDServiceRequest classes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix order of variables Created 5 years, 6 months 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 2014 The Chromium Authors. All rights reserved. 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 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_SSL_CHANNEL_ID_SERVICE_H_ 5 #ifndef NET_SSL_CHANNEL_ID_SERVICE_H_
6 #define NET_SSL_CHANNEL_ID_SERVICE_H_ 6 #define NET_SSL_CHANNEL_ID_SERVICE_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 11 matching lines...) Expand all
22 class TaskRunner; 22 class TaskRunner;
23 } // namespace base 23 } // namespace base
24 24
25 namespace crypto { 25 namespace crypto {
26 class ECPrivateKey; 26 class ECPrivateKey;
27 } // namespace crypto 27 } // namespace crypto
28 28
29 namespace net { 29 namespace net {
30 30
31 class ChannelIDServiceJob; 31 class ChannelIDServiceJob;
32 class ChannelIDServiceRequest;
33 class ChannelIDServiceWorker; 32 class ChannelIDServiceWorker;
34 33
35 // A class for creating and fetching Channel IDs. 34 // A class for creating and fetching Channel IDs.
36 35
37 // Inherits from NonThreadSafe in order to use the function 36 // Inherits from NonThreadSafe in order to use the function
38 // |CalledOnValidThread|. 37 // |CalledOnValidThread|.
39 class NET_EXPORT ChannelIDService 38 class NET_EXPORT ChannelIDService
40 : NON_EXPORTED_BASE(public base::NonThreadSafe) { 39 : NON_EXPORTED_BASE(public base::NonThreadSafe) {
41 public: 40 public:
42 class NET_EXPORT RequestHandle { 41 class NET_EXPORT Request {
43 public: 42 public:
44 RequestHandle(); 43 Request();
45 ~RequestHandle(); 44 ~Request();
46 45
47 // Cancel the request. Does nothing if the request finished or was already 46 // Cancel the request. Does nothing if the request finished or was already
48 // cancelled. 47 // cancelled.
49 void Cancel(); 48 void Cancel();
50 49
51 bool is_active() const { return request_ != NULL; } 50 bool is_active() const { return !callback_.is_null(); }
52 51
53 private: 52 private:
54 friend class ChannelIDService; 53 friend class ChannelIDService;
54 friend class ChannelIDServiceJob;
55 55
56 void RequestStarted(ChannelIDService* service, 56 void RequestStarted(ChannelIDService* service,
57 ChannelIDServiceRequest* request, 57 base::TimeTicks request_start,
58 const CompletionCallback& callback); 58 const CompletionCallback& callback,
59 scoped_ptr<crypto::ECPrivateKey>* key);
59 60
60 void OnRequestComplete(int result); 61 void Post(int error, scoped_ptr<crypto::ECPrivateKey> key);
61 62
62 ChannelIDService* service_; 63 ChannelIDService* service_;
63 ChannelIDServiceRequest* request_; 64 base::TimeTicks request_start_;
64 CompletionCallback callback_; 65 CompletionCallback callback_;
66 scoped_ptr<crypto::ECPrivateKey>* key_;
65 }; 67 };
66 68
67 // Password used on EncryptedPrivateKeyInfo data stored in EC private_key 69 // Password used on EncryptedPrivateKeyInfo data stored in EC private_key
68 // values. (This is not used to provide any security, but to workaround NSS 70 // values. (This is not used to provide any security, but to workaround NSS
69 // being unable to import unencrypted PrivateKeyInfo for EC keys.) 71 // being unable to import unencrypted PrivateKeyInfo for EC keys.)
70 static const char kEPKIPassword[]; 72 static const char kEPKIPassword[];
71 73
72 // This object owns |channel_id_store|. |task_runner| will 74 // This object owns |channel_id_store|. |task_runner| will
73 // be used to post channel ID generation worker tasks. The tasks are 75 // be used to post channel ID generation worker tasks. The tasks are
74 // safe for use with WorkerPool and SequencedWorkerPool::CONTINUE_ON_SHUTDOWN. 76 // safe for use with WorkerPool and SequencedWorkerPool::CONTINUE_ON_SHUTDOWN.
(...skipping 12 matching lines...) Expand all
87 // creates one otherwise. Returns OK if successful or an error code upon 89 // creates one otherwise. Returns OK if successful or an error code upon
88 // failure. 90 // failure.
89 // 91 //
90 // On successful completion, |key| holds the ECDSA keypair used for this 92 // On successful completion, |key| holds the ECDSA keypair used for this
91 // channel ID. 93 // channel ID.
92 // 94 //
93 // |callback| must not be null. ERR_IO_PENDING is returned if the operation 95 // |callback| must not be null. ERR_IO_PENDING is returned if the operation
94 // could not be completed immediately, in which case the result code will 96 // could not be completed immediately, in which case the result code will
95 // be passed to the callback when available. 97 // be passed to the callback when available.
96 // 98 //
97 // |*out_req| will be initialized with a handle to the async request. This 99 // |*out_req| will be initialized with a handle to the async request.
98 // RequestHandle object must be cancelled or destroyed before the
99 // ChannelIDService is destroyed.
100 int GetOrCreateChannelID(const std::string& host, 100 int GetOrCreateChannelID(const std::string& host,
101 scoped_ptr<crypto::ECPrivateKey>* key, 101 scoped_ptr<crypto::ECPrivateKey>* key,
102 const CompletionCallback& callback, 102 const CompletionCallback& callback,
103 RequestHandle* out_req); 103 Request* out_req);
104 104
105 // Fetches the channel ID for the specified host if one exists. 105 // Fetches the channel ID for the specified host if one exists.
106 // Returns OK if successful, ERR_FILE_NOT_FOUND if none exists, or an error 106 // Returns OK if successful, ERR_FILE_NOT_FOUND if none exists, or an error
107 // code upon failure. 107 // code upon failure.
108 // 108 //
109 // On successful completion, |key| holds the ECDSA keypair used for this 109 // On successful completion, |key| holds the ECDSA keypair used for this
110 // channel ID. 110 // channel ID.
111 // 111 //
112 // |callback| must not be null. ERR_IO_PENDING is returned if the operation 112 // |callback| must not be null. ERR_IO_PENDING is returned if the operation
113 // could not be completed immediately, in which case the result code will 113 // could not be completed immediately, in which case the result code will
114 // be passed to the callback when available. If an in-flight 114 // be passed to the callback when available. If an in-flight
115 // GetChannelID is pending, and a new GetOrCreateChannelID 115 // GetChannelID is pending, and a new GetOrCreateChannelID
116 // request arrives for the same domain, the GetChannelID request will 116 // request arrives for the same domain, the GetChannelID request will
117 // not complete until a new channel ID is created. 117 // not complete until a new channel ID is created.
118 // 118 //
119 // |*out_req| will be initialized with a handle to the async request. This 119 // |*out_req| will be initialized with a handle to the async request.
120 // RequestHandle object must be cancelled or destroyed before the
121 // ChannelIDService is destroyed.
122 int GetChannelID(const std::string& host, 120 int GetChannelID(const std::string& host,
123 scoped_ptr<crypto::ECPrivateKey>* key, 121 scoped_ptr<crypto::ECPrivateKey>* key,
124 const CompletionCallback& callback, 122 const CompletionCallback& callback,
125 RequestHandle* out_req); 123 Request* out_req);
126 124
127 // Returns the backing ChannelIDStore. 125 // Returns the backing ChannelIDStore.
128 ChannelIDStore* GetChannelIDStore(); 126 ChannelIDStore* GetChannelIDStore();
129 127
130 // Public only for unit testing. 128 // Public only for unit testing.
131 int channel_id_count(); 129 int channel_id_count();
132 uint64 requests() const { return requests_; } 130 uint64 requests() const { return requests_; }
133 uint64 key_store_hits() const { return key_store_hits_; } 131 uint64 key_store_hits() const { return key_store_hits_; }
134 uint64 inflight_joins() const { return inflight_joins_; } 132 uint64 inflight_joins() const { return inflight_joins_; }
135 uint64 workers_created() const { return workers_created_; } 133 uint64 workers_created() const { return workers_created_; }
136 134
137 private: 135 private:
138 // Cancels the specified request. |req| is the handle stored by 136 // Cancels the specified request. |req| is the handle stored by
139 // GetChannelID(). After a request is canceled, its completion 137 // GetChannelID(). After a request is canceled, its completion
140 // callback will not be called. 138 // callback will not be called.
141 void CancelRequest(ChannelIDServiceRequest* req); 139 void CancelRequest(Request* req);
142 140
143 void GotChannelID(int err, 141 void GotChannelID(int err,
144 const std::string& server_identifier, 142 const std::string& server_identifier,
145 scoped_ptr<crypto::ECPrivateKey> key); 143 scoped_ptr<crypto::ECPrivateKey> key);
146 void GeneratedChannelID( 144 void GeneratedChannelID(
147 const std::string& server_identifier, 145 const std::string& server_identifier,
148 int error, 146 int error,
149 scoped_ptr<ChannelIDStore::ChannelID> channel_id); 147 scoped_ptr<ChannelIDStore::ChannelID> channel_id);
150 void HandleResult(int error, 148 void HandleResult(int error,
151 const std::string& server_identifier, 149 const std::string& server_identifier,
152 scoped_ptr<crypto::ECPrivateKey> key); 150 scoped_ptr<crypto::ECPrivateKey> key);
153 151
154 // Searches for an in-flight request for the same domain. If found, 152 // Searches for an in-flight request for the same domain. If found,
155 // attaches to the request and returns true. Returns false if no in-flight 153 // attaches to the request and returns true. Returns false if no in-flight
156 // request is found. 154 // request is found.
157 bool JoinToInFlightRequest(const base::TimeTicks& request_start, 155 bool JoinToInFlightRequest(const base::TimeTicks& request_start,
158 const std::string& domain, 156 const std::string& domain,
159 scoped_ptr<crypto::ECPrivateKey>* key, 157 scoped_ptr<crypto::ECPrivateKey>* key,
160 bool create_if_missing, 158 bool create_if_missing,
161 const CompletionCallback& callback, 159 const CompletionCallback& callback,
162 RequestHandle* out_req); 160 Request* out_req);
163 161
164 // Looks for the channel ID for |domain| in this service's store. 162 // Looks for the channel ID for |domain| in this service's store.
165 // Returns OK if it can be found synchronously, ERR_IO_PENDING if the 163 // Returns OK if it can be found synchronously, ERR_IO_PENDING if the
166 // result cannot be obtained synchronously, or a network error code on 164 // result cannot be obtained synchronously, or a network error code on
167 // failure (including failure to find a channel ID of |domain|). 165 // failure (including failure to find a channel ID of |domain|).
168 int LookupChannelID(const base::TimeTicks& request_start, 166 int LookupChannelID(const base::TimeTicks& request_start,
169 const std::string& domain, 167 const std::string& domain,
170 scoped_ptr<crypto::ECPrivateKey>* key, 168 scoped_ptr<crypto::ECPrivateKey>* key,
171 bool create_if_missing, 169 bool create_if_missing,
172 const CompletionCallback& callback, 170 const CompletionCallback& callback,
173 RequestHandle* out_req); 171 Request* out_req);
174 172
175 scoped_ptr<ChannelIDStore> channel_id_store_; 173 scoped_ptr<ChannelIDStore> channel_id_store_;
176 scoped_refptr<base::TaskRunner> task_runner_; 174 scoped_refptr<base::TaskRunner> task_runner_;
177 175
178 // inflight_ maps from a server to an active generation which is taking 176 // inflight_ maps from a server to an active generation which is taking
179 // place. 177 // place.
180 std::map<std::string, ChannelIDServiceJob*> inflight_; 178 std::map<std::string, ChannelIDServiceJob*> inflight_;
181 179
182 uint64 requests_; 180 uint64 requests_;
183 uint64 key_store_hits_; 181 uint64 key_store_hits_;
184 uint64 inflight_joins_; 182 uint64 inflight_joins_;
185 uint64 workers_created_; 183 uint64 workers_created_;
186 184
187 base::WeakPtrFactory<ChannelIDService> weak_ptr_factory_; 185 base::WeakPtrFactory<ChannelIDService> weak_ptr_factory_;
188 186
189 DISALLOW_COPY_AND_ASSIGN(ChannelIDService); 187 DISALLOW_COPY_AND_ASSIGN(ChannelIDService);
190 }; 188 };
191 189
192 } // namespace net 190 } // namespace net
193 191
194 #endif // NET_SSL_CHANNEL_ID_SERVICE_H_ 192 #endif // NET_SSL_CHANNEL_ID_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698