OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef NET_HTTP_DISK_CACHE_BASED_QUIC_SERVER_INFO_H_ | |
6 #define NET_HTTP_DISK_CACHE_BASED_QUIC_SERVER_INFO_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/macros.h" | |
11 #include "base/memory/ref_counted.h" | |
12 #include "base/memory/weak_ptr.h" | |
13 #include "base/threading/non_thread_safe.h" | |
14 #include "base/time/time.h" | |
15 #include "net/base/completion_callback.h" | |
16 #include "net/base/net_export.h" | |
17 #include "net/disk_cache/disk_cache.h" | |
18 #include "net/quic/chromium/quic_server_info.h" | |
19 | |
20 namespace net { | |
21 | |
22 class HttpCache; | |
23 class IOBufferWithSize; | |
24 class QuicServerId; | |
25 | |
26 // DiskCacheBasedQuicServerInfo fetches information about a QUIC server from | |
27 // our standard disk cache. Since the information is defined to be | |
28 // non-sensitive, it's ok for us to keep it on disk. | |
29 class NET_EXPORT_PRIVATE DiskCacheBasedQuicServerInfo | |
30 : public QuicServerInfo, | |
31 public NON_EXPORTED_BASE(base::NonThreadSafe) { | |
32 public: | |
33 DiskCacheBasedQuicServerInfo(const QuicServerId& server_id, | |
34 HttpCache* http_cache); | |
35 ~DiskCacheBasedQuicServerInfo() override; | |
36 | |
37 // QuicServerInfo implementation. | |
38 void Start() override; | |
39 int WaitForDataReady(const CompletionCallback& callback) override; | |
40 void ResetWaitForDataReadyCallback() override; | |
41 void CancelWaitForDataReadyCallback() override; | |
42 bool IsDataReady() override; | |
43 bool IsReadyToPersist() override; | |
44 void Persist() override; | |
45 void OnExternalCacheHit() override; | |
46 size_t EstimateMemoryUsage() const override; | |
47 | |
48 private: | |
49 struct CacheOperationDataShim; | |
50 | |
51 enum State { | |
52 GET_BACKEND, | |
53 GET_BACKEND_COMPLETE, | |
54 OPEN, | |
55 OPEN_COMPLETE, | |
56 READ, | |
57 READ_COMPLETE, | |
58 WAIT_FOR_DATA_READY_DONE, | |
59 CREATE_OR_OPEN, | |
60 CREATE_OR_OPEN_COMPLETE, | |
61 WRITE, | |
62 WRITE_COMPLETE, | |
63 SET_DONE, | |
64 NONE, | |
65 }; | |
66 | |
67 // Persists |pending_write_data_| if it is not empty, otherwise serializes the | |
68 // data and pesists it. | |
69 void PersistInternal(); | |
70 | |
71 std::string key() const; | |
72 | |
73 // The |unused| parameter is a small hack so that we can have the | |
74 // CacheOperationDataShim object owned by the Callback that is created for | |
75 // this method. See comment above CacheOperationDataShim for details. | |
76 void OnIOComplete(CacheOperationDataShim* unused, int rv); | |
77 | |
78 int DoLoop(int rv); | |
79 | |
80 int DoGetBackendComplete(int rv); | |
81 int DoOpenComplete(int rv); | |
82 int DoReadComplete(int rv); | |
83 int DoWriteComplete(int rv); | |
84 int DoCreateOrOpenComplete(int rv); | |
85 | |
86 int DoGetBackend(); | |
87 int DoOpen(); | |
88 int DoRead(); | |
89 int DoWrite(); | |
90 int DoCreateOrOpen(); | |
91 | |
92 // DoWaitForDataReadyDone is the terminal state of the read operation. | |
93 int DoWaitForDataReadyDone(); | |
94 | |
95 // DoSetDone is the terminal state of the write operation. | |
96 int DoSetDone(); | |
97 | |
98 // Tracks in a histogram the number of times data read/parse/write API calls | |
99 // of QuicServerInfo to and from disk cache is called. | |
100 void RecordQuicServerInfoStatus(QuicServerInfoAPICall call); | |
101 | |
102 // Tracks in a histogram the failure reasons to read/load/write of | |
103 // QuicServerInfo to and from disk cache. It also saves the |failure| in | |
104 // |last_failure_|. | |
105 void RecordQuicServerInfoFailure(FailureReason failure); | |
106 | |
107 // Tracks in a histogram if |last_failure_| is not NO_FAILURE. | |
108 void RecordLastFailure(); | |
109 | |
110 CacheOperationDataShim* data_shim_; // Owned by |io_callback_|. | |
111 CompletionCallback io_callback_; | |
112 State state_; | |
113 bool ready_; | |
114 bool found_entry_; // Controls the behavior of DoCreateOrOpen. | |
115 std::string new_data_; | |
116 std::string pending_write_data_; | |
117 const QuicServerId server_id_; | |
118 HttpCache* const http_cache_; | |
119 disk_cache::Backend* backend_; | |
120 disk_cache::Entry* entry_; | |
121 CompletionCallback wait_for_ready_callback_; | |
122 scoped_refptr<IOBufferWithSize> read_buffer_; | |
123 scoped_refptr<IOBufferWithSize> write_buffer_; | |
124 std::string data_; | |
125 base::TimeTicks load_start_time_; | |
126 FailureReason last_failure_; | |
127 | |
128 base::WeakPtrFactory<DiskCacheBasedQuicServerInfo> weak_factory_; | |
129 | |
130 DISALLOW_COPY_AND_ASSIGN(DiskCacheBasedQuicServerInfo); | |
131 }; | |
132 | |
133 } // namespace net | |
134 | |
135 #endif // NET_HTTP_DISK_CACHE_BASED_QUIC_SERVER_INFO_H_ | |
OLD | NEW |