Chromium Code Reviews| 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 long as it will be re-created on next fetch. | |
|
mattm
2017/01/30 20:23:13
Wording is a little confusing, I'd remove the "as
maksims (do not use this acc)
2017/01/31 05:50:28
Done.
| |
| 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)) { |
| 202 CancelFetcher(); | |
|
mattm
2017/01/30 20:23:13
This seems unnecessary, can you explain when this
maksims (do not use this acc)
2017/01/31 05:50:28
I thought it would be necessary if fetch had been
| |
| 199 return; | 203 return; |
| 204 } | |
| 200 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 205 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 201 FROM_HERE, | 206 FROM_HERE, |
| 202 base::Bind(&ModelLoader::StartFetch, weak_factory_.GetWeakPtr()), | 207 base::Bind(&ModelLoader::StartFetch, weak_factory_.GetWeakPtr()), |
| 203 base::TimeDelta::FromMilliseconds(delay_ms)); | 208 base::TimeDelta::FromMilliseconds(delay_ms)); |
| 204 } | 209 } |
| 205 | 210 |
| 206 void ModelLoader::CancelFetcher() { | 211 void ModelLoader::CancelFetcher() { |
| 207 // Invalidate any scheduled request. | 212 // Invalidate any scheduled request. |
| 208 weak_factory_.InvalidateWeakPtrs(); | 213 weak_factory_.InvalidateWeakPtrs(); |
| 209 // Cancel any request in progress. | 214 // Cancel any request in progress. |
| 210 fetcher_.reset(); | 215 if (fetcher_) |
|
mattm
2017/01/30 20:23:13
unnecessary
maksims (do not use this acc)
2017/01/31 05:50:28
Done.
| |
| 216 fetcher_.reset(); | |
| 211 } | 217 } |
| 212 | 218 |
| 213 } // namespace safe_browsing | 219 } // namespace safe_browsing |
| OLD | NEW |