| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/safe_browsing/client_side_model_loader.h" | 5 #include "chrome/browser/safe_browsing/client_side_model_loader.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
| 13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
| 17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 18 #include "chrome/browser/safe_browsing/protocol_manager.h" | 18 #include "chrome/browser/safe_browsing/protocol_manager.h" |
| 19 #include "chrome/common/chrome_switches.h" | |
| 20 #include "chrome/common/safe_browsing/client_model.pb.h" | 19 #include "chrome/common/safe_browsing/client_model.pb.h" |
| 21 #include "chrome/common/safe_browsing/csd.pb.h" | 20 #include "chrome/common/safe_browsing/csd.pb.h" |
| 22 #include "chrome/common/safe_browsing/safebrowsing_messages.h" | |
| 23 #include "components/data_use_measurement/core/data_use_user_data.h" | 21 #include "components/data_use_measurement/core/data_use_user_data.h" |
| 22 #include "components/safe_browsing/common/safebrowsing_messages.h" |
| 23 #include "components/safe_browsing/common/safebrowsing_switches.h" |
| 24 #include "components/variations/variations_associated_data.h" | 24 #include "components/variations/variations_associated_data.h" |
| 25 #include "net/http/http_response_headers.h" | 25 #include "net/http/http_response_headers.h" |
| 26 #include "net/http/http_status_code.h" | 26 #include "net/http/http_status_code.h" |
| 27 #include "net/url_request/url_fetcher.h" | 27 #include "net/url_request/url_fetcher.h" |
| 28 #include "net/url_request/url_request_context_getter.h" | 28 #include "net/url_request/url_request_context_getter.h" |
| 29 #include "net/url_request/url_request_status.h" | 29 #include "net/url_request/url_request_status.h" |
| 30 #include "url/gurl.h" | 30 #include "url/gurl.h" |
| 31 | 31 |
| 32 namespace safe_browsing { | 32 namespace safe_browsing { |
| 33 | 33 |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 max_age += base::TimeDelta::FromMinutes(1); | 188 max_age += base::TimeDelta::FromMinutes(1); |
| 189 delay_ms = max_age.InMilliseconds(); | 189 delay_ms = max_age.InMilliseconds(); |
| 190 } | 190 } |
| 191 | 191 |
| 192 // Schedule the next model reload. | 192 // Schedule the next model reload. |
| 193 ScheduleFetch(delay_ms); | 193 ScheduleFetch(delay_ms); |
| 194 } | 194 } |
| 195 | 195 |
| 196 void ModelLoader::ScheduleFetch(int64_t delay_ms) { | 196 void ModelLoader::ScheduleFetch(int64_t delay_ms) { |
| 197 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 197 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 198 switches::kSbDisableAutoUpdate)) | 198 safe_browsing::switches::kSbDisableAutoUpdate)) |
| 199 return; | 199 return; |
| 200 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 200 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 201 FROM_HERE, | 201 FROM_HERE, |
| 202 base::Bind(&ModelLoader::StartFetch, weak_factory_.GetWeakPtr()), | 202 base::Bind(&ModelLoader::StartFetch, weak_factory_.GetWeakPtr()), |
| 203 base::TimeDelta::FromMilliseconds(delay_ms)); | 203 base::TimeDelta::FromMilliseconds(delay_ms)); |
| 204 } | 204 } |
| 205 | 205 |
| 206 void ModelLoader::CancelFetcher() { | 206 void ModelLoader::CancelFetcher() { |
| 207 // Invalidate any scheduled request. | 207 // Invalidate any scheduled request. |
| 208 weak_factory_.InvalidateWeakPtrs(); | 208 weak_factory_.InvalidateWeakPtrs(); |
| 209 // Cancel any request in progress. | 209 // Cancel any request in progress. |
| 210 fetcher_.reset(); | 210 fetcher_.reset(); |
| 211 } | 211 } |
| 212 | 212 |
| 213 } // namespace safe_browsing | 213 } // namespace safe_browsing |
| OLD | NEW |