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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
63 | 63 |
64 void DiskCacheBasedQuicServerInfo::Start() { | 64 void DiskCacheBasedQuicServerInfo::Start() { |
65 DCHECK(CalledOnValidThread()); | 65 DCHECK(CalledOnValidThread()); |
66 DCHECK_EQ(GET_BACKEND, state_); | 66 DCHECK_EQ(GET_BACKEND, state_); |
67 DoLoop(OK); | 67 DoLoop(OK); |
68 } | 68 } |
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_NE(GET_BACKEND, state_); |
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/11 01:01:45
1. Please add a comment to explain why we need to
ramant (doing other things)
2014/02/11 07:57:55
Done.
| |
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 |
87 bool DiskCacheBasedQuicServerInfo::IsDataReady() { | |
88 return ready_; | |
89 } | |
90 | |
86 void DiskCacheBasedQuicServerInfo::Persist() { | 91 void DiskCacheBasedQuicServerInfo::Persist() { |
87 DCHECK(CalledOnValidThread()); | 92 DCHECK(CalledOnValidThread()); |
88 DCHECK(state_ != GET_BACKEND); | 93 DCHECK_NE(GET_BACKEND, state_); |
89 | 94 |
90 DCHECK(new_data_.empty()); | 95 DCHECK(new_data_.empty()); |
91 CHECK(ready_); | 96 CHECK(ready_); |
92 DCHECK(user_callback_.is_null()); | 97 DCHECK(user_callback_.is_null()); |
93 new_data_ = Serialize(); | 98 new_data_ = Serialize(); |
94 | 99 |
95 if (!backend_) | 100 if (!backend_) |
96 return; | 101 return; |
97 | 102 |
98 state_ = CREATE_OR_OPEN; | 103 state_ = CREATE_OR_OPEN; |
99 DoLoop(OK); | 104 DoLoop(OK); |
100 } | 105 } |
101 | 106 |
102 DiskCacheBasedQuicServerInfo::~DiskCacheBasedQuicServerInfo() { | 107 DiskCacheBasedQuicServerInfo::~DiskCacheBasedQuicServerInfo() { |
103 DCHECK(user_callback_.is_null()); | 108 DCHECK(user_callback_.is_null()); |
104 if (entry_) | 109 if (entry_) |
105 entry_->Close(); | 110 entry_->Close(); |
106 } | 111 } |
107 | 112 |
108 std::string DiskCacheBasedQuicServerInfo::key() const { | 113 std::string DiskCacheBasedQuicServerInfo::key() const { |
109 return "quicserverinfo:" + hostname_; | 114 return "quicserverinfo:" + hostname_; |
110 } | 115 } |
111 | 116 |
112 void DiskCacheBasedQuicServerInfo::OnIOComplete(CacheOperationDataShim* unused, | 117 void DiskCacheBasedQuicServerInfo::OnIOComplete(CacheOperationDataShim* unused, |
113 int rv) { | 118 int rv) { |
119 DCHECK_NE(NONE, state_); | |
114 rv = DoLoop(rv); | 120 rv = DoLoop(rv); |
115 if (rv != ERR_IO_PENDING && !user_callback_.is_null()) { | 121 if (rv != ERR_IO_PENDING && !user_callback_.is_null()) { |
116 CompletionCallback callback = user_callback_; | 122 CompletionCallback callback = user_callback_; |
117 user_callback_.Reset(); | 123 user_callback_.Reset(); |
118 callback.Run(rv); | 124 callback.Run(rv); |
119 } | 125 } |
120 } | 126 } |
121 | 127 |
122 int DiskCacheBasedQuicServerInfo::DoLoop(int rv) { | 128 int DiskCacheBasedQuicServerInfo::DoLoop(int rv) { |
123 do { | 129 do { |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
265 entry_->Close(); | 271 entry_->Close(); |
266 entry_ = NULL; | 272 entry_ = NULL; |
267 Parse(data_); | 273 Parse(data_); |
268 return OK; | 274 return OK; |
269 } | 275 } |
270 | 276 |
271 int DiskCacheBasedQuicServerInfo::DoSetDone() { | 277 int DiskCacheBasedQuicServerInfo::DoSetDone() { |
272 if (entry_) | 278 if (entry_) |
273 entry_->Close(); | 279 entry_->Close(); |
274 entry_ = NULL; | 280 entry_ = NULL; |
281 new_data_.clear(); | |
275 state_ = NONE; | 282 state_ = NONE; |
276 return OK; | 283 return OK; |
277 } | 284 } |
278 | 285 |
279 } // namespace net | 286 } // namespace net |
OLD | NEW |