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
3 // found in the LICENSE file.
5 #ifndef NET_HTTP_DISK_CACHE_BASED_QUIC_SERVER_INFO_H_
6 #define NET_HTTP_DISK_CACHE_BASED_QUIC_SERVER_INFO_H_
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/threading/non_thread_safe.h"
13 #include "base/time/time.h"
14 #include "net/base/completion_callback.h"
15 #include "net/disk_cache/disk_cache.h"
16 #include "net/quic/crypto/quic_server_info.h"
24 // DiskCacheBasedQuicServerInfo fetches information about a QUIC server from
25 // our standard disk cache. Since the information is defined to be
26 // non-sensitive, it's ok for us to keep it on disk.
27 class NET_EXPORT_PRIVATE DiskCacheBasedQuicServerInfo
28 : public QuicServerInfo
,
29 public NON_EXPORTED_BASE(base::NonThreadSafe
) {
31 DiskCacheBasedQuicServerInfo(const QuicServerId
& server_id
,
32 HttpCache
* http_cache
);
34 // QuicServerInfo implementation.
35 void Start() override
;
36 int WaitForDataReady(const CompletionCallback
& callback
) override
;
37 void CancelWaitForDataReadyCallback() override
;
38 bool IsDataReady() override
;
39 bool IsReadyToPersist() override
;
40 void Persist() override
;
43 struct CacheOperationDataShim
;
51 WAIT_FOR_DATA_READY_DONE
,
53 CREATE_OR_OPEN_COMPLETE
,
60 ~DiskCacheBasedQuicServerInfo() override
;
62 std::string
key() const;
64 // The |unused| parameter is a small hack so that we can have the
65 // CacheOperationDataShim object owned by the Callback that is created for
66 // this method. See comment above CacheOperationDataShim for details.
67 void OnIOComplete(CacheOperationDataShim
* unused
, int rv
);
71 int DoGetBackendComplete(int rv
);
72 int DoOpenComplete(int rv
);
73 int DoReadComplete(int rv
);
74 int DoWriteComplete(int rv
);
75 int DoCreateOrOpenComplete(int rv
);
83 // DoWaitForDataReadyDone is the terminal state of the read operation.
84 int DoWaitForDataReadyDone();
86 // DoSetDone is the terminal state of the write operation.
89 CacheOperationDataShim
* data_shim_
; // Owned by |io_callback_|.
90 CompletionCallback io_callback_
;
93 bool found_entry_
; // Controls the behavior of DoCreateOrOpen.
94 std::string new_data_
;
95 const QuicServerId server_id_
;
96 HttpCache
* const http_cache_
;
97 disk_cache::Backend
* backend_
;
98 disk_cache::Entry
* entry_
;
99 CompletionCallback user_callback_
;
100 scoped_refptr
<IOBuffer
> read_buffer_
;
101 scoped_refptr
<IOBuffer
> write_buffer_
;
103 base::TimeTicks load_start_time_
;
105 base::WeakPtrFactory
<DiskCacheBasedQuicServerInfo
> weak_factory_
;
110 #endif // NET_HTTP_DISK_CACHE_BASED_QUIC_SERVER_INFO_H_