Removes placeholder message string for aria role option
[chromium-blink-merge.git] / net / http / disk_cache_based_quic_server_info.h
blob3076f3aa496893e7163349c9b4c5ca7ff2aa20a4
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 ResetWaitForDataReadyCallback() override;
38 void CancelWaitForDataReadyCallback() override;
39 bool IsDataReady() override;
40 bool IsReadyToPersist() override;
41 void Persist() override;
42 void OnExternalCacheHit() override;
44 private:
45 struct CacheOperationDataShim;
47 enum State {
48 GET_BACKEND,
49 GET_BACKEND_COMPLETE,
50 OPEN,
51 OPEN_COMPLETE,
52 READ,
53 READ_COMPLETE,
54 WAIT_FOR_DATA_READY_DONE,
55 CREATE_OR_OPEN,
56 CREATE_OR_OPEN_COMPLETE,
57 WRITE,
58 WRITE_COMPLETE,
59 SET_DONE,
60 NONE,
63 // Enum to track number of times data read/parse/write API calls of
64 // QuicServerInfo to and from disk cache is called.
65 enum QuicServerInfoAPICall {
66 QUIC_SERVER_INFO_START = 0,
67 QUIC_SERVER_INFO_WAIT_FOR_DATA_READY = 1,
68 QUIC_SERVER_INFO_PARSE = 2,
69 QUIC_SERVER_INFO_WAIT_FOR_DATA_READY_CANCEL = 3,
70 QUIC_SERVER_INFO_READY_TO_PERSIST = 4,
71 QUIC_SERVER_INFO_PERSIST = 5,
72 QUIC_SERVER_INFO_EXTERNAL_CACHE_HIT = 6,
73 QUIC_SERVER_INFO_NUM_OF_API_CALLS = 7,
76 // Enum to track failure reasons to read/load/write of QuicServerInfo to
77 // and from disk cache.
78 enum FailureReason {
79 WAIT_FOR_DATA_READY_INVALID_ARGUMENT_FAILURE = 0,
80 GET_BACKEND_FAILURE = 1,
81 OPEN_FAILURE = 2,
82 CREATE_OR_OPEN_FAILURE = 3,
83 PARSE_NO_DATA_FAILURE = 4,
84 PARSE_FAILURE = 5,
85 READ_FAILURE = 6,
86 READY_TO_PERSIST_FAILURE = 7,
87 PERSIST_NO_BACKEND_FAILURE = 8,
88 WRITE_FAILURE = 9,
89 NO_FAILURE = 10,
90 NUM_OF_FAILURES = 11,
93 ~DiskCacheBasedQuicServerInfo() override;
95 // Persists |pending_write_data_| if it is not empty, otherwise serializes the
96 // data and pesists it.
97 void PersistInternal();
99 std::string key() const;
101 // The |unused| parameter is a small hack so that we can have the
102 // CacheOperationDataShim object owned by the Callback that is created for
103 // this method. See comment above CacheOperationDataShim for details.
104 void OnIOComplete(CacheOperationDataShim* unused, int rv);
106 int DoLoop(int rv);
108 int DoGetBackendComplete(int rv);
109 int DoOpenComplete(int rv);
110 int DoReadComplete(int rv);
111 int DoWriteComplete(int rv);
112 int DoCreateOrOpenComplete(int rv);
114 int DoGetBackend();
115 int DoOpen();
116 int DoRead();
117 int DoWrite();
118 int DoCreateOrOpen();
120 // DoWaitForDataReadyDone is the terminal state of the read operation.
121 int DoWaitForDataReadyDone();
123 // DoSetDone is the terminal state of the write operation.
124 int DoSetDone();
126 // Tracks in a histogram the number of times data read/parse/write API calls
127 // of QuicServerInfo to and from disk cache is called.
128 void RecordQuicServerInfoStatus(QuicServerInfoAPICall call);
130 // Tracks in a histogram the failure reasons to read/load/write of
131 // QuicServerInfo to and from disk cache. It also saves the |failure| in
132 // |last_failure_|.
133 void RecordQuicServerInfoFailure(FailureReason failure);
135 // Tracks in a histogram if |last_failure_| is not NO_FAILURE.
136 void RecordLastFailure();
138 CacheOperationDataShim* data_shim_; // Owned by |io_callback_|.
139 CompletionCallback io_callback_;
140 State state_;
141 bool ready_;
142 bool found_entry_; // Controls the behavior of DoCreateOrOpen.
143 std::string new_data_;
144 std::string pending_write_data_;
145 const QuicServerId server_id_;
146 HttpCache* const http_cache_;
147 disk_cache::Backend* backend_;
148 disk_cache::Entry* entry_;
149 CompletionCallback wait_for_ready_callback_;
150 scoped_refptr<IOBuffer> read_buffer_;
151 scoped_refptr<IOBuffer> write_buffer_;
152 std::string data_;
153 base::TimeTicks load_start_time_;
154 FailureReason last_failure_;
156 base::WeakPtrFactory<DiskCacheBasedQuicServerInfo> weak_factory_;
158 DISALLOW_COPY_AND_ASSIGN(DiskCacheBasedQuicServerInfo);
161 } // namespace net
163 #endif // NET_HTTP_DISK_CACHE_BASED_QUIC_SERVER_INFO_H_