Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Side by Side Diff: components/safe_browsing_db/v4_update_protocol_manager.h

Issue 2470923003: Handle timeout for update requests. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 private: 80 private:
81 FRIEND_TEST_ALL_PREFIXES(V4UpdateProtocolManagerTest, 81 FRIEND_TEST_ALL_PREFIXES(V4UpdateProtocolManagerTest,
82 TestGetUpdatesErrorHandlingNetwork); 82 TestGetUpdatesErrorHandlingNetwork);
83 FRIEND_TEST_ALL_PREFIXES(V4UpdateProtocolManagerTest, 83 FRIEND_TEST_ALL_PREFIXES(V4UpdateProtocolManagerTest,
84 TestGetUpdatesErrorHandlingResponseCode); 84 TestGetUpdatesErrorHandlingResponseCode);
85 FRIEND_TEST_ALL_PREFIXES(V4UpdateProtocolManagerTest, TestGetUpdatesNoError); 85 FRIEND_TEST_ALL_PREFIXES(V4UpdateProtocolManagerTest, TestGetUpdatesNoError);
86 FRIEND_TEST_ALL_PREFIXES(V4UpdateProtocolManagerTest, 86 FRIEND_TEST_ALL_PREFIXES(V4UpdateProtocolManagerTest,
87 TestGetUpdatesWithOneBackoff); 87 TestGetUpdatesWithOneBackoff);
88 FRIEND_TEST_ALL_PREFIXES(V4UpdateProtocolManagerTest, 88 FRIEND_TEST_ALL_PREFIXES(V4UpdateProtocolManagerTest,
89 TestBase64EncodingUsesUrlEncoding); 89 TestBase64EncodingUsesUrlEncoding);
90 FRIEND_TEST_ALL_PREFIXES(V4UpdateProtocolManagerTest,
91 TestGetUpdatesHasTimeout);
90 friend class V4UpdateProtocolManagerFactoryImpl; 92 friend class V4UpdateProtocolManagerFactoryImpl;
91 93
92 // Fills a FetchThreatListUpdatesRequest protocol buffer for a request. 94 // Fills a FetchThreatListUpdatesRequest protocol buffer for a request.
93 // Returns the serialized and base64 URL encoded request as a string. 95 // Returns the serialized and base64 URL encoded request as a string.
94 std::string GetBase64SerializedUpdateRequestProto(); 96 std::string GetBase64SerializedUpdateRequestProto();
95 97
96 // The method to populate |gurl| with the URL to be sent to the server. 98 // The method to populate |gurl| with the URL to be sent to the server.
97 // |request_base64| is the base64 encoded form of an instance of the protobuf 99 // |request_base64| is the base64 encoded form of an instance of the protobuf
98 // FetchThreatListUpdatesRequest. Also sets the appropriate header values for 100 // FetchThreatListUpdatesRequest. Also sets the appropriate header values for
99 // sending PVer4 requests in |headers|. 101 // sending PVer4 requests in |headers|.
100 void GetUpdateUrlAndHeaders(const std::string& request_base64, 102 void GetUpdateUrlAndHeaders(const std::string& request_base64,
101 GURL* gurl, 103 GURL* gurl,
102 net::HttpRequestHeaders* headers) const; 104 net::HttpRequestHeaders* headers) const;
103 105
104 // Parses the base64 encoded response received from the server as a 106 // Parses the base64 encoded response received from the server as a
105 // FetchThreatListUpdatesResponse protobuf and returns each of the 107 // FetchThreatListUpdatesResponse protobuf and returns each of the
106 // ListUpdateResponse protobufs contained in it as a vector. 108 // ListUpdateResponse protobufs contained in it as a vector.
107 // Returns true if parsing is successful, false otherwise. 109 // Returns true if parsing is successful, false otherwise.
108 bool ParseUpdateResponse(const std::string& data_base64, 110 bool ParseUpdateResponse(const std::string& data_base64,
109 ParsedServerResponse* parsed_server_response); 111 ParsedServerResponse* parsed_server_response);
110 112
111 // Resets the update error counter and multiplier. 113 // Resets the update error counter and multiplier.
112 void ResetUpdateErrors(); 114 void ResetUpdateErrors();
113 115
116 // Called when update request times out. Cancels the existing request and
117 // re-sends the update request.
118 void HandleTimeout();
119
114 // Updates internal update and backoff state for each update response error, 120 // Updates internal update and backoff state for each update response error,
115 // assuming that the current time is |now|. 121 // assuming that the current time is |now|.
116 void HandleUpdateError(const base::Time& now); 122 void HandleUpdateError(const base::Time& now);
117 123
118 // Generates the URL for the update request and issues the request for the 124 // Generates the URL for the update request and issues the request for the
119 // lists passed to the constructor. 125 // lists passed to the constructor.
120 void IssueUpdateRequest(); 126 void IssueUpdateRequest();
121 127
122 // Returns whether another update is currently scheduled. 128 // Returns whether another update is currently scheduled.
123 bool IsUpdateScheduled() const; 129 bool IsUpdateScheduled() const;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 171
166 // The pending update request. The request must be canceled when the object is 172 // The pending update request. The request must be canceled when the object is
167 // destroyed. 173 // destroyed.
168 std::unique_ptr<net::URLFetcher> request_; 174 std::unique_ptr<net::URLFetcher> request_;
169 175
170 // Timer to setup the next update request. 176 // Timer to setup the next update request.
171 base::OneShotTimer update_timer_; 177 base::OneShotTimer update_timer_;
172 178
173 base::Time last_response_time_; 179 base::Time last_response_time_;
174 180
181 // Used to interrupt and re-issue update requests that take too long.
182 base::OneShotTimer timeout_timer_;
183
175 DISALLOW_COPY_AND_ASSIGN(V4UpdateProtocolManager); 184 DISALLOW_COPY_AND_ASSIGN(V4UpdateProtocolManager);
176 }; 185 };
177 186
178 // Interface of a factory to create V4UpdateProtocolManager. Useful for tests. 187 // Interface of a factory to create V4UpdateProtocolManager. Useful for tests.
179 class V4UpdateProtocolManagerFactory { 188 class V4UpdateProtocolManagerFactory {
180 public: 189 public:
181 V4UpdateProtocolManagerFactory() {} 190 V4UpdateProtocolManagerFactory() {}
182 virtual ~V4UpdateProtocolManagerFactory() {} 191 virtual ~V4UpdateProtocolManagerFactory() {}
183 virtual std::unique_ptr<V4UpdateProtocolManager> CreateProtocolManager( 192 virtual std::unique_ptr<V4UpdateProtocolManager> CreateProtocolManager(
184 net::URLRequestContextGetter* request_context_getter, 193 net::URLRequestContextGetter* request_context_getter,
185 const V4ProtocolConfig& config, 194 const V4ProtocolConfig& config,
186 V4UpdateCallback callback) = 0; 195 V4UpdateCallback callback) = 0;
187 196
188 private: 197 private:
189 DISALLOW_COPY_AND_ASSIGN(V4UpdateProtocolManagerFactory); 198 DISALLOW_COPY_AND_ASSIGN(V4UpdateProtocolManagerFactory);
190 }; 199 };
191 200
192 } // namespace safe_browsing 201 } // namespace safe_browsing
193 202
194 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_UPDATE_PROTOCOL_MANAGER_H_ 203 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_UPDATE_PROTOCOL_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698