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 #include "components/safe_browsing_db/v4_update_protocol_manager.h" | 5 #include "components/safe_browsing_db/v4_update_protocol_manager.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/base64url.h" | 9 #include "base/base64url.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 | 66 |
67 // Minimum time, in seconds, from start up before we must issue an update query. | 67 // Minimum time, in seconds, from start up before we must issue an update query. |
68 static const int kV4TimerStartIntervalSecMin = 60; | 68 static const int kV4TimerStartIntervalSecMin = 60; |
69 | 69 |
70 // Maximum time, in seconds, from start up before we must issue an update query. | 70 // Maximum time, in seconds, from start up before we must issue an update query. |
71 static const int kV4TimerStartIntervalSecMax = 300; | 71 static const int kV4TimerStartIntervalSecMax = 300; |
72 | 72 |
73 // Maximum time, in seconds, to wait for a response to an update request. | 73 // Maximum time, in seconds, to wait for a response to an update request. |
74 static const int kV4TimerUpdateWaitSecMax = 30; | 74 static const int kV4TimerUpdateWaitSecMax = 30; |
75 | 75 |
| 76 ChromeClientInfo::SafeBrowsingReportingPopulation GetReportingLevelProtoValue( |
| 77 ExtendedReportingLevel reporting_level) { |
| 78 switch (reporting_level) { |
| 79 case SBER_LEVEL_OFF: |
| 80 return ChromeClientInfo::OPT_OUT; |
| 81 case SBER_LEVEL_LEGACY: |
| 82 return ChromeClientInfo::EXTENDED; |
| 83 case SBER_LEVEL_SCOUT: |
| 84 return ChromeClientInfo::SCOUT; |
| 85 default: |
| 86 NOTREACHED() << "Unexpected reporting_level!"; |
| 87 return ChromeClientInfo::UNSPECIFIED; |
| 88 } |
| 89 } |
| 90 |
76 // The default V4UpdateProtocolManagerFactory. | 91 // The default V4UpdateProtocolManagerFactory. |
77 class V4UpdateProtocolManagerFactoryImpl | 92 class V4UpdateProtocolManagerFactoryImpl |
78 : public V4UpdateProtocolManagerFactory { | 93 : public V4UpdateProtocolManagerFactory { |
79 public: | 94 public: |
80 V4UpdateProtocolManagerFactoryImpl() {} | 95 V4UpdateProtocolManagerFactoryImpl() {} |
81 ~V4UpdateProtocolManagerFactoryImpl() override {} | 96 ~V4UpdateProtocolManagerFactoryImpl() override {} |
82 std::unique_ptr<V4UpdateProtocolManager> CreateProtocolManager( | 97 std::unique_ptr<V4UpdateProtocolManager> CreateProtocolManager( |
83 net::URLRequestContextGetter* request_context_getter, | 98 net::URLRequestContextGetter* request_context_getter, |
84 const V4ProtocolConfig& config, | 99 const V4ProtocolConfig& config, |
85 V4UpdateCallback callback) override { | 100 V4UpdateCallback update_callback, |
86 return std::unique_ptr<V4UpdateProtocolManager>( | 101 ExtendedReportingLevelCallback extended_reporting_level_callback) |
87 new V4UpdateProtocolManager(request_context_getter, config, callback)); | 102 override { |
| 103 return std::unique_ptr<V4UpdateProtocolManager>(new V4UpdateProtocolManager( |
| 104 request_context_getter, config, update_callback, |
| 105 extended_reporting_level_callback)); |
88 } | 106 } |
89 | 107 |
90 private: | 108 private: |
91 DISALLOW_COPY_AND_ASSIGN(V4UpdateProtocolManagerFactoryImpl); | 109 DISALLOW_COPY_AND_ASSIGN(V4UpdateProtocolManagerFactoryImpl); |
92 }; | 110 }; |
93 | 111 |
94 // V4UpdateProtocolManager implementation -------------------------------- | 112 // V4UpdateProtocolManager implementation -------------------------------- |
95 | 113 |
96 // static | 114 // static |
97 V4UpdateProtocolManagerFactory* V4UpdateProtocolManager::factory_ = NULL; | 115 V4UpdateProtocolManagerFactory* V4UpdateProtocolManager::factory_ = NULL; |
98 | 116 |
99 // static | 117 // static |
100 std::unique_ptr<V4UpdateProtocolManager> V4UpdateProtocolManager::Create( | 118 std::unique_ptr<V4UpdateProtocolManager> V4UpdateProtocolManager::Create( |
101 net::URLRequestContextGetter* request_context_getter, | 119 net::URLRequestContextGetter* request_context_getter, |
102 const V4ProtocolConfig& config, | 120 const V4ProtocolConfig& config, |
103 V4UpdateCallback callback) { | 121 V4UpdateCallback update_callback, |
| 122 ExtendedReportingLevelCallback extended_reporting_level_callback) { |
104 if (!factory_) { | 123 if (!factory_) { |
105 factory_ = new V4UpdateProtocolManagerFactoryImpl(); | 124 factory_ = new V4UpdateProtocolManagerFactoryImpl(); |
106 } | 125 } |
107 return factory_->CreateProtocolManager(request_context_getter, config, | 126 return factory_->CreateProtocolManager(request_context_getter, config, |
108 callback); | 127 update_callback, |
| 128 extended_reporting_level_callback); |
109 } | 129 } |
110 | 130 |
111 void V4UpdateProtocolManager::ResetUpdateErrors() { | 131 void V4UpdateProtocolManager::ResetUpdateErrors() { |
112 update_error_count_ = 0; | 132 update_error_count_ = 0; |
113 update_back_off_mult_ = 1; | 133 update_back_off_mult_ = 1; |
114 } | 134 } |
115 | 135 |
116 V4UpdateProtocolManager::V4UpdateProtocolManager( | 136 V4UpdateProtocolManager::V4UpdateProtocolManager( |
117 net::URLRequestContextGetter* request_context_getter, | 137 net::URLRequestContextGetter* request_context_getter, |
118 const V4ProtocolConfig& config, | 138 const V4ProtocolConfig& config, |
119 V4UpdateCallback update_callback) | 139 V4UpdateCallback update_callback, |
| 140 ExtendedReportingLevelCallback extended_reporting_level_callback) |
120 : update_error_count_(0), | 141 : update_error_count_(0), |
121 update_back_off_mult_(1), | 142 update_back_off_mult_(1), |
122 next_update_interval_(base::TimeDelta::FromSeconds( | 143 next_update_interval_(base::TimeDelta::FromSeconds( |
123 base::RandInt(kV4TimerStartIntervalSecMin, | 144 base::RandInt(kV4TimerStartIntervalSecMin, |
124 kV4TimerStartIntervalSecMax))), | 145 kV4TimerStartIntervalSecMax))), |
125 config_(config), | 146 config_(config), |
126 request_context_getter_(request_context_getter), | 147 request_context_getter_(request_context_getter), |
127 url_fetcher_id_(0), | 148 url_fetcher_id_(0), |
128 update_callback_(update_callback) { | 149 update_callback_(update_callback), |
| 150 extended_reporting_level_callback_(extended_reporting_level_callback) { |
129 // Do not auto-schedule updates. Let the owner (V4LocalDatabaseManager) do it | 151 // Do not auto-schedule updates. Let the owner (V4LocalDatabaseManager) do it |
130 // when it is ready to process updates. | 152 // when it is ready to process updates. |
131 } | 153 } |
132 | 154 |
133 V4UpdateProtocolManager::~V4UpdateProtocolManager() {} | 155 V4UpdateProtocolManager::~V4UpdateProtocolManager() {} |
134 | 156 |
135 bool V4UpdateProtocolManager::IsUpdateScheduled() const { | 157 bool V4UpdateProtocolManager::IsUpdateScheduled() const { |
136 return update_timer_.IsRunning(); | 158 return update_timer_.IsRunning(); |
137 } | 159 } |
138 | 160 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 | 232 |
211 if (!state.empty()) { | 233 if (!state.empty()) { |
212 list_update_request->set_state(state); | 234 list_update_request->set_state(state); |
213 } | 235 } |
214 | 236 |
215 list_update_request->mutable_constraints()->add_supported_compressions(RAW); | 237 list_update_request->mutable_constraints()->add_supported_compressions(RAW); |
216 list_update_request->mutable_constraints()->add_supported_compressions( | 238 list_update_request->mutable_constraints()->add_supported_compressions( |
217 RICE); | 239 RICE); |
218 } | 240 } |
219 | 241 |
| 242 if (!extended_reporting_level_callback_.is_null()) { |
| 243 request.mutable_chrome_client_info()->set_reporting_population( |
| 244 GetReportingLevelProtoValue(extended_reporting_level_callback_.Run())); |
| 245 } |
| 246 |
220 V4ProtocolManagerUtil::SetClientInfoFromConfig(request.mutable_client(), | 247 V4ProtocolManagerUtil::SetClientInfoFromConfig(request.mutable_client(), |
221 config_); | 248 config_); |
222 | 249 |
223 // Serialize and Base64 encode. | 250 // Serialize and Base64 encode. |
224 std::string req_data, req_base64; | 251 std::string req_data, req_base64; |
225 request.SerializeToString(&req_data); | 252 request.SerializeToString(&req_data); |
226 base::Base64UrlEncode(req_data, base::Base64UrlEncodePolicy::INCLUDE_PADDING, | 253 base::Base64UrlEncode(req_data, base::Base64UrlEncodePolicy::INCLUDE_PADDING, |
227 &req_base64); | 254 &req_base64); |
228 return req_base64; | 255 return req_base64; |
229 } | 256 } |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 | 392 |
366 void V4UpdateProtocolManager::GetUpdateUrlAndHeaders( | 393 void V4UpdateProtocolManager::GetUpdateUrlAndHeaders( |
367 const std::string& req_base64, | 394 const std::string& req_base64, |
368 GURL* gurl, | 395 GURL* gurl, |
369 net::HttpRequestHeaders* headers) const { | 396 net::HttpRequestHeaders* headers) const { |
370 V4ProtocolManagerUtil::GetRequestUrlAndHeaders( | 397 V4ProtocolManagerUtil::GetRequestUrlAndHeaders( |
371 req_base64, "threatListUpdates:fetch", config_, gurl, headers); | 398 req_base64, "threatListUpdates:fetch", config_, gurl, headers); |
372 } | 399 } |
373 | 400 |
374 } // namespace safe_browsing | 401 } // namespace safe_browsing |
OLD | NEW |