Commit 57be4a03 authored by Dan Harrington's avatar Dan Harrington Committed by Commit Bot

Remove PrefetchConfiguration, add prefetch_prefs.h

Move prefetch preferences to the offline_pages component. This removes the need
for PrefetchConfiguration.

Change-Id: Ia5c5e4d908bfa9abbfc72f9c076a54fb6dc2daee
Reviewed-on: https://chromium-review.googlesource.com/1217350
Commit-Queue: Dan H <harringtond@chromium.org>
Reviewed-by: default avatarDominic Battré <battre@chromium.org>
Reviewed-by: default avatarCarlos Knippschild <carlosk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#591387}
parent a755f3b5
......@@ -4025,8 +4025,6 @@ jumbo_split_static_library("browser") {
"offline_pages/prefetch/prefetch_background_task_handler_impl.cc",
"offline_pages/prefetch/prefetch_background_task_handler_impl.h",
"offline_pages/prefetch/prefetch_background_task_scheduler.h",
"offline_pages/prefetch/prefetch_configuration_impl.cc",
"offline_pages/prefetch/prefetch_configuration_impl.h",
"offline_pages/prefetch/prefetch_instance_id_proxy.cc",
"offline_pages/prefetch/prefetch_instance_id_proxy.h",
"offline_pages/prefetch/prefetch_service_factory.cc",
......
......@@ -3,51 +3,29 @@
// found in the LICENSE file.
#include "base/android/jni_android.h"
#include "chrome/browser/offline_pages/prefetch/prefetch_configuration_impl.h"
#include "chrome/browser/offline_pages/prefetch/prefetch_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_android.h"
#include "components/offline_pages/core/offline_page_feature.h"
#include "components/offline_pages/core/prefetch/prefetch_prefs.h"
#include "components/offline_pages/core/prefetch/prefetch_service.h"
#include "jni/PrefetchConfiguration_jni.h"
using base::android::JavaParamRef;
// These functions fulfill the Java to native link between
// PrefetchConfiguration.java and PrefetchConfigurationImpl.
// PrefetchConfiguration.java and prefetch_prefs.
namespace offline_pages {
namespace android {
namespace {
PrefetchConfigurationImpl* PrefetchConfigurationImplFromJProfile(
const JavaParamRef<jobject>& jprofile) {
Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile);
if (!profile)
return nullptr;
PrefetchService* prefetch_service =
PrefetchServiceFactory::GetForBrowserContext(profile);
if (!prefetch_service)
return nullptr;
// The cast below is safe because PrefetchConfigurationImpl is Chrome's
// implementation of PrefetchConfiguration.
return static_cast<PrefetchConfigurationImpl*>(
prefetch_service->GetPrefetchConfiguration());
}
} // namespace
JNI_EXPORT jboolean JNI_PrefetchConfiguration_IsPrefetchingEnabled(
JNIEnv* env,
const JavaParamRef<jclass>& jcaller,
const JavaParamRef<jobject>& jprofile) {
PrefetchConfigurationImpl* config_impl =
PrefetchConfigurationImplFromJProfile(jprofile);
if (config_impl)
return static_cast<jboolean>(config_impl->IsPrefetchingEnabled());
return false;
Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile);
return profile &&
static_cast<jboolean>(prefetch_prefs::IsEnabled(profile->GetPrefs()));
}
JNI_EXPORT void JNI_PrefetchConfiguration_SetPrefetchingEnabledInSettings(
......@@ -55,10 +33,11 @@ JNI_EXPORT void JNI_PrefetchConfiguration_SetPrefetchingEnabledInSettings(
const JavaParamRef<jclass>& jcaller,
const JavaParamRef<jobject>& jprofile,
jboolean enabled) {
PrefetchConfigurationImpl* config_impl =
PrefetchConfigurationImplFromJProfile(jprofile);
if (config_impl)
config_impl->SetPrefetchingEnabledInSettings(enabled);
Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile);
if (!profile)
return;
prefetch_prefs::SetPrefetchingEnabledInSettings(profile->GetPrefs(), enabled);
}
} // namespace android
......
......@@ -8,6 +8,7 @@
#include "chrome/browser/offline_pages/prefetch/prefetch_background_task_scheduler.h"
#include "chrome/common/pref_names.h"
#include "components/offline_pages/core/offline_page_feature.h"
#include "components/offline_pages/core/prefetch/prefetch_prefs.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "net/base/backoff_entry_serializer.h"
......@@ -27,12 +28,6 @@ const net::BackoffEntry::Policy kPrefetchBackoffPolicy = {
};
} // namespace
// static
void PrefetchBackgroundTaskHandlerImpl::RegisterPrefs(
PrefRegistrySimple* registry) {
registry->RegisterListPref(prefs::kOfflinePrefetchBackoff);
}
PrefetchBackgroundTaskHandlerImpl::PrefetchBackgroundTaskHandlerImpl(
PrefService* prefs)
: prefs_(prefs) {}
......@@ -59,8 +54,7 @@ int PrefetchBackgroundTaskHandlerImpl::GetAdditionalBackoffSeconds() const {
std::unique_ptr<net::BackoffEntry>
PrefetchBackgroundTaskHandlerImpl::GetCurrentBackoff() const {
const base::ListValue* value =
prefs_->GetList(prefs::kOfflinePrefetchBackoff);
const base::ListValue* value = prefs_->GetList(prefetch_prefs::kBackoff);
std::unique_ptr<net::BackoffEntry> result;
if (value) {
result = net::BackoffEntrySerializer::DeserializeFromValue(
......@@ -123,7 +117,7 @@ void PrefetchBackgroundTaskHandlerImpl::UpdateBackoff(
std::unique_ptr<base::Value> value =
net::BackoffEntrySerializer::SerializeToValue(*backoff,
base::Time::Now());
prefs_->Set(prefs::kOfflinePrefetchBackoff, *value);
prefs_->Set(prefetch_prefs::kBackoff, *value);
}
} // namespace offline_pages
......@@ -11,7 +11,6 @@
#include "base/time/tick_clock.h"
#include "components/offline_pages/core/prefetch/prefetch_background_task_handler.h"
class PrefRegistrySimple;
class PrefService;
namespace base {
......@@ -41,8 +40,6 @@ namespace offline_pages {
// The backoff value is controlled by a persisted BackoffEntry.
class PrefetchBackgroundTaskHandlerImpl : public PrefetchBackgroundTaskHandler {
public:
static void RegisterPrefs(PrefRegistrySimple* registry);
explicit PrefetchBackgroundTaskHandlerImpl(PrefService* profile);
~PrefetchBackgroundTaskHandlerImpl() override;
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/offline_pages/prefetch/prefetch_configuration_impl.h"
#include "chrome/common/pref_names.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
namespace offline_pages {
// static
void PrefetchConfigurationImpl::RegisterPrefs(PrefRegistrySimple* registry) {
registry->RegisterBooleanPref(prefs::kOfflinePrefetchEnabled, true);
}
PrefetchConfigurationImpl::PrefetchConfigurationImpl(PrefService* pref_service)
: pref_service_(pref_service) {}
PrefetchConfigurationImpl::~PrefetchConfigurationImpl() = default;
bool PrefetchConfigurationImpl::IsPrefetchingEnabledBySettings() {
return pref_service_->GetBoolean(prefs::kOfflinePrefetchEnabled);
}
void PrefetchConfigurationImpl::SetPrefetchingEnabledInSettings(bool enabled) {
pref_service_->SetBoolean(prefs::kOfflinePrefetchEnabled, enabled);
}
} // namespace offline_pages
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_OFFLINE_PAGES_PREFETCH_PREFETCH_CONFIGURATION_IMPL_H_
#define CHROME_BROWSER_OFFLINE_PAGES_PREFETCH_PREFETCH_CONFIGURATION_IMPL_H_
#include "base/macros.h"
#include "components/offline_pages/core/prefetch/prefetch_configuration.h"
class PrefRegistrySimple;
class PrefService;
namespace offline_pages {
// Implementation of PrefetchConfiguration that queries Chrome preferences.
class PrefetchConfigurationImpl : public PrefetchConfiguration {
public:
static void RegisterPrefs(PrefRegistrySimple* registry);
explicit PrefetchConfigurationImpl(PrefService* pref_service);
~PrefetchConfigurationImpl() override;
// PrefetchConfiguration implementation.
bool IsPrefetchingEnabledBySettings() override;
// Configures the user controlled setting that enables or disables the
// prefetching of offline pages to run.
void SetPrefetchingEnabledInSettings(bool enabled);
private:
PrefService* pref_service_;
DISALLOW_COPY_AND_ASSIGN(PrefetchConfigurationImpl);
};
} // namespace offline_pages
#endif // CHROME_BROWSER_OFFLINE_PAGES_PREFETCH_PREFETCH_CONFIGURATION_IMPL_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/offline_pages/prefetch/prefetch_configuration_impl.h"
#include "base/feature_list.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/common/pref_names.h"
#include "components/offline_pages/core/offline_page_feature.h"
#include "components/prefs/testing_pref_service.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace offline_pages {
class PrefetchConfigurationImplTest : public testing::Test {
public:
PrefetchConfigurationImplTest()
: pref_service_(), prefetch_config_(&pref_service_) {}
~PrefetchConfigurationImplTest() override = default;
void SetUp() override {
PrefetchConfigurationImpl::RegisterPrefs(pref_service_.registry());
}
PrefService& prefs() { return pref_service_; }
PrefetchConfigurationImpl& config() { return prefetch_config_; }
protected:
TestingPrefServiceSimple pref_service_;
PrefetchConfigurationImpl prefetch_config_;
DISALLOW_COPY_AND_ASSIGN(PrefetchConfigurationImplTest);
};
TEST_F(PrefetchConfigurationImplTest, EnabledInSettingsByDefault) {
EXPECT_TRUE(prefs().GetBoolean(prefs::kOfflinePrefetchEnabled));
EXPECT_TRUE(config().IsPrefetchingEnabledBySettings());
}
TEST_F(PrefetchConfigurationImplTest, WhenPrefetchFlagIsEnabled) {
base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(kPrefetchingOfflinePagesFeature);
// Disable in settings and check.
config().SetPrefetchingEnabledInSettings(false);
EXPECT_FALSE(config().IsPrefetchingEnabledBySettings());
EXPECT_FALSE(config().IsPrefetchingEnabled());
// Re-enable in settings and check.
config().SetPrefetchingEnabledInSettings(true);
EXPECT_TRUE(config().IsPrefetchingEnabledBySettings());
EXPECT_TRUE(config().IsPrefetchingEnabled());
}
TEST_F(PrefetchConfigurationImplTest, WhenPrefetchFlagIsDisabled) {
base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndDisableFeature(kPrefetchingOfflinePagesFeature);
// Disable in settings and check.
config().SetPrefetchingEnabledInSettings(false);
EXPECT_FALSE(config().IsPrefetchingEnabledBySettings());
EXPECT_FALSE(config().IsPrefetchingEnabled());
// Re-enable in settings and check.
config().SetPrefetchingEnabledInSettings(true);
EXPECT_TRUE(config().IsPrefetchingEnabledBySettings());
EXPECT_FALSE(config().IsPrefetchingEnabled());
}
} // namespace offline_pages
......@@ -16,7 +16,6 @@
#include "chrome/browser/offline_pages/offline_page_model_factory.h"
#include "chrome/browser/offline_pages/prefetch/offline_metrics_collector_impl.h"
#include "chrome/browser/offline_pages/prefetch/prefetch_background_task_handler_impl.h"
#include "chrome/browser/offline_pages/prefetch/prefetch_configuration_impl.h"
#include "chrome/browser/offline_pages/prefetch/prefetch_instance_id_proxy.h"
#include "chrome/browser/offline_pages/prefetch/thumbnail_fetcher_impl.h"
#include "chrome/browser/profiles/profile.h"
......@@ -68,7 +67,8 @@ KeyedService* PrefetchServiceFactory::BuildServiceInstanceFor(
auto offline_metrics_collector =
std::make_unique<OfflineMetricsCollectorImpl>(profile->GetPrefs());
auto prefetch_dispatcher = std::make_unique<PrefetchDispatcherImpl>();
auto prefetch_dispatcher =
std::make_unique<PrefetchDispatcherImpl>(profile->GetPrefs());
auto prefetch_gcm_app_handler = std::make_unique<PrefetchGCMAppHandler>(
std::make_unique<PrefetchInstanceIDProxy>(kPrefetchingOfflinePagesAppId,
......@@ -98,9 +98,6 @@ KeyedService* PrefetchServiceFactory::BuildServiceInstanceFor(
auto prefetch_background_task_handler =
std::make_unique<PrefetchBackgroundTaskHandlerImpl>(profile->GetPrefs());
auto configuration =
std::make_unique<PrefetchConfigurationImpl>(profile->GetPrefs());
auto thumbnail_fetcher = std::make_unique<ThumbnailFetcherImpl>();
return new PrefetchServiceImpl(
......@@ -109,7 +106,7 @@ KeyedService* PrefetchServiceFactory::BuildServiceInstanceFor(
std::move(prefetch_network_request_factory), offline_page_model,
std::move(prefetch_store), std::move(suggested_articles_observer),
std::move(prefetch_downloader), std::move(prefetch_importer),
std::move(prefetch_background_task_handler), std::move(configuration),
std::move(prefetch_background_task_handler),
std::move(thumbnail_fetcher));
}
......
......@@ -159,7 +159,7 @@
#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
#include "chrome/browser/offline_pages/prefetch/offline_metrics_collector_impl.h"
#include "chrome/browser/offline_pages/prefetch/prefetch_background_task_handler_impl.h"
#include "chrome/browser/offline_pages/prefetch/prefetch_configuration_impl.h"
#include "components/offline_pages/core/prefetch/prefetch_prefs.h"
#endif
#if BUILDFLAG(ENABLE_PLUGINS)
......@@ -724,8 +724,7 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
offline_pages::OfflineMetricsCollectorImpl::RegisterPrefs(registry);
offline_pages::PrefetchBackgroundTaskHandlerImpl::RegisterPrefs(registry);
offline_pages::PrefetchConfigurationImpl::RegisterPrefs(registry);
offline_pages::prefetch_prefs::RegisterPrefs(registry);
#endif
#if defined(OS_ANDROID)
......
......@@ -2524,8 +2524,6 @@ const char kClipboardLastModifiedTime[] = "ui.clipboard.last_modified_time";
#endif
#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
const char kOfflinePrefetchEnabled[] = "offline_prefetch.enabled";
const char kOfflinePrefetchBackoff[] = "offline_prefetch.backoff";
// The following set of Prefs is used by OfflineMetricsCollectorImpl to
// backup the current Chrome usage tracking state and accumulated counters
......
......@@ -878,8 +878,6 @@ extern const char kClipboardLastModifiedTime[];
#endif
#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
extern const char kOfflinePrefetchEnabled[];
extern const char kOfflinePrefetchBackoff[];
extern const char kOfflineUsageStartObserved[];
extern const char kOfflineUsageOnlineObserved[];
extern const char kOfflineUsageOfflineObserved[];
......
......@@ -2952,7 +2952,6 @@ test("unit_tests") {
"../browser/offline_pages/offline_page_utils_unittest.cc",
"../browser/offline_pages/prefetch/offline_metrics_collector_impl_unittest.cc",
"../browser/offline_pages/prefetch/prefetch_background_task_handler_impl_unittest.cc",
"../browser/offline_pages/prefetch/prefetch_configuration_impl_unittest.cc",
"../browser/offline_pages/prefetch/prefetch_instance_id_proxy_unittest.cc",
"../browser/offline_pages/prefetch/prefetched_pages_notifier_unittest.cc",
"../browser/offline_pages/prefetch/thumbnail_fetcher_impl_unittest.cc",
......
......@@ -45,8 +45,6 @@ static_library("prefetch") {
"prefetch_background_task.cc",
"prefetch_background_task.h",
"prefetch_background_task_handler.h",
"prefetch_configuration.cc",
"prefetch_configuration.h",
"prefetch_dispatcher.h",
"prefetch_dispatcher_impl.cc",
"prefetch_dispatcher_impl.h",
......@@ -63,6 +61,8 @@ static_library("prefetch") {
"prefetch_network_request_factory.h",
"prefetch_network_request_factory_impl.cc",
"prefetch_network_request_factory_impl.h",
"prefetch_prefs.cc",
"prefetch_prefs.h",
"prefetch_proto_utils.cc",
"prefetch_proto_utils.h",
"prefetch_request_fetcher.cc",
......@@ -107,6 +107,7 @@ static_library("prefetch") {
"//components/offline_pages/core",
"//components/offline_pages/core:switches",
"//components/offline_pages/task",
"//components/prefs",
"//components/variations:variations",
"//components/version_info",
"//google_apis",
......@@ -247,6 +248,7 @@ source_set("unit_tests") {
"//components/offline_pages/core:test_support",
"//components/offline_pages/task",
"//components/offline_pages/task:test_support",
"//components/prefs:test_support",
"//components/variations:test_support",
"//components/version_info:channel",
"//net:test_support",
......
include_rules = [
"+components/download/internal/test",
"+components/download/public",
"+components/prefs",
"+google_apis",
"+components/variations",
"+components/gcm_driver",
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/offline_pages/core/prefetch/prefetch_configuration.h"
#include "components/offline_pages/core/offline_page_feature.h"
namespace offline_pages {
bool PrefetchConfiguration::IsPrefetchingEnabled() {
return IsPrefetchingOfflinePagesEnabled() && IsPrefetchingEnabledBySettings();
}
} // namespace offline_pages
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_OFFLINE_PAGES_CORE_PREFETCH_PREFETCH_CONFIGURATION_H_
#define COMPONENTS_OFFLINE_PAGES_CORE_PREFETCH_PREFETCH_CONFIGURATION_H_
namespace offline_pages {
// Class that interfaces with configuration systems to provide prefetching
// specific configuration information.
class PrefetchConfiguration {
public:
virtual ~PrefetchConfiguration() = default;
// Returns true if all needed flags and settings allow the prefetching of
// offline pages to run. Note that this a runtime value that can change in the
// course of the application lifetime. Should not be overridden by subclasses.
bool IsPrefetchingEnabled();
// Returns true if the user controlled setting allows the prefetching of
// offline pages to run. Note that this a runtime value that can change in the
// course of the application lifetime.
virtual bool IsPrefetchingEnabledBySettings() = 0;
};
} // namespace offline_pages
#endif // COMPONENTS_OFFLINE_PAGES_CORE_PREFETCH_PREFETCH_CONFIGURATION_H_
......@@ -33,18 +33,18 @@
#include "components/offline_pages/core/prefetch/page_bundle_update_task.h"
#include "components/offline_pages/core/prefetch/prefetch_background_task.h"
#include "components/offline_pages/core/prefetch/prefetch_background_task_handler.h"
#include "components/offline_pages/core/prefetch/prefetch_configuration.h"
#include "components/offline_pages/core/prefetch/prefetch_downloader.h"
#include "components/offline_pages/core/prefetch/prefetch_gcm_handler.h"
#include "components/offline_pages/core/prefetch/prefetch_importer.h"
#include "components/offline_pages/core/prefetch/prefetch_network_request_factory.h"
#include "components/offline_pages/core/prefetch/prefetch_prefs.h"
#include "components/offline_pages/core/prefetch/prefetch_service.h"
#include "components/offline_pages/core/prefetch/prefetch_types.h"
#include "components/offline_pages/core/prefetch/sent_get_operation_cleanup_task.h"
#include "components/offline_pages/core/prefetch/stale_entry_finalizer_task.h"
#include "components/offline_pages/core/prefetch/suggested_articles_observer.h"
#include "components/offline_pages/core/prefetch/thumbnail_fetcher.h"
#include "components/offline_pages/task/task.h"
#include "components/prefs/pref_service.h"
#include "url/gurl.h"
namespace offline_pages {
......@@ -57,8 +57,8 @@ void DeleteBackgroundTaskHelper(std::unique_ptr<PrefetchBackgroundTask> task) {
} // namespace
PrefetchDispatcherImpl::PrefetchDispatcherImpl()
: task_queue_(this), weak_factory_(this) {}
PrefetchDispatcherImpl::PrefetchDispatcherImpl(PrefService* pref_service)
: pref_service_(pref_service), task_queue_(this), weak_factory_(this) {}
PrefetchDispatcherImpl::~PrefetchDispatcherImpl() = default;
......@@ -85,7 +85,7 @@ void PrefetchDispatcherImpl::EnsureTaskScheduled() {
void PrefetchDispatcherImpl::AddCandidatePrefetchURLs(
const std::string& name_space,
const std::vector<PrefetchURL>& prefetch_urls) {
if (!service_->GetPrefetchConfiguration()->IsPrefetchingEnabled())
if (!prefetch_prefs::IsEnabled(pref_service_))
return;
service_->GetLogger()->RecordActivity("Dispatcher: Received " +
......@@ -116,7 +116,7 @@ void PrefetchDispatcherImpl::AddCandidatePrefetchURLs(
void PrefetchDispatcherImpl::RemoveAllUnprocessedPrefetchURLs(
const std::string& name_space) {
if (!service_->GetPrefetchConfiguration()->IsPrefetchingEnabled())
if (!prefetch_prefs::IsEnabled(pref_service_))
return;
NOTIMPLEMENTED();
......@@ -124,7 +124,7 @@ void PrefetchDispatcherImpl::RemoveAllUnprocessedPrefetchURLs(
void PrefetchDispatcherImpl::RemovePrefetchURLsByClientId(
const ClientId& client_id) {
if (!service_->GetPrefetchConfiguration()->IsPrefetchingEnabled())
if (!prefetch_prefs::IsEnabled(pref_service_))
return;
PrefetchStore* prefetch_store = service_->GetPrefetchStore();
task_queue_.AddTask(std::make_unique<FinalizeDismissedUrlSuggestionTask>(
......@@ -133,7 +133,7 @@ void PrefetchDispatcherImpl::RemovePrefetchURLsByClientId(
void PrefetchDispatcherImpl::BeginBackgroundTask(
std::unique_ptr<PrefetchBackgroundTask> background_task) {
if (!service_->GetPrefetchConfiguration()->IsPrefetchingEnabled())
if (!prefetch_prefs::IsEnabled(pref_service_))
return;
service_->GetLogger()->RecordActivity(
"Dispatcher: Beginning background task.");
......@@ -225,7 +225,7 @@ void PrefetchDispatcherImpl::QueueActionTasks() {
}
void PrefetchDispatcherImpl::StopBackgroundTask() {
if (!service_->GetPrefetchConfiguration()->IsPrefetchingEnabled())
if (!prefetch_prefs::IsEnabled(pref_service_))
return;
service_->GetLogger()->RecordActivity(
......@@ -258,7 +258,7 @@ void PrefetchDispatcherImpl::DisposeTask() {
void PrefetchDispatcherImpl::GCMOperationCompletedMessageReceived(
const std::string& operation_name) {
if (!service_->GetPrefetchConfiguration()->IsPrefetchingEnabled())
if (!prefetch_prefs::IsEnabled(pref_service_))
return;
service_->GetLogger()->RecordActivity("Dispatcher: Received GCM message.");
......@@ -330,7 +330,7 @@ void PrefetchDispatcherImpl::GeneratePageBundleRequested(
void PrefetchDispatcherImpl::DownloadCompleted(
const PrefetchDownloadResult& download_result) {
if (!service_->GetPrefetchConfiguration()->IsPrefetchingEnabled())
if (!prefetch_prefs::IsEnabled(pref_service_))
return;
service_->GetLogger()->RecordActivity(
......@@ -357,7 +357,7 @@ void PrefetchDispatcherImpl::ItemDownloaded(int64_t offline_id,
void PrefetchDispatcherImpl::ArchiveImported(int64_t offline_id, bool success) {
DCHECK_NE(OfflinePageModel::kInvalidOfflineId, offline_id);
if (!service_->GetPrefetchConfiguration()->IsPrefetchingEnabled())
if (!prefetch_prefs::IsEnabled(pref_service_))
return;
service_->GetLogger()->RecordActivity("Importing archive " +
......
......@@ -18,13 +18,15 @@
#include "components/version_info/channel.h"
#include "net/url_request/url_request_context_getter.h"
class PrefService;
namespace offline_pages {
class PrefetchService;
class PrefetchDispatcherImpl : public PrefetchDispatcher,
public TaskQueue::Delegate {
public:
PrefetchDispatcherImpl();
explicit PrefetchDispatcherImpl(PrefService* pref_service);
~PrefetchDispatcherImpl() override;
// PrefetchDispatcher implementation:
......@@ -107,6 +109,7 @@ class PrefetchDispatcherImpl : public PrefetchDispatcher,
bool is_first_attempt,
const std::string& image_data);
PrefService* pref_service_;
PrefetchService* service_;
TaskQueue task_queue_;
bool needs_pipeline_processing_ = false;
......
......@@ -16,11 +16,11 @@
#include "components/offline_pages/core/prefetch/get_operation_request.h"
#include "components/offline_pages/core/prefetch/mock_thumbnail_fetcher.h"
#include "components/offline_pages/core/prefetch/prefetch_background_task.h"
#include "components/offline_pages/core/prefetch/prefetch_configuration.h"
#include "components/offline_pages/core/prefetch/prefetch_dispatcher_impl.h"
#include "components/offline_pages/core/prefetch/prefetch_importer_impl.h"
#include "components/offline_pages/core/prefetch/prefetch_item.h"
#include "components/offline_pages/core/prefetch/prefetch_network_request_factory.h"
#include "components/offline_pages/core/prefetch/prefetch_prefs.h"
#include "components/offline_pages/core/prefetch/prefetch_request_test_base.h"
#include "components/offline_pages/core/prefetch/prefetch_service.h"
#include "components/offline_pages/core/prefetch/prefetch_service_test_taco.h"
......@@ -30,6 +30,7 @@
#include "components/offline_pages/core/prefetch/test_download_service.h"
#include "components/offline_pages/core/prefetch/test_prefetch_network_request_factory.h"
#include "components/offline_pages/core/stub_offline_page_model.h"
#include "components/prefs/testing_pref_service.h"
#include "components/version_info/channel.h"
#include "net/http/http_status_code.h"
#include "net/url_request/url_request_test_util.h"
......@@ -102,16 +103,6 @@ class TestPrefetchBackgroundTask : public PrefetchBackgroundTask {
base::RepeatingCallback<void(PrefetchBackgroundTaskRescheduleType)> callback_;
};
class TestPrefetchConfiguration : public PrefetchConfiguration {
public:
bool IsPrefetchingEnabledBySettings() override { return enabled_; };
void set_enabled(bool enabled) { enabled_ = enabled; }
private:
bool enabled_ = true;
};
class FakePrefetchNetworkRequestFactory
: public TestPrefetchNetworkRequestFactory {
public:
......@@ -177,9 +168,7 @@ class PrefetchDispatcherTest : public PrefetchRequestTestBase {
}
void DisablePrefetchingInSettings() {
static_cast<TestPrefetchConfiguration*>(
taco_->prefetch_service()->GetPrefetchConfiguration())
->set_enabled(false);
prefetch_prefs::SetPrefetchingEnabledInSettings(&prefs_, false);
}
bool dispatcher_suspended() const { return dispatcher_->suspended_; }
......@@ -234,6 +223,7 @@ class PrefetchDispatcherTest : public PrefetchRequestTestBase {
PrefetchStoreTestUtil store_util_{task_runner()};
base::ScopedTempDir archive_directory_;
TestingPrefServiceSimple prefs_;
private:
std::unique_ptr<PrefetchServiceTestTaco> taco_;
......@@ -257,17 +247,16 @@ PrefetchDispatcherTest::PrefetchDispatcherTest() {
void PrefetchDispatcherTest::SetUp() {
ASSERT_TRUE(archive_directory_.CreateUniqueTempDir());
dispatcher_ = new PrefetchDispatcherImpl();
dispatcher_ = new PrefetchDispatcherImpl(&prefs_);
network_request_factory_ =
new FakePrefetchNetworkRequestFactory(shared_url_loader_factory());
prefetch_prefs::RegisterPrefs(prefs_.registry());
taco_.reset(new PrefetchServiceTestTaco);
store_util_.BuildStore();
taco_->SetPrefetchStore(store_util_.ReleaseStore());
taco_->SetPrefetchDispatcher(base::WrapUnique(dispatcher_));
taco_->SetPrefetchNetworkRequestFactory(
base::WrapUnique(network_request_factory_));
taco_->SetPrefetchConfiguration(
std::make_unique<TestPrefetchConfiguration>());
auto thumbnail_fetcher = std::make_unique<MockThumbnailFetcher>();
thumbnail_fetcher_ = thumbnail_fetcher.get();
taco_->SetThumbnailFetcher(std::move(thumbnail_fetcher));
......
......@@ -44,7 +44,7 @@ class PrefetchDownloadFlowTest : public PrefetchTaskTestBase {
download_client_ = std::make_unique<TestDownloadClient>(downloader.get());
download_service_.set_client(download_client_.get());
prefetch_service_taco_->SetPrefetchDispatcher(
std::make_unique<PrefetchDispatcherImpl>());
std::make_unique<PrefetchDispatcherImpl>(prefs()));
prefetch_service_taco_->SetPrefetchStore(store_util()->ReleaseStore());
prefetch_service_taco_->SetPrefetchDownloader(std::move(downloader));
prefetch_service_taco_->CreatePrefetchService();
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/offline_pages/core/prefetch/prefetch_prefs.h"
#include "components/offline_pages/core/offline_page_feature.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
namespace offline_pages {
namespace prefetch_prefs {
namespace {
// Prefs only accessed in this file
const char kEnabled[] = "offline_prefetch.enabled";
} // namespace
const char kBackoff[] = "offline_prefetch.backoff";
void RegisterPrefs(PrefRegistrySimple* registry) {
registry->RegisterListPref(kBackoff);
registry->RegisterBooleanPref(kEnabled, true);
}
void SetPrefetchingEnabledInSettings(PrefService* prefs, bool enabled) {
prefs->SetBoolean(kEnabled, enabled);
}
bool IsEnabled(PrefService* prefs) {
return IsPrefetchingOfflinePagesEnabled() && prefs->GetBoolean(kEnabled);
}
} // namespace prefetch_prefs
} // namespace offline_pages
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_OFFLINE_PAGES_CORE_PREFETCH_PREFETCH_PREFS_H_
#define COMPONENTS_OFFLINE_PAGES_CORE_PREFETCH_PREFETCH_PREFS_H_
class PrefService;
class PrefRegistrySimple;
namespace offline_pages {
namespace prefetch_prefs {
extern const char kBackoff[];
void RegisterPrefs(PrefRegistrySimple* registry);
// Configures the user controlled setting that enables or disables the
// prefetching of offline pages to run.
void SetPrefetchingEnabledInSettings(PrefService* prefs, bool enabled);
// Returns whether the prefetch feature is enabled. Checks both the feature
// flag and the user-controlled setting, which may change at runtime.
bool IsEnabled(PrefService* prefs);
} // namespace prefetch_prefs
} // namespace offline_pages
#endif // COMPONENTS_OFFLINE_PAGES_CORE_PREFETCH_PREFETCH_PREFS_H_
......@@ -18,7 +18,6 @@ class OfflineEventLogger;
class OfflineMetricsCollector;
class OfflinePageModel;
class PrefetchBackgroundTaskHandler;
class PrefetchConfiguration;
class PrefetchDispatcher;
class PrefetchDownloader;
class PrefetchGCMHandler;
......@@ -82,7 +81,6 @@ class PrefetchService : public KeyedService {
virtual PrefetchStore* GetPrefetchStore() = 0;
virtual PrefetchImporter* GetPrefetchImporter() = 0;
virtual PrefetchBackgroundTaskHandler* GetPrefetchBackgroundTaskHandler() = 0;
virtual PrefetchConfiguration* GetPrefetchConfiguration() = 0;
virtual ThumbnailFetcher* GetThumbnailFetcher() = 0;
virtual OfflinePageModel* GetOfflinePageModel() = 0;
......
......@@ -12,7 +12,6 @@
#include "components/offline_pages/core/client_namespace_constants.h"
#include "components/offline_pages/core/prefetch/offline_metrics_collector.h"
#include "components/offline_pages/core/prefetch/prefetch_background_task_handler.h"
#include "components/offline_pages/core/prefetch/prefetch_configuration.h"
#include "components/offline_pages/core/prefetch/prefetch_dispatcher.h"
#include "components/offline_pages/core/prefetch/prefetch_downloader.h"
#include "components/offline_pages/core/prefetch/prefetch_gcm_handler.h"
......@@ -37,7 +36,6 @@ PrefetchServiceImpl::PrefetchServiceImpl(
std::unique_ptr<PrefetchImporter> prefetch_importer,
std::unique_ptr<PrefetchBackgroundTaskHandler>
prefetch_background_task_handler,
std::unique_ptr<PrefetchConfiguration> prefetch_configuration,
std::unique_ptr<ThumbnailFetcher> thumbnail_fetcher)
: offline_metrics_collector_(std::move(offline_metrics_collector)),
prefetch_dispatcher_(std::move(dispatcher)),
......@@ -50,7 +48,6 @@ PrefetchServiceImpl::PrefetchServiceImpl(
prefetch_importer_(std::move(prefetch_importer)),
prefetch_background_task_handler_(
std::move(prefetch_background_task_handler)),
prefetch_configuration_(std::move(prefetch_configuration)),
thumbnail_fetcher_(std::move(thumbnail_fetcher)) {
prefetch_dispatcher_->SetService(this);
prefetch_downloader_->SetPrefetchService(this);
......@@ -133,10 +130,6 @@ PrefetchServiceImpl::GetPrefetchBackgroundTaskHandler() {
return prefetch_background_task_handler_.get();
}
PrefetchConfiguration* PrefetchServiceImpl::GetPrefetchConfiguration() {
return prefetch_configuration_.get();
}
ThumbnailFetcher* PrefetchServiceImpl::GetThumbnailFetcher() {
return thumbnail_fetcher_.get();
}
......
......@@ -28,7 +28,6 @@ class PrefetchServiceImpl : public PrefetchService {
std::unique_ptr<PrefetchDownloader> prefetch_downloader,
std::unique_ptr<PrefetchImporter> prefetch_importer,
std::unique_ptr<PrefetchBackgroundTaskHandler> background_task_handler,
std::unique_ptr<PrefetchConfiguration> prefetch_configuration,
std::unique_ptr<ThumbnailFetcher> thumbnail_fetcher);
~PrefetchServiceImpl() override;
......@@ -53,7 +52,6 @@ class PrefetchServiceImpl : public PrefetchService {
PrefetchDownloader* GetPrefetchDownloader() override;
PrefetchImporter* GetPrefetchImporter() override;
PrefetchBackgroundTaskHandler* GetPrefetchBackgroundTaskHandler() override;
PrefetchConfiguration* GetPrefetchConfiguration() override;
ThumbnailFetcher* GetThumbnailFetcher() override;
// KeyedService implementation:
......@@ -73,7 +71,6 @@ class PrefetchServiceImpl : public PrefetchService {
std::unique_ptr<PrefetchImporter> prefetch_importer_;
std::unique_ptr<PrefetchBackgroundTaskHandler>
prefetch_background_task_handler_;
std::unique_ptr<PrefetchConfiguration> prefetch_configuration_;
std::unique_ptr<ThumbnailFetcher> thumbnail_fetcher_;
DISALLOW_COPY_AND_ASSIGN(PrefetchServiceImpl);
......
......@@ -13,7 +13,6 @@
#include "components/offline_pages/core/prefetch/mock_thumbnail_fetcher.h"
#include "components/offline_pages/core/prefetch/offline_metrics_collector.h"
#include "components/offline_pages/core/prefetch/prefetch_background_task_handler.h"
#include "components/offline_pages/core/prefetch/prefetch_configuration.h"
#include "components/offline_pages/core/prefetch/prefetch_dispatcher.h"
#include "components/offline_pages/core/prefetch/prefetch_downloader.h"
#include "components/offline_pages/core/prefetch/prefetch_downloader_impl.h"
......@@ -54,17 +53,6 @@ class StubPrefetchBackgroundTaskHandler : public PrefetchBackgroundTaskHandler {
DISALLOW_COPY_AND_ASSIGN(StubPrefetchBackgroundTaskHandler);
};
class StubPrefetchConfiguration : public PrefetchConfiguration {
public:
StubPrefetchConfiguration() = default;
~StubPrefetchConfiguration() override = default;
bool IsPrefetchingEnabledBySettings() override { return true; };
private:
DISALLOW_COPY_AND_ASSIGN(StubPrefetchConfiguration);
};
} // namespace
PrefetchServiceTestTaco::PrefetchServiceTestTaco() {
......@@ -88,7 +76,6 @@ PrefetchServiceTestTaco::PrefetchServiceTestTaco() {
suggested_articles_observer_->GetTestingArticles();
prefetch_background_task_handler_ =
std::make_unique<StubPrefetchBackgroundTaskHandler>();
prefetch_configuration_ = std::make_unique<StubPrefetchConfiguration>();
offline_page_model_ = std::make_unique<StubOfflinePageModel>();
thumbnail_fetcher_ = std::make_unique<MockThumbnailFetcher>();
}
......@@ -157,12 +144,6 @@ void PrefetchServiceTestTaco::SetPrefetchBackgroundTaskHandler(
std::move(prefetch_background_task_handler);
}
void PrefetchServiceTestTaco::SetPrefetchConfiguration(
std::unique_ptr<PrefetchConfiguration> prefetch_configuration) {
CHECK(!prefetch_service_);
prefetch_configuration_ = std::move(prefetch_configuration);
}
void PrefetchServiceTestTaco::SetThumbnailFetcher(
std::unique_ptr<ThumbnailFetcher> thumbnail_fetcher) {
CHECK(!prefetch_service_);
......@@ -184,7 +165,7 @@ void PrefetchServiceTestTaco::CreatePrefetchService() {
std::move(suggested_articles_observer_), std::move(prefetch_downloader_),
std::move(prefetch_importer_),
std::move(prefetch_background_task_handler_),
std::move(prefetch_configuration_), std::move(thumbnail_fetcher_));
std::move(thumbnail_fetcher_));
}
std::unique_ptr<PrefetchService>
......
......@@ -15,7 +15,6 @@ namespace offline_pages {
class OfflineMetricsCollector;
class OfflinePageModel;
class PrefetchBackgroundTaskHandler;
class PrefetchConfiguration;
class PrefetchDispatcher;
class PrefetchDownloader;
class PrefetchGCMHandler;
......@@ -62,8 +61,6 @@ class PrefetchServiceTestTaco {
void SetPrefetchBackgroundTaskHandler(
std::unique_ptr<PrefetchBackgroundTaskHandler>
prefetch_background_task_handler);
void SetPrefetchConfiguration(
std::unique_ptr<PrefetchConfiguration> prefetch_configuration);
// Default type: MockThumbnailFetcher.
void SetThumbnailFetcher(std::unique_ptr<ThumbnailFetcher> thumbnail_fetcher);
void SetOfflinePageModel(
......@@ -97,7 +94,6 @@ class PrefetchServiceTestTaco {
std::unique_ptr<PrefetchImporter> prefetch_importer_;
std::unique_ptr<PrefetchBackgroundTaskHandler>
prefetch_background_task_handler_;
std::unique_ptr<PrefetchConfiguration> prefetch_configuration_;
std::unique_ptr<PrefetchService> prefetch_service_;
std::unique_ptr<ThumbnailFetcher> thumbnail_fetcher_;
std::unique_ptr<OfflinePageModel> offline_page_model_;
......
......@@ -5,6 +5,7 @@
#include "components/offline_pages/core/prefetch/prefetch_task_test_base.h"
#include "components/offline_pages/core/offline_store_utils.h"
#include "components/offline_pages/core/prefetch/prefetch_prefs.h"
#include "components/offline_pages/core/prefetch/store/prefetch_store_test_util.h"
#include "components/offline_pages/task/task_test_base.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -26,6 +27,7 @@ PrefetchTaskTestBase::~PrefetchTaskTestBase() = default;
void PrefetchTaskTestBase::SetUp() {
TaskTestBase::SetUp();
prefetch_prefs::RegisterPrefs(prefs_.registry());
store_test_util_.BuildStoreInMemory();
}
......
......@@ -13,6 +13,7 @@
#include "components/offline_pages/core/prefetch/store/prefetch_store_test_util.h"
#include "components/offline_pages/core/prefetch/test_prefetch_network_request_factory.h"
#include "components/offline_pages/task/task_test_base.h"
#include "components/prefs/testing_pref_service.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/test/test_url_loader_factory.h"
......@@ -67,7 +68,10 @@ class PrefetchTaskTestBase : public TaskTestBase {
MockPrefetchItemGenerator* item_generator() { return &item_generator_; }
TestingPrefServiceSimple* prefs() { return &prefs_; }
private:
TestingPrefServiceSimple prefs_;
network::TestURLLoaderFactory test_url_loader_factory_;
scoped_refptr<network::SharedURLLoaderFactory>
test_shared_url_loader_factory_;
......
......@@ -56,10 +56,6 @@ StubPrefetchService::GetPrefetchBackgroundTaskHandler() {
return nullptr;
}
PrefetchConfiguration* StubPrefetchService::GetPrefetchConfiguration() {
return nullptr;
}
ThumbnailFetcher* StubPrefetchService::GetThumbnailFetcher() {
return nullptr;
}
......
......@@ -27,7 +27,6 @@ class StubPrefetchService : public PrefetchService {
PrefetchStore* GetPrefetchStore() override;
PrefetchImporter* GetPrefetchImporter() override;
PrefetchBackgroundTaskHandler* GetPrefetchBackgroundTaskHandler() override;
PrefetchConfiguration* GetPrefetchConfiguration() override;
ThumbnailFetcher* GetThumbnailFetcher() override;
OfflinePageModel* GetOfflinePageModel() override;
SuggestedArticlesObserver* GetSuggestedArticlesObserver() override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment