Add include.
[chromium-blink-merge.git] / net / http / disk_cache_based_quic_server_info.h
blob97fe95e10c79b08da35b84b9fcf8da9c6f75612f
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_
8 #include <string>
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"
18 namespace net {
20 class HttpCache;
21 class IOBuffer;
22 class QuicServerId;
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) {
30 public:
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;
42 private:
43 struct CacheOperationDataShim;
44 enum State {
45 GET_BACKEND,
46 GET_BACKEND_COMPLETE,
47 OPEN,
48 OPEN_COMPLETE,
49 READ,
50 READ_COMPLETE,
51 WAIT_FOR_DATA_READY_DONE,
52 CREATE_OR_OPEN,
53 CREATE_OR_OPEN_COMPLETE,
54 WRITE,
55 WRITE_COMPLETE,
56 SET_DONE,
57 NONE,
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);
69 int DoLoop(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);
77 int DoGetBackend();
78 int DoOpen();
79 int DoRead();
80 int DoWrite();
81 int DoCreateOrOpen();
83 // DoWaitForDataReadyDone is the terminal state of the read operation.
84 int DoWaitForDataReadyDone();
86 // DoSetDone is the terminal state of the write operation.
87 int DoSetDone();
89 CacheOperationDataShim* data_shim_; // Owned by |io_callback_|.
90 CompletionCallback io_callback_;
91 State state_;
92 bool ready_;
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_;
102 std::string data_;
103 base::TimeTicks load_start_time_;
105 base::WeakPtrFactory<DiskCacheBasedQuicServerInfo> weak_factory_;
108 } // namespace net
110 #endif // NET_HTTP_DISK_CACHE_BASED_QUIC_SERVER_INFO_H_