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