| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef NET_HTTP_DISK_CACHE_BASED_QUIC_SERVER_INFO_H_ | 5 #ifndef NET_HTTP_DISK_CACHE_BASED_QUIC_SERVER_INFO_H_ |
| 6 #define NET_HTTP_DISK_CACHE_BASED_QUIC_SERVER_INFO_H_ | 6 #define NET_HTTP_DISK_CACHE_BASED_QUIC_SERVER_INFO_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 // QuicServerInfo implementation. | 34 // QuicServerInfo implementation. |
| 35 void Start() override; | 35 void Start() override; |
| 36 int WaitForDataReady(const CompletionCallback& callback) override; | 36 int WaitForDataReady(const CompletionCallback& callback) override; |
| 37 void CancelWaitForDataReadyCallback() override; | 37 void CancelWaitForDataReadyCallback() override; |
| 38 bool IsDataReady() override; | 38 bool IsDataReady() override; |
| 39 bool IsReadyToPersist() override; | 39 bool IsReadyToPersist() override; |
| 40 void Persist() override; | 40 void Persist() override; |
| 41 | 41 |
| 42 private: | 42 private: |
| 43 struct CacheOperationDataShim; | 43 struct CacheOperationDataShim; |
| 44 |
| 44 enum State { | 45 enum State { |
| 45 GET_BACKEND, | 46 GET_BACKEND, |
| 46 GET_BACKEND_COMPLETE, | 47 GET_BACKEND_COMPLETE, |
| 47 OPEN, | 48 OPEN, |
| 48 OPEN_COMPLETE, | 49 OPEN_COMPLETE, |
| 49 READ, | 50 READ, |
| 50 READ_COMPLETE, | 51 READ_COMPLETE, |
| 51 WAIT_FOR_DATA_READY_DONE, | 52 WAIT_FOR_DATA_READY_DONE, |
| 52 CREATE_OR_OPEN, | 53 CREATE_OR_OPEN, |
| 53 CREATE_OR_OPEN_COMPLETE, | 54 CREATE_OR_OPEN_COMPLETE, |
| 54 WRITE, | 55 WRITE, |
| 55 WRITE_COMPLETE, | 56 WRITE_COMPLETE, |
| 56 SET_DONE, | 57 SET_DONE, |
| 57 NONE, | 58 NONE, |
| 58 }; | 59 }; |
| 59 | 60 |
| 61 // Enum to track number of times data read/parse/write API calls of |
| 62 // QuicServerInfo to and from disk cache is called. |
| 63 enum QuicServerInfoAPICall { |
| 64 QUIC_SERVER_INFO_START = 0, |
| 65 QUIC_SERVER_INFO_WAIT_FOR_DATA_READY = 1, |
| 66 QUIC_SERVER_INFO_PARSE = 2, |
| 67 QUIC_SERVER_INFO_WAIT_FOR_DATA_READY_CANCEL = 3, |
| 68 QUIC_SERVER_INFO_READY_TO_PERSIST = 4, |
| 69 QUIC_SERVER_INFO_PERSIST = 5, |
| 70 QUIC_SERVER_INFO_NUM_OF_API_CALLS = 6, |
| 71 }; |
| 72 |
| 73 // Enum to track failure reasons to read/load/write of QuicServerInfo to |
| 74 // and from disk cache. |
| 75 enum FailureReason { |
| 76 WAIT_FOR_DATA_READY_INVALID_ARGUMENT_FAILURE = 0, |
| 77 GET_BACKEND_FAILURE = 1, |
| 78 OPEN_FAILURE = 2, |
| 79 CREATE_OR_OPEN_FAILURE = 3, |
| 80 PARSE_NO_DATA_FAILURE = 4, |
| 81 PARSE_FAILURE = 5, |
| 82 READ_FAILURE = 6, |
| 83 READY_TO_PERSIST_FAILURE = 7, |
| 84 PERSIST_NO_BACKEND_FAILURE = 8, |
| 85 WRITE_FAILURE = 9, |
| 86 NUM_OF_FAILURES = 10, |
| 87 }; |
| 88 |
| 60 ~DiskCacheBasedQuicServerInfo() override; | 89 ~DiskCacheBasedQuicServerInfo() override; |
| 61 | 90 |
| 62 std::string key() const; | 91 std::string key() const; |
| 63 | 92 |
| 64 // The |unused| parameter is a small hack so that we can have the | 93 // The |unused| parameter is a small hack so that we can have the |
| 65 // CacheOperationDataShim object owned by the Callback that is created for | 94 // CacheOperationDataShim object owned by the Callback that is created for |
| 66 // this method. See comment above CacheOperationDataShim for details. | 95 // this method. See comment above CacheOperationDataShim for details. |
| 67 void OnIOComplete(CacheOperationDataShim* unused, int rv); | 96 void OnIOComplete(CacheOperationDataShim* unused, int rv); |
| 68 | 97 |
| 69 int DoLoop(int rv); | 98 int DoLoop(int rv); |
| 70 | 99 |
| 71 int DoGetBackendComplete(int rv); | 100 int DoGetBackendComplete(int rv); |
| 72 int DoOpenComplete(int rv); | 101 int DoOpenComplete(int rv); |
| 73 int DoReadComplete(int rv); | 102 int DoReadComplete(int rv); |
| 74 int DoWriteComplete(int rv); | 103 int DoWriteComplete(int rv); |
| 75 int DoCreateOrOpenComplete(int rv); | 104 int DoCreateOrOpenComplete(int rv); |
| 76 | 105 |
| 77 int DoGetBackend(); | 106 int DoGetBackend(); |
| 78 int DoOpen(); | 107 int DoOpen(); |
| 79 int DoRead(); | 108 int DoRead(); |
| 80 int DoWrite(); | 109 int DoWrite(); |
| 81 int DoCreateOrOpen(); | 110 int DoCreateOrOpen(); |
| 82 | 111 |
| 83 // DoWaitForDataReadyDone is the terminal state of the read operation. | 112 // DoWaitForDataReadyDone is the terminal state of the read operation. |
| 84 int DoWaitForDataReadyDone(); | 113 int DoWaitForDataReadyDone(); |
| 85 | 114 |
| 86 // DoSetDone is the terminal state of the write operation. | 115 // DoSetDone is the terminal state of the write operation. |
| 87 int DoSetDone(); | 116 int DoSetDone(); |
| 88 | 117 |
| 118 // Tracks in a histogram the number of times data read/parse/write API calls |
| 119 // of QuicServerInfo to and from disk cache is called. |
| 120 void RecordQuicServerInfoStatus(QuicServerInfoAPICall call); |
| 121 |
| 122 // Tracks in a histogram the failure reasons to read/load/write of |
| 123 // QuicServerInfo to and from disk cache. |
| 124 void RecordQuicServerInfoFailure(FailureReason failure); |
| 125 |
| 89 CacheOperationDataShim* data_shim_; // Owned by |io_callback_|. | 126 CacheOperationDataShim* data_shim_; // Owned by |io_callback_|. |
| 90 CompletionCallback io_callback_; | 127 CompletionCallback io_callback_; |
| 91 State state_; | 128 State state_; |
| 92 bool ready_; | 129 bool ready_; |
| 93 bool found_entry_; // Controls the behavior of DoCreateOrOpen. | 130 bool found_entry_; // Controls the behavior of DoCreateOrOpen. |
| 94 std::string new_data_; | 131 std::string new_data_; |
| 95 const QuicServerId server_id_; | 132 const QuicServerId server_id_; |
| 96 HttpCache* const http_cache_; | 133 HttpCache* const http_cache_; |
| 97 disk_cache::Backend* backend_; | 134 disk_cache::Backend* backend_; |
| 98 disk_cache::Entry* entry_; | 135 disk_cache::Entry* entry_; |
| 99 CompletionCallback user_callback_; | 136 CompletionCallback user_callback_; |
| 100 scoped_refptr<IOBuffer> read_buffer_; | 137 scoped_refptr<IOBuffer> read_buffer_; |
| 101 scoped_refptr<IOBuffer> write_buffer_; | 138 scoped_refptr<IOBuffer> write_buffer_; |
| 102 std::string data_; | 139 std::string data_; |
| 103 base::TimeTicks load_start_time_; | 140 base::TimeTicks load_start_time_; |
| 104 | 141 |
| 105 base::WeakPtrFactory<DiskCacheBasedQuicServerInfo> weak_factory_; | 142 base::WeakPtrFactory<DiskCacheBasedQuicServerInfo> weak_factory_; |
| 106 }; | 143 }; |
| 107 | 144 |
| 108 } // namespace net | 145 } // namespace net |
| 109 | 146 |
| 110 #endif // NET_HTTP_DISK_CACHE_BASED_QUIC_SERVER_INFO_H_ | 147 #endif // NET_HTTP_DISK_CACHE_BASED_QUIC_SERVER_INFO_H_ |
| OLD | NEW |