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

Side by Side Diff: components/precache/content/precache_manager.cc

Issue 2544613003: Disable precache if data_reduction_proxy enabled. (Closed)
Patch Set: Rebase. Created 4 years 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "components/precache/content/precache_manager.h" 5 #include "components/precache/content/precache_manager.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/metrics/field_trial.h" 14 #include "base/metrics/field_trial.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett ings.h"
17 #include "components/history/core/browser/history_service.h" 18 #include "components/history/core/browser/history_service.h"
18 #include "components/precache/core/precache_database.h" 19 #include "components/precache/core/precache_database.h"
19 #include "components/precache/core/precache_switches.h" 20 #include "components/precache/core/precache_switches.h"
20 #include "components/precache/core/proto/unfinished_work.pb.h" 21 #include "components/precache/core/proto/unfinished_work.pb.h"
21 #include "components/prefs/pref_service.h" 22 #include "components/prefs/pref_service.h"
22 #include "components/sync/driver/sync_service.h" 23 #include "components/sync/driver/sync_service.h"
23 #include "components/variations/metrics_util.h" 24 #include "components/variations/metrics_util.h"
24 #include "components/variations/variations_associated_data.h" 25 #include "components/variations/variations_associated_data.h"
25 #include "content/public/browser/browser_context.h" 26 #include "content/public/browser/browser_context.h"
26 #include "content/public/browser/browser_thread.h" 27 #include "content/public/browser/browser_thread.h"
27 #include "content/public/browser/storage_partition.h" 28 #include "content/public/browser/storage_partition.h"
28 #include "net/base/network_change_notifier.h" 29 #include "net/base/network_change_notifier.h"
29 30
30 using content::BrowserThread; 31 using content::BrowserThread;
31 32
32 namespace { 33 namespace {
33 34
34 const char kPrecacheFieldTrialName[] = "Precache"; 35 const char kPrecacheFieldTrialName[] = "Precache";
35 const char kPrecacheFieldTrialEnabledGroup[] = "Enabled"; 36 const char kPrecacheFieldTrialEnabledGroup[] = "Enabled";
36 const char kPrecacheFieldTrialControlGroup[] = "Control"; 37 const char kPrecacheFieldTrialControlGroup[] = "Control";
37 const char kConfigURLParam[] = "config_url"; 38 const char kConfigURLParam[] = "config_url";
38 const char kManifestURLPrefixParam[] = "manifest_url_prefix"; 39 const char kManifestURLPrefixParam[] = "manifest_url_prefix";
40 const char kDataReductionProxyParam[] = "disable_if_data_reduction_proxy";
39 const size_t kNumTopHosts = 100; 41 const size_t kNumTopHosts = 100;
40 42
41 } // namespace 43 } // namespace
42 44
43 namespace precache { 45 namespace precache {
44 46
45 size_t NumTopHosts() { 47 size_t NumTopHosts() {
46 return kNumTopHosts; 48 return kNumTopHosts;
47 } 49 }
48 50
49 PrecacheManager::PrecacheManager( 51 PrecacheManager::PrecacheManager(
50 content::BrowserContext* browser_context, 52 content::BrowserContext* browser_context,
51 const syncer::SyncService* const sync_service, 53 const syncer::SyncService* const sync_service,
52 const history::HistoryService* const history_service, 54 const history::HistoryService* const history_service,
55 const data_reduction_proxy::DataReductionProxySettings*
56 data_reduction_proxy_settings,
53 const base::FilePath& db_path, 57 const base::FilePath& db_path,
54 std::unique_ptr<PrecacheDatabase> precache_database) 58 std::unique_ptr<PrecacheDatabase> precache_database)
55 : browser_context_(browser_context), 59 : browser_context_(browser_context),
56 sync_service_(sync_service), 60 sync_service_(sync_service),
57 history_service_(history_service), 61 history_service_(history_service),
62 data_reduction_proxy_settings_(data_reduction_proxy_settings),
58 is_precaching_(false) { 63 is_precaching_(false) {
59 precache_database_ = std::move(precache_database); 64 precache_database_ = std::move(precache_database);
60 BrowserThread::PostTask( 65 BrowserThread::PostTask(
61 BrowserThread::DB, FROM_HERE, 66 BrowserThread::DB, FROM_HERE,
62 base::Bind(base::IgnoreResult(&PrecacheDatabase::Init), 67 base::Bind(base::IgnoreResult(&PrecacheDatabase::Init),
63 base::Unretained(precache_database_.get()), db_path)); 68 base::Unretained(precache_database_.get()), db_path));
64 } 69 }
65 70
66 PrecacheManager::~PrecacheManager() { 71 PrecacheManager::~PrecacheManager() {
67 // DeleteSoon posts a non-nestable task to the task runner, so any previously 72 // DeleteSoon posts a non-nestable task to the task runner, so any previously
(...skipping 24 matching lines...) Expand all
92 base::StartsWith( 97 base::StartsWith(
93 base::FieldTrialList::FindFullName(kPrecacheFieldTrialName), 98 base::FieldTrialList::FindFullName(kPrecacheFieldTrialName),
94 kPrecacheFieldTrialControlGroup, base::CompareCase::SENSITIVE); 99 kPrecacheFieldTrialControlGroup, base::CompareCase::SENSITIVE);
95 } 100 }
96 101
97 bool PrecacheManager::IsPrecachingAllowed() const { 102 bool PrecacheManager::IsPrecachingAllowed() const {
98 return PrecachingAllowed() == AllowedType::ALLOWED; 103 return PrecachingAllowed() == AllowedType::ALLOWED;
99 } 104 }
100 105
101 PrecacheManager::AllowedType PrecacheManager::PrecachingAllowed() const { 106 PrecacheManager::AllowedType PrecacheManager::PrecachingAllowed() const {
107 bool disable_if_proxy = !variations::GetVariationParamValue(
108 kPrecacheFieldTrialName, kDataReductionProxyParam).empty();
109 if (disable_if_proxy &&
110 (!data_reduction_proxy_settings_ ||
111 data_reduction_proxy_settings_->IsDataReductionProxyEnabled()))
112 return AllowedType::DISALLOWED;
113
102 if (!(sync_service_ && sync_service_->IsEngineInitialized())) 114 if (!(sync_service_ && sync_service_->IsEngineInitialized()))
103 return AllowedType::PENDING; 115 return AllowedType::PENDING;
104 116
105 // SyncService delegates to SyncPrefs, which must be called on the UI thread. 117 // SyncService delegates to SyncPrefs, which must be called on the UI thread.
106 if (history_service_ && 118 if (history_service_ &&
107 sync_service_->GetActiveDataTypes().Has(syncer::SESSIONS) && 119 sync_service_->GetActiveDataTypes().Has(syncer::SESSIONS) &&
108 !sync_service_->GetEncryptedDataTypes().Has(syncer::SESSIONS)) 120 !sync_service_->GetEncryptedDataTypes().Has(syncer::SESSIONS))
109 return AllowedType::ALLOWED; 121 return AllowedType::ALLOWED;
110 122
111 return AllowedType::DISALLOWED; 123 return AllowedType::DISALLOWED;
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 this)); 367 this));
356 precache_fetcher_->Start(); 368 precache_fetcher_->Start();
357 } 369 }
358 370
359 void PrecacheManager::OnHostsReceivedThenDone( 371 void PrecacheManager::OnHostsReceivedThenDone(
360 const history::TopHostsList& host_counts) { 372 const history::TopHostsList& host_counts) {
361 OnDone(); 373 OnDone();
362 } 374 }
363 375
364 } // namespace precache 376 } // namespace precache
OLDNEW
« no previous file with comments | « components/precache/content/precache_manager.h ('k') | components/precache/content/precache_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698