Chromium Code Reviews| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 44 | 44 |
| 45 size_t NumTopHosts() { | 45 size_t NumTopHosts() { |
| 46 return kNumTopHosts; | 46 return kNumTopHosts; |
| 47 } | 47 } |
| 48 | 48 |
| 49 PrecacheManager::PrecacheManager( | 49 PrecacheManager::PrecacheManager( |
| 50 content::BrowserContext* browser_context, | 50 content::BrowserContext* browser_context, |
| 51 const syncer::SyncService* const sync_service, | 51 const syncer::SyncService* const sync_service, |
| 52 const history::HistoryService* const history_service, | 52 const history::HistoryService* const history_service, |
| 53 const base::FilePath& db_path, | 53 const base::FilePath& db_path, |
| 54 std::unique_ptr<PrecacheDatabase> precache_database) | 54 std::unique_ptr<PrecacheDatabase> precache_database, |
| 55 const base::Callback<void(const base::Time&)>& | |
| 56 register_synthetic_field_trial_callback) | |
| 55 : browser_context_(browser_context), | 57 : browser_context_(browser_context), |
| 56 sync_service_(sync_service), | 58 sync_service_(sync_service), |
| 57 history_service_(history_service), | 59 history_service_(history_service), |
| 58 is_precaching_(false) { | 60 is_precaching_(false), |
| 61 register_synthetic_field_trial_callback_( | |
| 62 register_synthetic_field_trial_callback) { | |
| 59 precache_database_ = std::move(precache_database); | 63 precache_database_ = std::move(precache_database); |
| 60 BrowserThread::PostTask( | 64 BrowserThread::PostTask( |
| 61 BrowserThread::DB, FROM_HERE, | 65 BrowserThread::DB, FROM_HERE, |
| 62 base::Bind(base::IgnoreResult(&PrecacheDatabase::Init), | 66 base::Bind(base::IgnoreResult(&PrecacheDatabase::Init), |
| 63 base::Unretained(precache_database_.get()), db_path)); | 67 base::Unretained(precache_database_.get()), db_path)); |
| 68 BrowserThread::PostTaskAndReplyWithResult( | |
|
twifkak
2016/12/08 21:49:22
Good idea, sticking it in the PrecacheManager cons
| |
| 69 BrowserThread::DB, FROM_HERE, | |
| 70 base::Bind(&PrecacheDatabase::GetLastPrecacheTimestamp, | |
| 71 base::Unretained(precache_database_.get())), | |
| 72 base::Bind(&PrecacheManager::RegisterSyntheticFieldTrial, AsWeakPtr())); | |
| 64 } | 73 } |
| 65 | 74 |
| 66 PrecacheManager::~PrecacheManager() { | 75 PrecacheManager::~PrecacheManager() { |
| 67 // DeleteSoon posts a non-nestable task to the task runner, so any previously | 76 // DeleteSoon posts a non-nestable task to the task runner, so any previously |
| 68 // posted tasks that rely on an Unretained precache_database_ will finish | 77 // posted tasks that rely on an Unretained precache_database_ will finish |
| 69 // before it is deleted. | 78 // before it is deleted. |
| 70 BrowserThread::DeleteSoon(BrowserThread::DB, FROM_HERE, | 79 BrowserThread::DeleteSoon(BrowserThread::DB, FROM_HERE, |
| 71 precache_database_.release()); | 80 precache_database_.release()); |
| 72 } | 81 } |
| 73 | 82 |
| 83 void PrecacheManager::RegisterSyntheticFieldTrial( | |
| 84 const base::Time& last_precache_time) { | |
| 85 register_synthetic_field_trial_callback_.Run(last_precache_time); | |
| 86 } | |
| 87 | |
| 74 bool PrecacheManager::IsInExperimentGroup() const { | 88 bool PrecacheManager::IsInExperimentGroup() const { |
| 75 // Verify IsPrecachingAllowed() before calling FieldTrialList::FindFullName(). | 89 // Verify IsPrecachingAllowed() before calling FieldTrialList::FindFullName(). |
| 76 // This is because field trials are only assigned when requested. This allows | 90 // This is because field trials are only assigned when requested. This allows |
| 77 // us to create Control and Experiment groups that are limited to users for | 91 // us to create Control and Experiment groups that are limited to users for |
| 78 // whom PrecachingAllowed() is true, thus accentuating the impact of | 92 // whom PrecachingAllowed() is true, thus accentuating the impact of |
| 79 // precaching. | 93 // precaching. |
| 80 return IsPrecachingAllowed() && | 94 return IsPrecachingAllowed() && |
| 81 (base::StartsWith( | 95 (base::StartsWith( |
| 82 base::FieldTrialList::FindFullName(kPrecacheFieldTrialName), | 96 base::FieldTrialList::FindFullName(kPrecacheFieldTrialName), |
| 83 kPrecacheFieldTrialEnabledGroup, base::CompareCase::SENSITIVE) || | 97 kPrecacheFieldTrialEnabledGroup, base::CompareCase::SENSITIVE) || |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 355 this)); | 369 this)); |
| 356 precache_fetcher_->Start(); | 370 precache_fetcher_->Start(); |
| 357 } | 371 } |
| 358 | 372 |
| 359 void PrecacheManager::OnHostsReceivedThenDone( | 373 void PrecacheManager::OnHostsReceivedThenDone( |
| 360 const history::TopHostsList& host_counts) { | 374 const history::TopHostsList& host_counts) { |
| 361 OnDone(); | 375 OnDone(); |
| 362 } | 376 } |
| 363 | 377 |
| 364 } // namespace precache | 378 } // namespace precache |
| OLD | NEW |