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

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

Issue 8670009: SSL Host info: Make sure that we can update certificate chains in (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 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 | Annotate | Revision Log
OLDNEW
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 #include "net/http/disk_cache_based_ssl_host_info.h" 5 #include "net/http/disk_cache_based_ssl_host_info.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "net/base/io_buffer.h" 9 #include "net/base/io_buffer.h"
10 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
(...skipping 26 matching lines...) Expand all
37 const std::string& hostname, 37 const std::string& hostname,
38 const SSLConfig& ssl_config, 38 const SSLConfig& ssl_config,
39 CertVerifier* cert_verifier, 39 CertVerifier* cert_verifier,
40 HttpCache* http_cache) 40 HttpCache* http_cache)
41 : SSLHostInfo(hostname, ssl_config, cert_verifier), 41 : SSLHostInfo(hostname, ssl_config, cert_verifier),
42 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 42 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
43 callback_(new CallbackImpl(weak_ptr_factory_.GetWeakPtr(), 43 callback_(new CallbackImpl(weak_ptr_factory_.GetWeakPtr(),
44 &DiskCacheBasedSSLHostInfo::OnIOComplete)), 44 &DiskCacheBasedSSLHostInfo::OnIOComplete)),
45 state_(GET_BACKEND), 45 state_(GET_BACKEND),
46 ready_(false), 46 ready_(false),
47 found_entry_(false),
47 hostname_(hostname), 48 hostname_(hostname),
48 http_cache_(http_cache), 49 http_cache_(http_cache),
49 backend_(NULL), 50 backend_(NULL),
50 entry_(NULL), 51 entry_(NULL),
51 user_callback_(NULL) { 52 user_callback_(NULL) {
52 } 53 }
53 54
54 void DiskCacheBasedSSLHostInfo::Start() { 55 void DiskCacheBasedSSLHostInfo::Start() {
55 DCHECK(CalledOnValidThread()); 56 DCHECK(CalledOnValidThread());
56 DCHECK_EQ(GET_BACKEND, state_); 57 DCHECK_EQ(GET_BACKEND, state_);
(...skipping 18 matching lines...) Expand all
75 DCHECK(state_ != GET_BACKEND); 76 DCHECK(state_ != GET_BACKEND);
76 77
77 DCHECK(new_data_.empty()); 78 DCHECK(new_data_.empty());
78 CHECK(ready_); 79 CHECK(ready_);
79 DCHECK(user_callback_ == NULL); 80 DCHECK(user_callback_ == NULL);
80 new_data_ = Serialize(); 81 new_data_ = Serialize();
81 82
82 if (!backend_) 83 if (!backend_)
83 return; 84 return;
84 85
85 state_ = CREATE; 86 state_ = CREATE_OR_OPEN;
86 DoLoop(OK); 87 DoLoop(OK);
87 } 88 }
88 89
89 DiskCacheBasedSSLHostInfo::~DiskCacheBasedSSLHostInfo() { 90 DiskCacheBasedSSLHostInfo::~DiskCacheBasedSSLHostInfo() {
90 DCHECK(!user_callback_); 91 DCHECK(!user_callback_);
91 if (entry_) 92 if (entry_)
92 entry_->Close(); 93 entry_->Close();
93 if (!IsCallbackPending()) 94 if (!IsCallbackPending())
94 delete callback_; 95 delete callback_;
95 } 96 }
(...skipping 29 matching lines...) Expand all
125 break; 126 break;
126 case READ: 127 case READ:
127 rv = DoRead(); 128 rv = DoRead();
128 break; 129 break;
129 case READ_COMPLETE: 130 case READ_COMPLETE:
130 rv = DoReadComplete(rv); 131 rv = DoReadComplete(rv);
131 break; 132 break;
132 case WAIT_FOR_DATA_READY_DONE: 133 case WAIT_FOR_DATA_READY_DONE:
133 rv = DoWaitForDataReadyDone(); 134 rv = DoWaitForDataReadyDone();
134 break; 135 break;
135 case CREATE: 136 case CREATE_OR_OPEN:
136 rv = DoCreate(); 137 rv = DoCreateOrOpen();
137 break; 138 break;
138 case CREATE_COMPLETE: 139 case CREATE_OR_OPEN_COMPLETE:
139 rv = DoCreateComplete(rv); 140 rv = DoCreateOrOpenComplete(rv);
140 break; 141 break;
141 case WRITE: 142 case WRITE:
142 rv = DoWrite(); 143 rv = DoWrite();
143 break; 144 break;
144 case WRITE_COMPLETE: 145 case WRITE_COMPLETE:
145 rv = DoWriteComplete(rv); 146 rv = DoWriteComplete(rv);
146 break; 147 break;
147 case SET_DONE: 148 case SET_DONE:
148 rv = DoSetDone(); 149 rv = DoSetDone();
149 break; 150 break;
(...skipping 13 matching lines...) Expand all
163 } else { 164 } else {
164 state_ = WAIT_FOR_DATA_READY_DONE; 165 state_ = WAIT_FOR_DATA_READY_DONE;
165 } 166 }
166 return OK; 167 return OK;
167 } 168 }
168 169
169 int DiskCacheBasedSSLHostInfo::DoOpenComplete(int rv) { 170 int DiskCacheBasedSSLHostInfo::DoOpenComplete(int rv) {
170 if (rv == OK) { 171 if (rv == OK) {
171 entry_ = callback_->entry(); 172 entry_ = callback_->entry();
172 state_ = READ; 173 state_ = READ;
174 found_entry_ = true;
173 } else { 175 } else {
174 state_ = WAIT_FOR_DATA_READY_DONE; 176 state_ = WAIT_FOR_DATA_READY_DONE;
175 } 177 }
176 178
177 return OK; 179 return OK;
178 } 180 }
179 181
180 int DiskCacheBasedSSLHostInfo::DoReadComplete(int rv) { 182 int DiskCacheBasedSSLHostInfo::DoReadComplete(int rv) {
181 if (rv > 0) 183 if (rv > 0)
182 data_.assign(read_buffer_->data(), rv); 184 data_.assign(read_buffer_->data(), rv);
183 185
184 state_ = WAIT_FOR_DATA_READY_DONE; 186 state_ = WAIT_FOR_DATA_READY_DONE;
185 return OK; 187 return OK;
186 } 188 }
187 189
188 int DiskCacheBasedSSLHostInfo::DoWriteComplete(int rv) { 190 int DiskCacheBasedSSLHostInfo::DoWriteComplete(int rv) {
189 state_ = SET_DONE; 191 state_ = SET_DONE;
190 return OK; 192 return OK;
191 } 193 }
192 194
193 int DiskCacheBasedSSLHostInfo::DoCreateComplete(int rv) { 195 int DiskCacheBasedSSLHostInfo::DoCreateOrOpenComplete(int rv) {
194 if (rv != OK) { 196 if (rv != OK) {
195 state_ = SET_DONE; 197 state_ = SET_DONE;
196 } else { 198 } else {
197 entry_ = callback_->entry(); 199 entry_ = callback_->entry();
198 state_ = WRITE; 200 state_ = WRITE;
199 } 201 }
200 return OK; 202 return OK;
201 } 203 }
202 204
203 int DiskCacheBasedSSLHostInfo::DoGetBackend() { 205 int DiskCacheBasedSSLHostInfo::DoGetBackend() {
(...skipping 21 matching lines...) Expand all
225 227
226 int DiskCacheBasedSSLHostInfo::DoWrite() { 228 int DiskCacheBasedSSLHostInfo::DoWrite() {
227 write_buffer_ = new IOBuffer(new_data_.size()); 229 write_buffer_ = new IOBuffer(new_data_.size());
228 memcpy(write_buffer_->data(), new_data_.data(), new_data_.size()); 230 memcpy(write_buffer_->data(), new_data_.data(), new_data_.size());
229 state_ = WRITE_COMPLETE; 231 state_ = WRITE_COMPLETE;
230 232
231 return entry_->WriteData(0 /* index */, 0 /* offset */, write_buffer_, 233 return entry_->WriteData(0 /* index */, 0 /* offset */, write_buffer_,
232 new_data_.size(), callback_, true /* truncate */); 234 new_data_.size(), callback_, true /* truncate */);
233 } 235 }
234 236
235 int DiskCacheBasedSSLHostInfo::DoCreate() { 237 int DiskCacheBasedSSLHostInfo::DoCreateOrOpen() {
236 DCHECK(entry_ == NULL); 238 DCHECK(entry_ == NULL);
237 state_ = CREATE_COMPLETE; 239 state_ = CREATE_OR_OPEN_COMPLETE;
240 if (found_entry_)
241 return backend_->OpenEntry(key(), callback_->entry_pointer(), callback_);
242
238 return backend_->CreateEntry(key(), callback_->entry_pointer(), callback_); 243 return backend_->CreateEntry(key(), callback_->entry_pointer(), callback_);
239 } 244 }
240 245
241 int DiskCacheBasedSSLHostInfo::DoWaitForDataReadyDone() { 246 int DiskCacheBasedSSLHostInfo::DoWaitForDataReadyDone() {
242 DCHECK(!ready_); 247 DCHECK(!ready_);
243 state_ = NONE; 248 state_ = NONE;
244 ready_ = true; 249 ready_ = true;
245 // We close the entry because, if we shutdown before ::Persist is called, 250 // We close the entry because, if we shutdown before ::Persist is called,
246 // then we might leak a cache reference, which causes a DCHECK on shutdown. 251 // then we might leak a cache reference, which causes a DCHECK on shutdown.
247 if (entry_) 252 if (entry_)
248 entry_->Close(); 253 entry_->Close();
249 entry_ = NULL; 254 entry_ = NULL;
250 Parse(data_); 255 Parse(data_);
251 return OK; 256 return OK;
252 } 257 }
253 258
254 int DiskCacheBasedSSLHostInfo::DoSetDone() { 259 int DiskCacheBasedSSLHostInfo::DoSetDone() {
255 if (entry_) 260 if (entry_)
256 entry_->Close(); 261 entry_->Close();
257 entry_ = NULL; 262 entry_ = NULL;
258 state_ = NONE; 263 state_ = NONE;
259 return OK; 264 return OK;
260 } 265 }
261 266
262 bool DiskCacheBasedSSLHostInfo::IsCallbackPending() const { 267 bool DiskCacheBasedSSLHostInfo::IsCallbackPending() const {
263 switch (state_) { 268 switch (state_) {
264 case GET_BACKEND_COMPLETE: 269 case GET_BACKEND_COMPLETE:
265 case OPEN_COMPLETE: 270 case OPEN_COMPLETE:
266 case READ_COMPLETE: 271 case READ_COMPLETE:
267 case CREATE_COMPLETE: 272 case CREATE_OR_OPEN_COMPLETE:
268 case WRITE_COMPLETE: 273 case WRITE_COMPLETE:
269 return true; 274 return true;
270 default: 275 default:
271 return false; 276 return false;
272 } 277 }
273 } 278 }
274 279
275 } // namespace net 280 } // namespace net
OLDNEW
« no previous file with comments | « net/http/disk_cache_based_ssl_host_info.h ('k') | net/http/disk_cache_based_ssl_host_info_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698