From 2fd18739de7bae8c59fcc5b58fad0138d6657886 Mon Sep 17 00:00:00 2001 From: treib Date: Thu, 16 Apr 2015 10:19:38 -0700 Subject: [PATCH] Supervised user blacklist: Don't download the blacklist file on every startup BUG=410824 Review URL: https://codereview.chromium.org/1086393002 Cr-Commit-Position: refs/heads/master@{#325462} --- .../browser/supervised_user/supervised_user_service.cc | 16 ++++++++++++++-- chrome/browser/supervised_user/supervised_user_service.h | 14 +++++++++----- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/chrome/browser/supervised_user/supervised_user_service.cc b/chrome/browser/supervised_user/supervised_user_service.cc index 76c4288a97c1..b880731360fe 100644 --- a/chrome/browser/supervised_user/supervised_user_service.cc +++ b/chrome/browser/supervised_user/supervised_user_service.cc @@ -6,10 +6,12 @@ #include "base/command_line.h" #include "base/files/file_path.h" +#include "base/files/file_util.h" #include "base/memory/ref_counted.h" #include "base/path_service.h" #include "base/prefs/pref_service.h" #include "base/strings/utf_string_conversions.h" +#include "base/task_runner_util.h" #include "base/version.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/component_updater/supervised_user_whitelist_installer.h" @@ -620,8 +622,18 @@ void SupervisedUserService::OnSiteListUpdated() { void SupervisedUserService::LoadBlacklist(const base::FilePath& path, const GURL& url) { - // TODO(treib): Don't re-download the blacklist if the local file exists! - if (!url.is_valid()) { + base::PostTaskAndReplyWithResult( + BrowserThread::GetBlockingPool(), + FROM_HERE, + base::Bind(&base::PathExists, path), + base::Bind(&SupervisedUserService::OnBlacklistFileChecked, + weak_ptr_factory_.GetWeakPtr(), path, url)); +} + +void SupervisedUserService::OnBlacklistFileChecked(const base::FilePath& path, + const GURL& url, + bool file_exists) { + if (file_exists) { LoadBlacklistFromFile(path); return; } diff --git a/chrome/browser/supervised_user/supervised_user_service.h b/chrome/browser/supervised_user/supervised_user_service.h index 11ac157d1429..1f10b59b7b43 100644 --- a/chrome/browser/supervised_user/supervised_user_service.h +++ b/chrome/browser/supervised_user/supervised_user_service.h @@ -281,13 +281,17 @@ class SupervisedUserService : public KeyedService, void OnSiteListsChanged( const std::vector>& site_lists); - // Asynchronously downloads a static blacklist file from |url|, stores it at - // |path|, loads it, and applies it to the URL filters. If |url| is not valid - // (e.g. empty), directly tries to load from |path|. + // Asynchronously loads a blacklist from a binary file at |path| and applies + // it to the URL filters. If no file exists at |path| yet, downloads a file + // from |url| and stores it at |path| first. void LoadBlacklist(const base::FilePath& path, const GURL& url); - // Asynchronously loads a static blacklist from a binary file at |path| and - // applies it to the URL filters. + void OnBlacklistFileChecked(const base::FilePath& path, + const GURL& url, + bool file_exists); + + // Asynchronously loads a blacklist from a binary file at |path| and applies + // it to the URL filters. void LoadBlacklistFromFile(const base::FilePath& path); void OnBlacklistDownloadDone(const base::FilePath& path, bool success); -- 2.11.4.GIT