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

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

Issue 1176253002: Fix IsPrecachingAllowed() to check Sync instead of Data Saver. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove explicit, add consts, remove user_prefs dep. Created 5 years, 6 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
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/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/metrics/field_trial.h" 15 #include "base/metrics/field_trial.h"
16 #include "base/prefs/pref_service.h" 16 #include "base/prefs/pref_service.h"
17 #include "base/time/time.h" 17 #include "base/time/time.h"
18 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_ names.h"
19 #include "components/history/core/browser/history_service.h" 18 #include "components/history/core/browser/history_service.h"
20 #include "components/precache/core/precache_database.h" 19 #include "components/precache/core/precache_database.h"
21 #include "components/precache/core/precache_switches.h" 20 #include "components/precache/core/precache_switches.h"
22 #include "components/user_prefs/user_prefs.h" 21 #include "components/sync_driver/sync_service.h"
23 #include "components/variations/variations_associated_data.h" 22 #include "components/variations/variations_associated_data.h"
24 #include "content/public/browser/browser_context.h" 23 #include "content/public/browser/browser_context.h"
25 #include "content/public/browser/browser_thread.h" 24 #include "content/public/browser/browser_thread.h"
26 #include "net/base/network_change_notifier.h" 25 #include "net/base/network_change_notifier.h"
27 26
28 using content::BrowserThread; 27 using content::BrowserThread;
29 28
30 namespace { 29 namespace {
31 30
32 const char kPrecacheFieldTrialName[] = "Precache"; 31 const char kPrecacheFieldTrialName[] = "Precache";
33 const char kPrecacheFieldTrialEnabledGroup[] = "Enabled"; 32 const char kPrecacheFieldTrialEnabledGroup[] = "Enabled";
34 const char kManifestURLPrefixParam[] = "manifest_url_prefix"; 33 const char kManifestURLPrefixParam[] = "manifest_url_prefix";
35 const int kNumTopHosts = 100; 34 const int kNumTopHosts = 100;
36 35
37 } // namespace 36 } // namespace
38 37
39 namespace precache { 38 namespace precache {
40 39
41 int NumTopHosts() { 40 int NumTopHosts() {
42 return kNumTopHosts; 41 return kNumTopHosts;
43 } 42 }
44 43
45 PrecacheManager::PrecacheManager(content::BrowserContext* browser_context) 44 PrecacheManager::PrecacheManager(content::BrowserContext* browser_context,
45 sync_driver::SyncService* sync_service)
46 : browser_context_(browser_context), 46 : browser_context_(browser_context),
47 sync_service_(sync_service),
47 precache_database_(new PrecacheDatabase()), 48 precache_database_(new PrecacheDatabase()),
48 is_precaching_(false) { 49 is_precaching_(false) {
49 base::FilePath db_path(browser_context_->GetPath().Append( 50 base::FilePath db_path(browser_context_->GetPath().Append(
50 base::FilePath(FILE_PATH_LITERAL("PrecacheDatabase")))); 51 base::FilePath(FILE_PATH_LITERAL("PrecacheDatabase"))));
51 52
52 BrowserThread::PostTask( 53 BrowserThread::PostTask(
53 BrowserThread::DB, FROM_HERE, 54 BrowserThread::DB, FROM_HERE,
54 base::Bind(base::IgnoreResult(&PrecacheDatabase::Init), 55 base::Bind(base::IgnoreResult(&PrecacheDatabase::Init),
55 precache_database_, db_path)); 56 precache_database_, db_path));
56 } 57 }
57 58
58 PrecacheManager::~PrecacheManager() {} 59 PrecacheManager::~PrecacheManager() {}
59 60
60 // static 61 // static
61 bool PrecacheManager::IsPrecachingEnabled() { 62 bool PrecacheManager::IsPrecachingEnabled() {
62 return base::FieldTrialList::FindFullName(kPrecacheFieldTrialName) == 63 return base::FieldTrialList::FindFullName(kPrecacheFieldTrialName) ==
63 kPrecacheFieldTrialEnabledGroup || 64 kPrecacheFieldTrialEnabledGroup ||
64 base::CommandLine::ForCurrentProcess()->HasSwitch( 65 base::CommandLine::ForCurrentProcess()->HasSwitch(
65 switches::kEnablePrecache); 66 switches::kEnablePrecache);
66 } 67 }
67 68
68 bool PrecacheManager::IsPrecachingAllowed() { 69 bool PrecacheManager::IsPrecachingAllowed() {
69 DCHECK_CURRENTLY_ON(BrowserThread::UI); 70 return sync_service_ && sync_service_->CanSyncStart() &&
70 return user_prefs::UserPrefs::Get(browser_context_)->GetBoolean( 71 sync_service_->HasSyncSetupCompleted() &&
71 data_reduction_proxy::prefs::kDataReductionProxyEnabled); 72 sync_service_->GetPreferredDataTypes().Has(syncer::SESSIONS) &&
73 !sync_service_->GetEncryptedDataTypes().Has(syncer::SESSIONS);
Nicolas Zea 2015/06/18 18:25:48 One correction (which I think was overlooked in th
72 } 74 }
73 75
74 void PrecacheManager::StartPrecaching( 76 void PrecacheManager::StartPrecaching(
75 const PrecacheCompletionCallback& precache_completion_callback, 77 const PrecacheCompletionCallback& precache_completion_callback,
76 const history::HistoryService& history_service) { 78 const history::HistoryService& history_service) {
77 DCHECK_CURRENTLY_ON(BrowserThread::UI); 79 DCHECK_CURRENTLY_ON(BrowserThread::UI);
78 80
79 if (is_precaching_) { 81 if (is_precaching_) {
80 DLOG(WARNING) << "Cannot start precaching because precaching is already " 82 DLOG(WARNING) << "Cannot start precaching because precaching is already "
81 "in progress."; 83 "in progress.";
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 // Start precaching. 189 // Start precaching.
188 precache_fetcher_.reset( 190 precache_fetcher_.reset(
189 new PrecacheFetcher(hosts, browser_context_->GetRequestContext(), 191 new PrecacheFetcher(hosts, browser_context_->GetRequestContext(),
190 variations::GetVariationParamValue( 192 variations::GetVariationParamValue(
191 kPrecacheFieldTrialName, kManifestURLPrefixParam), 193 kPrecacheFieldTrialName, kManifestURLPrefixParam),
192 this)); 194 this));
193 precache_fetcher_->Start(); 195 precache_fetcher_->Start();
194 } 196 }
195 197
196 } // namespace precache 198 } // namespace precache
OLDNEW
« no previous file with comments | « components/precache/content/precache_manager.h ('k') | components/precache/content/precache_manager_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698