Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #include "net/http/disk_cache_based_quic_server_info.h" | 5 #include "net/http/disk_cache_based_quic_server_info.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "net/base/completion_callback.h" | 10 #include "net/base/completion_callback.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 69 | 69 |
| 70 int DiskCacheBasedQuicServerInfo::WaitForDataReady( | 70 int DiskCacheBasedQuicServerInfo::WaitForDataReady( |
| 71 const CompletionCallback& callback) { | 71 const CompletionCallback& callback) { |
| 72 DCHECK(CalledOnValidThread()); | 72 DCHECK(CalledOnValidThread()); |
| 73 DCHECK(state_ != GET_BACKEND); | 73 DCHECK(state_ != GET_BACKEND); |
| 74 | 74 |
| 75 if (ready_) | 75 if (ready_) |
| 76 return OK; | 76 return OK; |
| 77 | 77 |
| 78 if (!callback.is_null()) { | 78 if (!callback.is_null()) { |
| 79 DCHECK(user_callback_.is_null()); | 79 if (!user_callback_.is_null()) |
| 80 return ERR_INVALID_ARGUMENT; | |
|
wtc
2014/02/07 00:54:11
Nit: we may want to use a different error code.
C
ramant (doing other things)
2014/02/07 20:30:51
If user_callback_ not null, then there is a pendin
| |
| 80 user_callback_ = callback; | 81 user_callback_ = callback; |
| 81 } | 82 } |
| 82 | 83 |
| 83 return ERR_IO_PENDING; | 84 return ERR_IO_PENDING; |
| 84 } | 85 } |
| 85 | 86 |
| 86 void DiskCacheBasedQuicServerInfo::Persist() { | 87 void DiskCacheBasedQuicServerInfo::Persist() { |
| 87 DCHECK(CalledOnValidThread()); | 88 DCHECK(CalledOnValidThread()); |
| 88 DCHECK(state_ != GET_BACKEND); | 89 DCHECK_NE(state_, GET_BACKEND); |
| 89 | 90 |
| 90 DCHECK(new_data_.empty()); | 91 DCHECK(new_data_.empty()); |
| 91 CHECK(ready_); | 92 CHECK(ready_); |
| 92 DCHECK(user_callback_.is_null()); | 93 DCHECK(user_callback_.is_null()); |
| 93 new_data_ = Serialize(); | 94 new_data_ = Serialize(); |
| 94 | 95 |
| 95 if (!backend_) | 96 if (!backend_) |
| 96 return; | 97 return; |
| 97 | 98 |
| 98 state_ = CREATE_OR_OPEN; | 99 state_ = CREATE_OR_OPEN; |
| 99 DoLoop(OK); | 100 DoLoop(OK); |
| 100 } | 101 } |
| 101 | 102 |
| 102 DiskCacheBasedQuicServerInfo::~DiskCacheBasedQuicServerInfo() { | 103 DiskCacheBasedQuicServerInfo::~DiskCacheBasedQuicServerInfo() { |
| 103 DCHECK(user_callback_.is_null()); | 104 DCHECK(user_callback_.is_null()); |
| 104 if (entry_) | 105 if (entry_) |
| 105 entry_->Close(); | 106 entry_->Close(); |
| 106 } | 107 } |
| 107 | 108 |
| 108 std::string DiskCacheBasedQuicServerInfo::key() const { | 109 std::string DiskCacheBasedQuicServerInfo::key() const { |
| 109 return "quicserverinfo:" + hostname_; | 110 return "quicserverinfo:" + hostname_; |
| 110 } | 111 } |
| 111 | 112 |
| 112 void DiskCacheBasedQuicServerInfo::OnIOComplete(CacheOperationDataShim* unused, | 113 void DiskCacheBasedQuicServerInfo::OnIOComplete(CacheOperationDataShim* unused, |
| 113 int rv) { | 114 int rv) { |
| 115 DCHECK_NE(state_, NONE); | |
| 114 rv = DoLoop(rv); | 116 rv = DoLoop(rv); |
| 115 if (rv != ERR_IO_PENDING && !user_callback_.is_null()) { | 117 if (rv != ERR_IO_PENDING && !user_callback_.is_null()) { |
| 116 CompletionCallback callback = user_callback_; | 118 CompletionCallback callback = user_callback_; |
| 117 user_callback_.Reset(); | 119 user_callback_.Reset(); |
| 118 callback.Run(rv); | 120 callback.Run(rv); |
| 119 } | 121 } |
| 120 } | 122 } |
| 121 | 123 |
| 122 int DiskCacheBasedQuicServerInfo::DoLoop(int rv) { | 124 int DiskCacheBasedQuicServerInfo::DoLoop(int rv) { |
| 123 do { | 125 do { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 int DiskCacheBasedQuicServerInfo::DoReadComplete(int rv) { | 194 int DiskCacheBasedQuicServerInfo::DoReadComplete(int rv) { |
| 193 if (rv > 0) | 195 if (rv > 0) |
| 194 data_.assign(read_buffer_->data(), rv); | 196 data_.assign(read_buffer_->data(), rv); |
| 195 | 197 |
| 196 state_ = WAIT_FOR_DATA_READY_DONE; | 198 state_ = WAIT_FOR_DATA_READY_DONE; |
| 197 return OK; | 199 return OK; |
| 198 } | 200 } |
| 199 | 201 |
| 200 int DiskCacheBasedQuicServerInfo::DoWriteComplete(int rv) { | 202 int DiskCacheBasedQuicServerInfo::DoWriteComplete(int rv) { |
| 201 state_ = SET_DONE; | 203 state_ = SET_DONE; |
| 204 new_data_.clear(); | |
|
wtc
2014/02/07 00:54:11
Another good place to do new_data_.clear() is in D
ramant (doing other things)
2014/02/07 20:30:51
Done.
| |
| 202 return OK; | 205 return OK; |
| 203 } | 206 } |
| 204 | 207 |
| 205 int DiskCacheBasedQuicServerInfo::DoCreateOrOpenComplete(int rv) { | 208 int DiskCacheBasedQuicServerInfo::DoCreateOrOpenComplete(int rv) { |
| 206 if (rv != OK) { | 209 if (rv != OK) { |
| 207 state_ = SET_DONE; | 210 state_ = SET_DONE; |
| 208 } else { | 211 } else { |
| 209 entry_ = data_shim_->entry; | 212 entry_ = data_shim_->entry; |
| 210 state_ = WRITE; | 213 state_ = WRITE; |
| 211 } | 214 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 270 | 273 |
| 271 int DiskCacheBasedQuicServerInfo::DoSetDone() { | 274 int DiskCacheBasedQuicServerInfo::DoSetDone() { |
| 272 if (entry_) | 275 if (entry_) |
| 273 entry_->Close(); | 276 entry_->Close(); |
| 274 entry_ = NULL; | 277 entry_ = NULL; |
| 275 state_ = NONE; | 278 state_ = NONE; |
| 276 return OK; | 279 return OK; |
| 277 } | 280 } |
| 278 | 281 |
| 279 } // namespace net | 282 } // namespace net |
| OLD | NEW |