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

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

Issue 2470923003: Handle timeout for update requests. (Closed)
Patch Set: Added a histogram for counting update timeouts 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
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, TestDisableAutoUpdates); 90 FRIEND_TEST_ALL_PREFIXES(V4UpdateProtocolManagerTest, TestDisableAutoUpdates);
91 FRIEND_TEST_ALL_PREFIXES(V4UpdateProtocolManagerTest,
92 TestGetUpdatesHasTimeout);
91 friend class V4UpdateProtocolManagerFactoryImpl; 93 friend class V4UpdateProtocolManagerFactoryImpl;
92 94
93 // Fills a FetchThreatListUpdatesRequest protocol buffer for a request. 95 // Fills a FetchThreatListUpdatesRequest protocol buffer for a request.
94 // Returns the serialized and base64 URL encoded request as a string. 96 // Returns the serialized and base64 URL encoded request as a string.
95 std::string GetBase64SerializedUpdateRequestProto(); 97 std::string GetBase64SerializedUpdateRequestProto();
96 98
97 // The method to populate |gurl| with the URL to be sent to the server. 99 // The method to populate |gurl| with the URL to be sent to the server.
98 // |request_base64| is the base64 encoded form of an instance of the protobuf 100 // |request_base64| is the base64 encoded form of an instance of the protobuf
99 // FetchThreatListUpdatesRequest. Also sets the appropriate header values for 101 // FetchThreatListUpdatesRequest. Also sets the appropriate header values for
100 // sending PVer4 requests in |headers|. 102 // sending PVer4 requests in |headers|.
101 void GetUpdateUrlAndHeaders(const std::string& request_base64, 103 void GetUpdateUrlAndHeaders(const std::string& request_base64,
102 GURL* gurl, 104 GURL* gurl,
103 net::HttpRequestHeaders* headers) const; 105 net::HttpRequestHeaders* headers) const;
104 106
105 // Parses the base64 encoded response received from the server as a 107 // Parses the base64 encoded response received from the server as a
106 // FetchThreatListUpdatesResponse protobuf and returns each of the 108 // FetchThreatListUpdatesResponse protobuf and returns each of the
107 // ListUpdateResponse protobufs contained in it as a vector. 109 // ListUpdateResponse protobufs contained in it as a vector.
108 // Returns true if parsing is successful, false otherwise. 110 // Returns true if parsing is successful, false otherwise.
109 bool ParseUpdateResponse(const std::string& data_base64, 111 bool ParseUpdateResponse(const std::string& data_base64,
110 ParsedServerResponse* parsed_server_response); 112 ParsedServerResponse* parsed_server_response);
111 113
112 // Resets the update error counter and multiplier. 114 // Resets the update error counter and multiplier.
113 void ResetUpdateErrors(); 115 void ResetUpdateErrors();
114 116
117 // Called when update request times out. Cancels the existing request and
118 // re-sends the update request.
119 void HandleTimeout();
120
115 // Updates internal update and backoff state for each update response error, 121 // Updates internal update and backoff state for each update response error,
116 // assuming that the current time is |now|. 122 // assuming that the current time is |now|.
117 void HandleUpdateError(const base::Time& now); 123 void HandleUpdateError(const base::Time& now);
118 124
119 // Generates the URL for the update request and issues the request for the 125 // Generates the URL for the update request and issues the request for the
120 // lists passed to the constructor. 126 // lists passed to the constructor.
121 void IssueUpdateRequest(); 127 void IssueUpdateRequest();
122 128
123 // Returns whether another update is currently scheduled. 129 // Returns whether another update is currently scheduled.
124 bool IsUpdateScheduled() const; 130 bool IsUpdateScheduled() const;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 172
167 // 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
168 // destroyed. 174 // destroyed.
169 std::unique_ptr<net::URLFetcher> request_; 175 std::unique_ptr<net::URLFetcher> request_;
170 176
171 // Timer to setup the next update request. 177 // Timer to setup the next update request.
172 base::OneShotTimer update_timer_; 178 base::OneShotTimer update_timer_;
173 179
174 base::Time last_response_time_; 180 base::Time last_response_time_;
175 181
182 // Used to interrupt and re-issue update requests that take too long.
Nathan Parker 2016/11/08 23:39:29 It doesn't re-issue, it just reschedules now, yes?
vakh (use Gerrit instead) 2016/11/09 00:08:51 Done.
183 base::OneShotTimer timeout_timer_;
184
176 DISALLOW_COPY_AND_ASSIGN(V4UpdateProtocolManager); 185 DISALLOW_COPY_AND_ASSIGN(V4UpdateProtocolManager);
177 }; 186 };
178 187
179 // Interface of a factory to create V4UpdateProtocolManager. Useful for tests. 188 // Interface of a factory to create V4UpdateProtocolManager. Useful for tests.
180 class V4UpdateProtocolManagerFactory { 189 class V4UpdateProtocolManagerFactory {
181 public: 190 public:
182 V4UpdateProtocolManagerFactory() {} 191 V4UpdateProtocolManagerFactory() {}
183 virtual ~V4UpdateProtocolManagerFactory() {} 192 virtual ~V4UpdateProtocolManagerFactory() {}
184 virtual std::unique_ptr<V4UpdateProtocolManager> CreateProtocolManager( 193 virtual std::unique_ptr<V4UpdateProtocolManager> CreateProtocolManager(
185 net::URLRequestContextGetter* request_context_getter, 194 net::URLRequestContextGetter* request_context_getter,
186 const V4ProtocolConfig& config, 195 const V4ProtocolConfig& config,
187 V4UpdateCallback callback) = 0; 196 V4UpdateCallback callback) = 0;
188 197
189 private: 198 private:
190 DISALLOW_COPY_AND_ASSIGN(V4UpdateProtocolManagerFactory); 199 DISALLOW_COPY_AND_ASSIGN(V4UpdateProtocolManagerFactory);
191 }; 200 };
192 201
193 } // namespace safe_browsing 202 } // namespace safe_browsing
194 203
195 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_UPDATE_PROTOCOL_MANAGER_H_ 204 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_UPDATE_PROTOCOL_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698