| 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" |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 // If the most recently fetched model had a valid max-age and the model was | 182 // If the most recently fetched model had a valid max-age and the model was |
| 183 // valid we're scheduling the next model update for after the max-age expired. | 183 // valid we're scheduling the next model update for after the max-age expired. |
| 184 if (!max_age.is_zero() && | 184 if (!max_age.is_zero() && |
| 185 (status == MODEL_SUCCESS || status == MODEL_NOT_CHANGED)) { | 185 (status == MODEL_SUCCESS || status == MODEL_NOT_CHANGED)) { |
| 186 // We're adding 60s of additional delay to make sure we're past | 186 // We're adding 60s of additional delay to make sure we're past |
| 187 // the model's age. | 187 // the model's age. |
| 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 // Reset |fetcher_| as it will be re-created on next fetch. |
| 193 fetcher_.reset(); |
| 194 |
| 192 // Schedule the next model reload. | 195 // Schedule the next model reload. |
| 193 ScheduleFetch(delay_ms); | 196 ScheduleFetch(delay_ms); |
| 194 } | 197 } |
| 195 | 198 |
| 196 void ModelLoader::ScheduleFetch(int64_t delay_ms) { | 199 void ModelLoader::ScheduleFetch(int64_t delay_ms) { |
| 197 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 200 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 198 safe_browsing::switches::kSbDisableAutoUpdate)) | 201 safe_browsing::switches::kSbDisableAutoUpdate)) |
| 199 return; | 202 return; |
| 200 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 203 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 201 FROM_HERE, | 204 FROM_HERE, |
| 202 base::Bind(&ModelLoader::StartFetch, weak_factory_.GetWeakPtr()), | 205 base::Bind(&ModelLoader::StartFetch, weak_factory_.GetWeakPtr()), |
| 203 base::TimeDelta::FromMilliseconds(delay_ms)); | 206 base::TimeDelta::FromMilliseconds(delay_ms)); |
| 204 } | 207 } |
| 205 | 208 |
| 206 void ModelLoader::CancelFetcher() { | 209 void ModelLoader::CancelFetcher() { |
| 207 // Invalidate any scheduled request. | 210 // Invalidate any scheduled request. |
| 208 weak_factory_.InvalidateWeakPtrs(); | 211 weak_factory_.InvalidateWeakPtrs(); |
| 209 // Cancel any request in progress. | 212 // Cancel any request in progress. |
| 210 fetcher_.reset(); | 213 fetcher_.reset(); |
| 211 } | 214 } |
| 212 | 215 |
| 213 } // namespace safe_browsing | 216 } // namespace safe_browsing |
| OLD | NEW |