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

Side by Side Diff: chrome/browser/safe_browsing/client_side_model_loader.cc

Issue 2665653002: Make ModelLoader to release URLFeatcher once fetching is done. (Closed)
Patch Set: remove unnecessary changes Created 3 years, 10 months 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698