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

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

Issue 6339012: More net/ method ordering. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More done while waiting for previous patch to clear Created 9 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « net/http/disk_cache_based_ssl_host_info.h ('k') | net/http/http_auth_filter.h » ('j') | 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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"
11 #include "net/http/http_cache.h" 11 #include "net/http/http_cache.h"
12 #include "net/http/http_network_session.h" 12 #include "net/http/http_network_session.h"
13 13
14 namespace net { 14 namespace net {
15 15
16 DiskCacheBasedSSLHostInfo::CallbackImpl::CallbackImpl(
17 const base::WeakPtr<DiskCacheBasedSSLHostInfo>& obj,
18 void (DiskCacheBasedSSLHostInfo::*meth) (int))
19 : obj_(obj),
20 meth_(meth) {
21 }
22
23 DiskCacheBasedSSLHostInfo::CallbackImpl::~CallbackImpl() {}
24
25 void DiskCacheBasedSSLHostInfo::CallbackImpl::RunWithParams(
26 const Tuple1<int>& params) {
27 if (!obj_) {
28 delete this;
29 } else {
30 DispatchToMethod(obj_.get(), meth_, params);
31 }
32 }
33
16 DiskCacheBasedSSLHostInfo::DiskCacheBasedSSLHostInfo( 34 DiskCacheBasedSSLHostInfo::DiskCacheBasedSSLHostInfo(
17 const std::string& hostname, 35 const std::string& hostname,
18 const SSLConfig& ssl_config, 36 const SSLConfig& ssl_config,
19 HttpCache* http_cache) 37 HttpCache* http_cache)
20 : SSLHostInfo(hostname, ssl_config, 38 : SSLHostInfo(hostname, ssl_config,
21 http_cache->network_layer()->GetSession()->cert_verifier()), 39 http_cache->network_layer()->GetSession()->cert_verifier()),
22 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 40 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
23 callback_(new CallbackImpl(weak_ptr_factory_.GetWeakPtr(), 41 callback_(new CallbackImpl(weak_ptr_factory_.GetWeakPtr(),
24 &DiskCacheBasedSSLHostInfo::DoLoop)), 42 &DiskCacheBasedSSLHostInfo::DoLoop)),
25 state_(GET_BACKEND), 43 state_(GET_BACKEND),
26 ready_(false), 44 ready_(false),
27 hostname_(hostname), 45 hostname_(hostname),
28 http_cache_(http_cache), 46 http_cache_(http_cache),
29 backend_(NULL), 47 backend_(NULL),
30 entry_(NULL), 48 entry_(NULL),
31 user_callback_(NULL) { 49 user_callback_(NULL) {
32 } 50 }
33 51
34 void DiskCacheBasedSSLHostInfo::Start() { 52 void DiskCacheBasedSSLHostInfo::Start() {
35 DCHECK(CalledOnValidThread()); 53 DCHECK(CalledOnValidThread());
36 DCHECK_EQ(GET_BACKEND, state_); 54 DCHECK_EQ(GET_BACKEND, state_);
37 DoLoop(OK); 55 DoLoop(OK);
38 } 56 }
39 57
58 int DiskCacheBasedSSLHostInfo::WaitForDataReady(CompletionCallback* callback) {
59 DCHECK(CalledOnValidThread());
60 DCHECK(state_ != GET_BACKEND);
61
62 if (ready_)
63 return OK;
64 if (callback) {
65 DCHECK(!user_callback_);
66 user_callback_ = callback;
67 }
68 return ERR_IO_PENDING;
69 }
70
71 void DiskCacheBasedSSLHostInfo::Persist() {
72 DCHECK(CalledOnValidThread());
73 DCHECK(state_ != GET_BACKEND);
74
75 DCHECK(new_data_.empty());
76 CHECK(ready_);
77 DCHECK(user_callback_ == NULL);
78 new_data_ = Serialize();
79
80 if (!backend_)
81 return;
82
83 state_ = CREATE;
84 DoLoop(OK);
85 }
86
40 DiskCacheBasedSSLHostInfo::~DiskCacheBasedSSLHostInfo() { 87 DiskCacheBasedSSLHostInfo::~DiskCacheBasedSSLHostInfo() {
41 DCHECK(!user_callback_); 88 DCHECK(!user_callback_);
42 if (entry_) 89 if (entry_)
43 entry_->Close(); 90 entry_->Close();
44 if (!IsCallbackPending()) 91 if (!IsCallbackPending())
45 delete callback_; 92 delete callback_;
46 } 93 }
47 94
48 std::string DiskCacheBasedSSLHostInfo::key() const { 95 std::string DiskCacheBasedSSLHostInfo::key() const {
49 return "sslhostinfo:" + hostname_; 96 return "sslhostinfo:" + hostname_;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 case SET_DONE: 135 case SET_DONE:
89 rv = SetDone(); 136 rv = SetDone();
90 break; 137 break;
91 default: 138 default:
92 rv = OK; 139 rv = OK;
93 NOTREACHED(); 140 NOTREACHED();
94 } 141 }
95 } while (rv != ERR_IO_PENDING && state_ != NONE); 142 } while (rv != ERR_IO_PENDING && state_ != NONE);
96 } 143 }
97 144
98 bool DiskCacheBasedSSLHostInfo::IsCallbackPending() const {
99 switch (state_) {
100 case GET_BACKEND_COMPLETE:
101 case OPEN_COMPLETE:
102 case READ_COMPLETE:
103 case CREATE_COMPLETE:
104 case WRITE_COMPLETE:
105 return true;
106 default:
107 return false;
108 }
109 }
110
111 int DiskCacheBasedSSLHostInfo::DoGetBackend() {
112 state_ = GET_BACKEND_COMPLETE;
113 return http_cache_->GetBackend(callback_->backend_pointer(), callback_);
114 }
115
116 int DiskCacheBasedSSLHostInfo::DoGetBackendComplete(int rv) { 145 int DiskCacheBasedSSLHostInfo::DoGetBackendComplete(int rv) {
117 if (rv == OK) { 146 if (rv == OK) {
118 backend_ = callback_->backend(); 147 backend_ = callback_->backend();
119 state_ = OPEN; 148 state_ = OPEN;
120 } else { 149 } else {
121 state_ = WAIT_FOR_DATA_READY_DONE; 150 state_ = WAIT_FOR_DATA_READY_DONE;
122 } 151 }
123 return OK; 152 return OK;
124 } 153 }
125 154
126 int DiskCacheBasedSSLHostInfo::DoOpen() {
127 state_ = OPEN_COMPLETE;
128 return backend_->OpenEntry(key(), callback_->entry_pointer(), callback_);
129 }
130
131 int DiskCacheBasedSSLHostInfo::DoOpenComplete(int rv) { 155 int DiskCacheBasedSSLHostInfo::DoOpenComplete(int rv) {
132 if (rv == OK) { 156 if (rv == OK) {
133 entry_ = callback_->entry(); 157 entry_ = callback_->entry();
134 state_ = READ; 158 state_ = READ;
135 } else { 159 } else {
136 state_ = WAIT_FOR_DATA_READY_DONE; 160 state_ = WAIT_FOR_DATA_READY_DONE;
137 } 161 }
138 162
139 return OK; 163 return OK;
140 } 164 }
141 165
166 int DiskCacheBasedSSLHostInfo::DoReadComplete(int rv) {
167 if (rv > 0)
168 data_ = std::string(read_buffer_->data(), rv);
169
170 state_ = WAIT_FOR_DATA_READY_DONE;
171 return OK;
172 }
173
174 int DiskCacheBasedSSLHostInfo::DoWriteComplete(int rv) {
175 state_ = SET_DONE;
176 return OK;
177 }
178
179 int DiskCacheBasedSSLHostInfo::DoCreateComplete(int rv) {
180 if (rv != OK) {
181 state_ = SET_DONE;
182 } else {
183 entry_ = callback_->entry();
184 state_ = WRITE;
185 }
186 return OK;
187 }
188
189 int DiskCacheBasedSSLHostInfo::DoGetBackend() {
190 state_ = GET_BACKEND_COMPLETE;
191 return http_cache_->GetBackend(callback_->backend_pointer(), callback_);
192 }
193
194 int DiskCacheBasedSSLHostInfo::DoOpen() {
195 state_ = OPEN_COMPLETE;
196 return backend_->OpenEntry(key(), callback_->entry_pointer(), callback_);
197 }
198
142 int DiskCacheBasedSSLHostInfo::DoRead() { 199 int DiskCacheBasedSSLHostInfo::DoRead() {
143 const int32 size = entry_->GetDataSize(0 /* index */); 200 const int32 size = entry_->GetDataSize(0 /* index */);
144 if (!size) { 201 if (!size) {
145 state_ = WAIT_FOR_DATA_READY_DONE; 202 state_ = WAIT_FOR_DATA_READY_DONE;
146 return OK; 203 return OK;
147 } 204 }
148 205
149 read_buffer_ = new IOBuffer(size); 206 read_buffer_ = new IOBuffer(size);
150 state_ = READ_COMPLETE; 207 state_ = READ_COMPLETE;
151 return entry_->ReadData(0 /* index */, 0 /* offset */, read_buffer_, 208 return entry_->ReadData(0 /* index */, 0 /* offset */, read_buffer_,
152 size, callback_); 209 size, callback_);
153 } 210 }
154 211
155 int DiskCacheBasedSSLHostInfo::DoReadComplete(int rv) { 212 int DiskCacheBasedSSLHostInfo::DoWrite() {
156 if (rv > 0) 213 write_buffer_ = new IOBuffer(new_data_.size());
157 data_ = std::string(read_buffer_->data(), rv); 214 memcpy(write_buffer_->data(), new_data_.data(), new_data_.size());
215 state_ = WRITE_COMPLETE;
158 216
159 state_ = WAIT_FOR_DATA_READY_DONE; 217 return entry_->WriteData(0 /* index */, 0 /* offset */, write_buffer_,
160 return OK; 218 new_data_.size(), callback_, true /* truncate */);
219 }
220
221 int DiskCacheBasedSSLHostInfo::DoCreate() {
222 DCHECK(entry_ == NULL);
223 state_ = CREATE_COMPLETE;
224 return backend_->CreateEntry(key(), callback_->entry_pointer(), callback_);
161 } 225 }
162 226
163 int DiskCacheBasedSSLHostInfo::WaitForDataReadyDone() { 227 int DiskCacheBasedSSLHostInfo::WaitForDataReadyDone() {
164 CompletionCallback* callback; 228 CompletionCallback* callback;
165 229
166 DCHECK(!ready_); 230 DCHECK(!ready_);
167 state_ = NONE; 231 state_ = NONE;
168 ready_ = true; 232 ready_ = true;
169 callback = user_callback_; 233 callback = user_callback_;
170 user_callback_ = NULL; 234 user_callback_ = NULL;
171 // We close the entry because, if we shutdown before ::Persist is called, 235 // We close the entry because, if we shutdown before ::Persist is called,
172 // then we might leak a cache reference, which causes a DCHECK on shutdown. 236 // then we might leak a cache reference, which causes a DCHECK on shutdown.
173 if (entry_) 237 if (entry_)
174 entry_->Close(); 238 entry_->Close();
175 entry_ = NULL; 239 entry_ = NULL;
176 Parse(data_); 240 Parse(data_);
177 241
178 if (callback) 242 if (callback)
179 callback->Run(OK); 243 callback->Run(OK);
180 244
181 return OK; 245 return OK;
182 } 246 }
183 247
184 int DiskCacheBasedSSLHostInfo::WaitForDataReady(CompletionCallback* callback) {
185 DCHECK(CalledOnValidThread());
186 DCHECK(state_ != GET_BACKEND);
187
188 if (ready_)
189 return OK;
190 if (callback) {
191 DCHECK(!user_callback_);
192 user_callback_ = callback;
193 }
194 return ERR_IO_PENDING;
195 }
196
197 void DiskCacheBasedSSLHostInfo::Persist() {
198 DCHECK(CalledOnValidThread());
199 DCHECK(state_ != GET_BACKEND);
200
201 DCHECK(new_data_.empty());
202 CHECK(ready_);
203 DCHECK(user_callback_ == NULL);
204 new_data_ = Serialize();
205
206 if (!backend_)
207 return;
208
209 state_ = CREATE;
210 DoLoop(OK);
211 }
212
213 int DiskCacheBasedSSLHostInfo::DoCreate() {
214 DCHECK(entry_ == NULL);
215 state_ = CREATE_COMPLETE;
216 return backend_->CreateEntry(key(), callback_->entry_pointer(), callback_);
217 }
218
219 int DiskCacheBasedSSLHostInfo::DoCreateComplete(int rv) {
220 if (rv != OK) {
221 state_ = SET_DONE;
222 } else {
223 entry_ = callback_->entry();
224 state_ = WRITE;
225 }
226 return OK;
227 }
228
229 int DiskCacheBasedSSLHostInfo::DoWrite() {
230 write_buffer_ = new IOBuffer(new_data_.size());
231 memcpy(write_buffer_->data(), new_data_.data(), new_data_.size());
232 state_ = WRITE_COMPLETE;
233
234 return entry_->WriteData(0 /* index */, 0 /* offset */, write_buffer_,
235 new_data_.size(), callback_, true /* truncate */);
236 }
237
238 int DiskCacheBasedSSLHostInfo::DoWriteComplete(int rv) {
239 state_ = SET_DONE;
240 return OK;
241 }
242
243 int DiskCacheBasedSSLHostInfo::SetDone() { 248 int DiskCacheBasedSSLHostInfo::SetDone() {
244 if (entry_) 249 if (entry_)
245 entry_->Close(); 250 entry_->Close();
246 entry_ = NULL; 251 entry_ = NULL;
247 state_ = NONE; 252 state_ = NONE;
248 return OK; 253 return OK;
249 } 254 }
250 255
256 bool DiskCacheBasedSSLHostInfo::IsCallbackPending() const {
257 switch (state_) {
258 case GET_BACKEND_COMPLETE:
259 case OPEN_COMPLETE:
260 case READ_COMPLETE:
261 case CREATE_COMPLETE:
262 case WRITE_COMPLETE:
263 return true;
264 default:
265 return false;
266 }
267 }
268
251 } // namespace net 269 } // namespace net
OLDNEW
« no previous file with comments | « net/http/disk_cache_based_ssl_host_info.h ('k') | net/http/http_auth_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698