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

Side by Side Diff: net/http/disk_based_cert_cache.cc

Issue 465633003: Updates state order of DiskBasedCertCache::WriteWorker. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 #include "net/http/disk_based_cert_cache.h" 5 #include "net/http/disk_based_cert_cache.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 // WriteWorker finishes processing. 74 // WriteWorker finishes processing.
75 void AddCallback(const SetCallback& user_callback); 75 void AddCallback(const SetCallback& user_callback);
76 76
77 // Signals the WriteWorker to abort early. The WriteWorker will be destroyed 77 // Signals the WriteWorker to abort early. The WriteWorker will be destroyed
78 // upon the completion of any pending callbacks. User callbacks will be 78 // upon the completion of any pending callbacks. User callbacks will be
79 // invoked with an empty string. 79 // invoked with an empty string.
80 void Cancel(); 80 void Cancel();
81 81
82 private: 82 private:
83 enum State { 83 enum State {
84 STATE_OPEN,
85 STATE_OPEN_COMPLETE,
84 STATE_CREATE, 86 STATE_CREATE,
85 STATE_CREATE_COMPLETE, 87 STATE_CREATE_COMPLETE,
86 STATE_OPEN,
87 STATE_OPEN_COMPLETE,
88 STATE_WRITE, 88 STATE_WRITE,
89 STATE_WRITE_COMPLETE, 89 STATE_WRITE_COMPLETE,
90 STATE_NONE 90 STATE_NONE
91 }; 91 };
92 92
93 void OnIOComplete(int rv); 93 void OnIOComplete(int rv);
94 int DoLoop(int rv); 94 int DoLoop(int rv);
95 95
96 int DoOpen();
97 int DoOpenComplete(int rv);
96 int DoCreate(); 98 int DoCreate();
97 int DoCreateComplete(int rv); 99 int DoCreateComplete(int rv);
98 int DoOpen();
99 int DoOpenComplete(int rv);
100 int DoWrite(); 100 int DoWrite();
101 int DoWriteComplete(int rv); 101 int DoWriteComplete(int rv);
102 102
103 void Finish(int rv); 103 void Finish(int rv);
104 104
105 // Invokes all of the |user_callbacks_| 105 // Invokes all of the |user_callbacks_|
106 void RunCallbacks(int rv); 106 void RunCallbacks(int rv);
107 107
108 disk_cache::Backend* backend_; 108 disk_cache::Backend* backend_;
109 const X509Certificate::OSCertHandle cert_handle_; 109 const X509Certificate::OSCertHandle cert_handle_;
(...skipping 29 matching lines...) Expand all
139 139
140 DiskBasedCertCache::WriteWorker::~WriteWorker() { 140 DiskBasedCertCache::WriteWorker::~WriteWorker() {
141 if (cert_handle_) 141 if (cert_handle_)
142 X509Certificate::FreeOSCertHandle(cert_handle_); 142 X509Certificate::FreeOSCertHandle(cert_handle_);
143 if (entry_) 143 if (entry_)
144 entry_->Close(); 144 entry_->Close();
145 } 145 }
146 146
147 void DiskBasedCertCache::WriteWorker::Start() { 147 void DiskBasedCertCache::WriteWorker::Start() {
148 DCHECK_EQ(STATE_NONE, next_state_); 148 DCHECK_EQ(STATE_NONE, next_state_);
149 next_state_ = STATE_CREATE; 149
150 next_state_ = STATE_OPEN;
150 int rv = DoLoop(OK); 151 int rv = DoLoop(OK);
151 152
152 if (rv == ERR_IO_PENDING) 153 if (rv == ERR_IO_PENDING)
153 return; 154 return;
154 155
155 Finish(rv); 156 Finish(rv);
156 } 157 }
157 158
158 void DiskBasedCertCache::WriteWorker::AddCallback( 159 void DiskBasedCertCache::WriteWorker::AddCallback(
159 const SetCallback& user_callback) { 160 const SetCallback& user_callback) {
(...skipping 16 matching lines...) Expand all
176 return; 177 return;
177 178
178 Finish(rv); 179 Finish(rv);
179 } 180 }
180 181
181 int DiskBasedCertCache::WriteWorker::DoLoop(int rv) { 182 int DiskBasedCertCache::WriteWorker::DoLoop(int rv) {
182 do { 183 do {
183 State state = next_state_; 184 State state = next_state_;
184 next_state_ = STATE_NONE; 185 next_state_ = STATE_NONE;
185 switch (state) { 186 switch (state) {
187 case STATE_OPEN:
188 rv = DoOpen();
189 break;
190 case STATE_OPEN_COMPLETE:
191 rv = DoOpenComplete(rv);
192 break;
186 case STATE_CREATE: 193 case STATE_CREATE:
187 rv = DoCreate(); 194 rv = DoCreate();
188 break; 195 break;
189 case STATE_CREATE_COMPLETE: 196 case STATE_CREATE_COMPLETE:
190 rv = DoCreateComplete(rv); 197 rv = DoCreateComplete(rv);
191 break; 198 break;
192 case STATE_OPEN:
193 rv = DoOpen();
194 break;
195 case STATE_OPEN_COMPLETE:
196 rv = DoOpenComplete(rv);
197 break;
198 case STATE_WRITE: 199 case STATE_WRITE:
199 rv = DoWrite(); 200 rv = DoWrite();
200 break; 201 break;
201 case STATE_WRITE_COMPLETE: 202 case STATE_WRITE_COMPLETE:
202 rv = DoWriteComplete(rv); 203 rv = DoWriteComplete(rv);
203 break; 204 break;
204 case STATE_NONE: 205 case STATE_NONE:
205 NOTREACHED(); 206 NOTREACHED();
206 break; 207 break;
207 } 208 }
208 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); 209 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE);
209 210
210 return rv; 211 return rv;
211 } 212 }
212 213
213 int DiskBasedCertCache::WriteWorker::DoCreate() { 214 int DiskBasedCertCache::WriteWorker::DoOpen() {
214 next_state_ = STATE_CREATE_COMPLETE; 215 next_state_ = STATE_OPEN_COMPLETE;
215 216 return backend_->OpenEntry(key_, &entry_, io_callback_);
216 return backend_->CreateEntry(key_, &entry_, io_callback_);
217 } 217 }
218 218
219 int DiskBasedCertCache::WriteWorker::DoCreateComplete(int rv) { 219 int DiskBasedCertCache::WriteWorker::DoOpenComplete(int rv) {
220 // An error here usually signifies that the entry already exists. 220 // The entry doesn't exist yet, so we should create it.
221 // If this occurs, it is necessary to instead open the previously
222 // existing entry.
223 if (rv < 0) { 221 if (rv < 0) {
224 next_state_ = STATE_OPEN; 222 next_state_ = STATE_CREATE;
225 return OK; 223 return OK;
226 } 224 }
227 225
228 next_state_ = STATE_WRITE; 226 next_state_ = STATE_WRITE;
229 return OK; 227 return OK;
230 } 228 }
231 229
232 int DiskBasedCertCache::WriteWorker::DoOpen() { 230 int DiskBasedCertCache::WriteWorker::DoCreate() {
233 next_state_ = STATE_OPEN_COMPLETE; 231 next_state_ = STATE_CREATE_COMPLETE;
234 return backend_->OpenEntry(key_, &entry_, io_callback_); 232 return backend_->CreateEntry(key_, &entry_, io_callback_);
235 } 233 }
236 234
237 int DiskBasedCertCache::WriteWorker::DoOpenComplete(int rv) { 235 int DiskBasedCertCache::WriteWorker::DoCreateComplete(int rv) {
238 if (rv < 0) 236 if (rv < 0)
239 return rv; 237 return rv;
240 238
241 next_state_ = STATE_WRITE; 239 next_state_ = STATE_WRITE;
242 return OK; 240 return OK;
243 } 241 }
244 242
245 int DiskBasedCertCache::WriteWorker::DoWrite() { 243 int DiskBasedCertCache::WriteWorker::DoWrite() {
246 std::string write_data; 244 std::string write_data;
247 bool encoded = X509Certificate::GetDEREncoded(cert_handle_, &write_data); 245 bool encoded = X509Certificate::GetDEREncoded(cert_handle_, &write_data);
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 589
592 void DiskBasedCertCache::FinishedWriteOperation( 590 void DiskBasedCertCache::FinishedWriteOperation(
593 const std::string& key, 591 const std::string& key,
594 X509Certificate::OSCertHandle cert_handle) { 592 X509Certificate::OSCertHandle cert_handle) {
595 write_worker_map_.erase(key); 593 write_worker_map_.erase(key);
596 if (!key.empty()) 594 if (!key.empty())
597 mru_cert_cache_.Put(key, X509Certificate::DupOSCertHandle(cert_handle)); 595 mru_cert_cache_.Put(key, X509Certificate::DupOSCertHandle(cert_handle));
598 } 596 }
599 597
600 } // namespace net 598 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698