OLD | NEW |
---|---|
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 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
56 return kNumTopHosts; | 56 return kNumTopHosts; |
57 } | 57 } |
58 | 58 |
59 PrecacheManager::PrecacheManager( | 59 PrecacheManager::PrecacheManager( |
60 content::BrowserContext* browser_context, | 60 content::BrowserContext* browser_context, |
61 const syncer::SyncService* const sync_service, | 61 const syncer::SyncService* const sync_service, |
62 const history::HistoryService* const history_service, | 62 const history::HistoryService* const history_service, |
63 const data_reduction_proxy::DataReductionProxySettings* | 63 const data_reduction_proxy::DataReductionProxySettings* |
64 data_reduction_proxy_settings, | 64 data_reduction_proxy_settings, |
65 const base::FilePath& db_path, | 65 const base::FilePath& db_path, |
66 std::unique_ptr<PrecacheDatabase> precache_database) | 66 std::unique_ptr<PrecacheDatabase> precache_database, |
67 const base::Callback<void(const base::Time&)>& | |
68 register_synthetic_field_trial_callback) | |
67 : browser_context_(browser_context), | 69 : browser_context_(browser_context), |
68 sync_service_(sync_service), | 70 sync_service_(sync_service), |
69 history_service_(history_service), | 71 history_service_(history_service), |
70 data_reduction_proxy_settings_(data_reduction_proxy_settings), | 72 data_reduction_proxy_settings_(data_reduction_proxy_settings), |
71 is_precaching_(false) { | 73 is_precaching_(false), |
74 register_synthetic_field_trial_callback_( | |
75 register_synthetic_field_trial_callback) { | |
72 precache_database_ = std::move(precache_database); | 76 precache_database_ = std::move(precache_database); |
73 BrowserThread::PostTask( | 77 BrowserThread::PostTask( |
74 BrowserThread::DB, FROM_HERE, | 78 BrowserThread::DB, FROM_HERE, |
75 base::Bind(base::IgnoreResult(&PrecacheDatabase::Init), | 79 base::Bind(base::IgnoreResult(&PrecacheDatabase::Init), |
76 base::Unretained(precache_database_.get()), db_path)); | 80 base::Unretained(precache_database_.get()), db_path)); |
81 BrowserThread::PostTaskAndReplyWithResult( | |
jamartin
2016/12/21 23:54:33
There are no race conditions between these two tas
twifkak
2017/01/05 23:53:14
Assuming you mean the potential race between Init
| |
82 BrowserThread::DB, FROM_HERE, | |
83 base::Bind(&PrecacheDatabase::GetLastPrecacheTimestamp, | |
84 base::Unretained(precache_database_.get())), | |
85 base::Bind(&PrecacheManager::RegisterSyntheticFieldTrial, AsWeakPtr())); | |
77 } | 86 } |
78 | 87 |
79 PrecacheManager::~PrecacheManager() { | 88 PrecacheManager::~PrecacheManager() { |
80 // DeleteSoon posts a non-nestable task to the task runner, so any previously | 89 // DeleteSoon posts a non-nestable task to the task runner, so any previously |
81 // posted tasks that rely on an Unretained precache_database_ will finish | 90 // posted tasks that rely on an Unretained precache_database_ will finish |
82 // before it is deleted. | 91 // before it is deleted. |
83 BrowserThread::DeleteSoon(BrowserThread::DB, FROM_HERE, | 92 BrowserThread::DeleteSoon(BrowserThread::DB, FROM_HERE, |
84 precache_database_.release()); | 93 precache_database_.release()); |
85 } | 94 } |
86 | 95 |
96 void PrecacheManager::RegisterSyntheticFieldTrial( | |
97 const base::Time& last_precache_time) { | |
98 register_synthetic_field_trial_callback_.Run(last_precache_time); | |
99 } | |
100 | |
87 bool PrecacheManager::IsInExperimentGroup() const { | 101 bool PrecacheManager::IsInExperimentGroup() const { |
88 // Verify IsPrecachingAllowed() before calling FieldTrialList::FindFullName(). | 102 // Verify IsPrecachingAllowed() before calling FieldTrialList::FindFullName(). |
89 // This is because field trials are only assigned when requested. This allows | 103 // This is because field trials are only assigned when requested. This allows |
90 // us to create Control and Experiment groups that are limited to users for | 104 // us to create Control and Experiment groups that are limited to users for |
91 // whom PrecachingAllowed() is true, thus accentuating the impact of | 105 // whom PrecachingAllowed() is true, thus accentuating the impact of |
92 // precaching. | 106 // precaching. |
93 return IsPrecachingAllowed() && | 107 return IsPrecachingAllowed() && |
94 (base::StartsWith( | 108 (base::StartsWith( |
95 base::FieldTrialList::FindFullName(kPrecacheFieldTrialName), | 109 base::FieldTrialList::FindFullName(kPrecacheFieldTrialName), |
96 kPrecacheFieldTrialEnabledGroup, base::CompareCase::SENSITIVE) || | 110 kPrecacheFieldTrialEnabledGroup, base::CompareCase::SENSITIVE) || |
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
481 this)); | 495 this)); |
482 precache_fetcher_->Start(); | 496 precache_fetcher_->Start(); |
483 } | 497 } |
484 | 498 |
485 void PrecacheManager::OnHostsReceivedThenDone( | 499 void PrecacheManager::OnHostsReceivedThenDone( |
486 const history::TopHostsList& host_counts) { | 500 const history::TopHostsList& host_counts) { |
487 OnDone(); | 501 OnDone(); |
488 } | 502 } |
489 | 503 |
490 } // namespace precache | 504 } // namespace precache |
OLD | NEW |