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" |
11 #include "net/base/io_buffer.h" | 11 #include "net/base/io_buffer.h" |
12 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
13 #include "net/http/http_cache.h" | 13 #include "net/http/http_cache.h" |
14 #include "net/http/http_network_session.h" | 14 #include "net/http/http_network_session.h" |
15 #include "net/quic/quic_session_key.h" | 15 #include "net/quic/quic_server_id.h" |
16 | 16 |
17 namespace net { | 17 namespace net { |
18 | 18 |
19 // Some APIs inside disk_cache take a handle that the caller must keep alive | 19 // Some APIs inside disk_cache take a handle that the caller must keep alive |
20 // until the API has finished its asynchronous execution. | 20 // until the API has finished its asynchronous execution. |
21 // | 21 // |
22 // Unfortunately, DiskCacheBasedQuicServerInfo may be deleted before the | 22 // Unfortunately, DiskCacheBasedQuicServerInfo may be deleted before the |
23 // operation completes causing a use-after-free. | 23 // operation completes causing a use-after-free. |
24 // | 24 // |
25 // This data shim struct is meant to provide a location for the disk_cache | 25 // This data shim struct is meant to provide a location for the disk_cache |
(...skipping 11 matching lines...) Expand all Loading... |
37 // | 37 // |
38 // TODO(ajwong): Change disk_cache's API to return results via Callback. | 38 // TODO(ajwong): Change disk_cache's API to return results via Callback. |
39 struct DiskCacheBasedQuicServerInfo::CacheOperationDataShim { | 39 struct DiskCacheBasedQuicServerInfo::CacheOperationDataShim { |
40 CacheOperationDataShim() : backend(NULL), entry(NULL) {} | 40 CacheOperationDataShim() : backend(NULL), entry(NULL) {} |
41 | 41 |
42 disk_cache::Backend* backend; | 42 disk_cache::Backend* backend; |
43 disk_cache::Entry* entry; | 43 disk_cache::Entry* entry; |
44 }; | 44 }; |
45 | 45 |
46 DiskCacheBasedQuicServerInfo::DiskCacheBasedQuicServerInfo( | 46 DiskCacheBasedQuicServerInfo::DiskCacheBasedQuicServerInfo( |
47 const QuicSessionKey& server_key, | 47 const QuicServerId& server_id, |
48 HttpCache* http_cache) | 48 HttpCache* http_cache) |
49 : QuicServerInfo(server_key), | 49 : QuicServerInfo(server_id), |
50 weak_factory_(this), | 50 weak_factory_(this), |
51 data_shim_(new CacheOperationDataShim()), | 51 data_shim_(new CacheOperationDataShim()), |
52 io_callback_( | 52 io_callback_( |
53 base::Bind(&DiskCacheBasedQuicServerInfo::OnIOComplete, | 53 base::Bind(&DiskCacheBasedQuicServerInfo::OnIOComplete, |
54 weak_factory_.GetWeakPtr(), | 54 weak_factory_.GetWeakPtr(), |
55 base::Owned(data_shim_))), // Ownership assigned. | 55 base::Owned(data_shim_))), // Ownership assigned. |
56 state_(GET_BACKEND), | 56 state_(GET_BACKEND), |
57 ready_(false), | 57 ready_(false), |
58 found_entry_(false), | 58 found_entry_(false), |
59 server_key_(server_key), | 59 server_id_(server_id), |
60 http_cache_(http_cache), | 60 http_cache_(http_cache), |
61 backend_(NULL), | 61 backend_(NULL), |
62 entry_(NULL) { | 62 entry_(NULL) { |
63 } | 63 } |
64 | 64 |
65 void DiskCacheBasedQuicServerInfo::Start() { | 65 void DiskCacheBasedQuicServerInfo::Start() { |
66 DCHECK(CalledOnValidThread()); | 66 DCHECK(CalledOnValidThread()); |
67 DCHECK_EQ(GET_BACKEND, state_); | 67 DCHECK_EQ(GET_BACKEND, state_); |
68 DoLoop(OK); | 68 DoLoop(OK); |
69 } | 69 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 DoLoop(OK); | 113 DoLoop(OK); |
114 } | 114 } |
115 | 115 |
116 DiskCacheBasedQuicServerInfo::~DiskCacheBasedQuicServerInfo() { | 116 DiskCacheBasedQuicServerInfo::~DiskCacheBasedQuicServerInfo() { |
117 DCHECK(user_callback_.is_null()); | 117 DCHECK(user_callback_.is_null()); |
118 if (entry_) | 118 if (entry_) |
119 entry_->Close(); | 119 entry_->Close(); |
120 } | 120 } |
121 | 121 |
122 std::string DiskCacheBasedQuicServerInfo::key() const { | 122 std::string DiskCacheBasedQuicServerInfo::key() const { |
123 return "quicserverinfo:" + server_key_.ToString(); | 123 return "quicserverinfo:" + server_id_.ToString(); |
124 } | 124 } |
125 | 125 |
126 void DiskCacheBasedQuicServerInfo::OnIOComplete(CacheOperationDataShim* unused, | 126 void DiskCacheBasedQuicServerInfo::OnIOComplete(CacheOperationDataShim* unused, |
127 int rv) { | 127 int rv) { |
128 DCHECK_NE(NONE, state_); | 128 DCHECK_NE(NONE, state_); |
129 rv = DoLoop(rv); | 129 rv = DoLoop(rv); |
130 if (rv != ERR_IO_PENDING && !user_callback_.is_null()) { | 130 if (rv != ERR_IO_PENDING && !user_callback_.is_null()) { |
131 CompletionCallback callback = user_callback_; | 131 CompletionCallback callback = user_callback_; |
132 user_callback_.Reset(); | 132 user_callback_.Reset(); |
133 callback.Run(rv); | 133 callback.Run(rv); |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 int DiskCacheBasedQuicServerInfo::DoSetDone() { | 286 int DiskCacheBasedQuicServerInfo::DoSetDone() { |
287 if (entry_) | 287 if (entry_) |
288 entry_->Close(); | 288 entry_->Close(); |
289 entry_ = NULL; | 289 entry_ = NULL; |
290 new_data_.clear(); | 290 new_data_.clear(); |
291 state_ = NONE; | 291 state_ = NONE; |
292 return OK; | 292 return OK; |
293 } | 293 } |
294 | 294 |
295 } // namespace net | 295 } // namespace net |
OLD | NEW |