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 "net/base/completion_callback.h"
14 #include "net/disk_cache/disk_cache.h"
15 #include "net/quic/crypto/quic_server_info.h"
23 // DiskCacheBasedQuicServerInfo fetches information about a QUIC server from
24 // our standard disk cache. Since the information is defined to be
25 // non-sensitive, it's ok for us to keep it on disk.
26 class NET_EXPORT_PRIVATE DiskCacheBasedQuicServerInfo
27 : public QuicServerInfo
,
28 public NON_EXPORTED_BASE(base::NonThreadSafe
) {
30 DiskCacheBasedQuicServerInfo(const QuicServerId
& server_id
,
31 HttpCache
* http_cache
);
33 // QuicServerInfo implementation.
34 virtual void Start() OVERRIDE
;
35 virtual int WaitForDataReady(const CompletionCallback
& callback
) OVERRIDE
;
36 virtual bool IsDataReady() OVERRIDE
;
37 virtual bool IsReadyToPersist() OVERRIDE
;
38 virtual void Persist() OVERRIDE
;
41 struct CacheOperationDataShim
;
49 WAIT_FOR_DATA_READY_DONE
,
51 CREATE_OR_OPEN_COMPLETE
,
58 virtual ~DiskCacheBasedQuicServerInfo();
60 std::string
key() const;
62 // The |unused| parameter is a small hack so that we can have the
63 // CacheOperationDataShim object owned by the Callback that is created for
64 // this method. See comment above CacheOperationDataShim for details.
65 void OnIOComplete(CacheOperationDataShim
* unused
, int rv
);
69 int DoGetBackendComplete(int rv
);
70 int DoOpenComplete(int rv
);
71 int DoReadComplete(int rv
);
72 int DoWriteComplete(int rv
);
73 int DoCreateOrOpenComplete(int rv
);
81 // DoWaitForDataReadyDone is the terminal state of the read operation.
82 int DoWaitForDataReadyDone();
84 // DoSetDone is the terminal state of the write operation.
87 base::WeakPtrFactory
<DiskCacheBasedQuicServerInfo
> weak_factory_
;
88 CacheOperationDataShim
* data_shim_
; // Owned by |io_callback_|.
89 CompletionCallback io_callback_
;
92 bool found_entry_
; // Controls the behavior of DoCreateOrOpen.
93 std::string new_data_
;
94 const QuicServerId server_id_
;
95 HttpCache
* const http_cache_
;
96 disk_cache::Backend
* backend_
;
97 disk_cache::Entry
* entry_
;
98 CompletionCallback user_callback_
;
99 scoped_refptr
<IOBuffer
> read_buffer_
;
100 scoped_refptr
<IOBuffer
> write_buffer_
;
106 #endif // NET_HTTP_DISK_CACHE_BASED_QUIC_SERVER_INFO_H_