OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 COMPONENTS_SAFE_BROWSING_DB_V4_UPDATE_PROTOCOL_MANAGER_H_ | 5 #ifndef COMPONENTS_SAFE_BROWSING_DB_V4_UPDATE_PROTOCOL_MANAGER_H_ |
6 #define COMPONENTS_SAFE_BROWSING_DB_V4_UPDATE_PROTOCOL_MANAGER_H_ | 6 #define COMPONENTS_SAFE_BROWSING_DB_V4_UPDATE_PROTOCOL_MANAGER_H_ |
7 | 7 |
8 // A class that implements Chrome's interface with the SafeBrowsing V4 update | 8 // A class that implements Chrome's interface with the SafeBrowsing V4 update |
9 // protocol. | 9 // protocol. |
10 // | 10 // |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 static std::unique_ptr<V4UpdateProtocolManager> Create( | 61 static std::unique_ptr<V4UpdateProtocolManager> Create( |
62 net::URLRequestContextGetter* request_context_getter, | 62 net::URLRequestContextGetter* request_context_getter, |
63 const V4ProtocolConfig& config, | 63 const V4ProtocolConfig& config, |
64 const base::hash_map<UpdateListIdentifier, std::string>& | 64 const base::hash_map<UpdateListIdentifier, std::string>& |
65 current_list_states, | 65 current_list_states, |
66 V4UpdateCallback callback); | 66 V4UpdateCallback callback); |
67 | 67 |
68 // net::URLFetcherDelegate interface. | 68 // net::URLFetcherDelegate interface. |
69 void OnURLFetchComplete(const net::URLFetcher* source) override; | 69 void OnURLFetchComplete(const net::URLFetcher* source) override; |
70 | 70 |
| 71 // Schedule the next update without backoff. |
| 72 void ScheduleNextUpdate(); |
| 73 |
71 protected: | 74 protected: |
72 // Constructs a V4UpdateProtocolManager that issues network requests using | 75 // Constructs a V4UpdateProtocolManager that issues network requests using |
73 // |request_context_getter|. | 76 // |request_context_getter|. |
74 // Schedules an update to get the hash prefixes for the lists in | 77 // Schedules an update to get the hash prefixes for the lists in |
75 // |current_list_states|, and invoke |callback| when the results | 78 // |current_list_states|, and invoke |callback| when the results |
76 // are retrieved. The callback may be invoked synchronously. | 79 // are retrieved. The callback may be invoked synchronously. |
77 V4UpdateProtocolManager( | 80 V4UpdateProtocolManager( |
78 net::URLRequestContextGetter* request_context_getter, | 81 net::URLRequestContextGetter* request_context_getter, |
79 const V4ProtocolConfig& config, | 82 const V4ProtocolConfig& config, |
80 const base::hash_map<UpdateListIdentifier, std::string>& | 83 const base::hash_map<UpdateListIdentifier, std::string>& |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 // assuming that the current time is |now|. | 120 // assuming that the current time is |now|. |
118 void HandleUpdateError(const base::Time& now); | 121 void HandleUpdateError(const base::Time& now); |
119 | 122 |
120 // Generates the URL for the update request and issues the request for the | 123 // Generates the URL for the update request and issues the request for the |
121 // lists passed to the constructor. | 124 // lists passed to the constructor. |
122 void IssueUpdateRequest(); | 125 void IssueUpdateRequest(); |
123 | 126 |
124 // Returns whether another update is currently scheduled. | 127 // Returns whether another update is currently scheduled. |
125 bool IsUpdateScheduled() const; | 128 bool IsUpdateScheduled() const; |
126 | 129 |
127 // Schedule the next update, considering whether we are in backoff. | 130 // Schedule the next update with backoff specified. |
128 void ScheduleNextUpdate(bool back_off); | 131 void ScheduleNextUpdateWithBackoff(bool back_off); |
129 | 132 |
130 // Schedule the next update, after the given interval. | 133 // Schedule the next update, after the given interval. |
131 void ScheduleNextUpdateAfterInterval(base::TimeDelta interval); | 134 void ScheduleNextUpdateAfterInterval(base::TimeDelta interval); |
132 | 135 |
133 // Get the next update interval, considering whether we are in backoff. | 136 // Get the next update interval, considering whether we are in backoff. |
134 base::TimeDelta GetNextUpdateInterval(bool back_off); | 137 base::TimeDelta GetNextUpdateInterval(bool back_off); |
135 | 138 |
136 // The factory that controls the creation of V4UpdateProtocolManager. | 139 // The factory that controls the creation of V4UpdateProtocolManager. |
137 // This is used by tests. | 140 // This is used by tests. |
138 static V4UpdateProtocolManagerFactory* factory_; | 141 static V4UpdateProtocolManagerFactory* factory_; |
(...skipping 19 matching lines...) Expand all Loading... |
158 // The config of the client making Pver4 requests. | 161 // The config of the client making Pver4 requests. |
159 const V4ProtocolConfig config_; | 162 const V4ProtocolConfig config_; |
160 | 163 |
161 // The context we use to issue network requests. | 164 // The context we use to issue network requests. |
162 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 165 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
163 | 166 |
164 // ID for URLFetchers for testing. | 167 // ID for URLFetchers for testing. |
165 int url_fetcher_id_; | 168 int url_fetcher_id_; |
166 | 169 |
167 // The callback that's called when GetUpdates completes. | 170 // The callback that's called when GetUpdates completes. |
168 V4UpdateCallback callback_; | 171 V4UpdateCallback update_callback_; |
169 | 172 |
170 // The pending update request. The request must be canceled when the object is | 173 // The pending update request. The request must be canceled when the object is |
171 // destroyed. | 174 // destroyed. |
172 std::unique_ptr<net::URLFetcher> request_; | 175 std::unique_ptr<net::URLFetcher> request_; |
173 | 176 |
174 // Timer to setup the next update request. | 177 // Timer to setup the next update request. |
175 base::OneShotTimer update_timer_; | 178 base::OneShotTimer update_timer_; |
176 | 179 |
| 180 base::Time last_response_time_; |
| 181 |
177 DISALLOW_COPY_AND_ASSIGN(V4UpdateProtocolManager); | 182 DISALLOW_COPY_AND_ASSIGN(V4UpdateProtocolManager); |
178 }; | 183 }; |
179 | 184 |
180 // Interface of a factory to create V4UpdateProtocolManager. Useful for tests. | 185 // Interface of a factory to create V4UpdateProtocolManager. Useful for tests. |
181 class V4UpdateProtocolManagerFactory { | 186 class V4UpdateProtocolManagerFactory { |
182 public: | 187 public: |
183 V4UpdateProtocolManagerFactory() {} | 188 V4UpdateProtocolManagerFactory() {} |
184 virtual ~V4UpdateProtocolManagerFactory() {} | 189 virtual ~V4UpdateProtocolManagerFactory() {} |
185 virtual std::unique_ptr<V4UpdateProtocolManager> CreateProtocolManager( | 190 virtual std::unique_ptr<V4UpdateProtocolManager> CreateProtocolManager( |
186 net::URLRequestContextGetter* request_context_getter, | 191 net::URLRequestContextGetter* request_context_getter, |
187 const V4ProtocolConfig& config, | 192 const V4ProtocolConfig& config, |
188 const base::hash_map<UpdateListIdentifier, std::string>& | 193 const base::hash_map<UpdateListIdentifier, std::string>& |
189 current_list_states, | 194 current_list_states, |
190 V4UpdateCallback callback) = 0; | 195 V4UpdateCallback callback) = 0; |
191 | 196 |
192 private: | 197 private: |
193 DISALLOW_COPY_AND_ASSIGN(V4UpdateProtocolManagerFactory); | 198 DISALLOW_COPY_AND_ASSIGN(V4UpdateProtocolManagerFactory); |
194 }; | 199 }; |
195 | 200 |
196 } // namespace safe_browsing | 201 } // namespace safe_browsing |
197 | 202 |
198 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_UPDATE_PROTOCOL_MANAGER_H_ | 203 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_UPDATE_PROTOCOL_MANAGER_H_ |
OLD | NEW |