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 18 matching lines...) Expand all Loading... | |
| 29 | 29 |
| 30 using content::BrowserThread; | 30 using content::BrowserThread; |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 const char kPrecacheFieldTrialName[] = "Precache"; | 34 const char kPrecacheFieldTrialName[] = "Precache"; |
| 35 const char kPrecacheFieldTrialEnabledGroup[] = "Enabled"; | 35 const char kPrecacheFieldTrialEnabledGroup[] = "Enabled"; |
| 36 const char kPrecacheFieldTrialControlGroup[] = "Control"; | 36 const char kPrecacheFieldTrialControlGroup[] = "Control"; |
| 37 const char kConfigURLParam[] = "config_url"; | 37 const char kConfigURLParam[] = "config_url"; |
| 38 const char kManifestURLPrefixParam[] = "manifest_url_prefix"; | 38 const char kManifestURLPrefixParam[] = "manifest_url_prefix"; |
| 39 const char kGlobalRankingParam[] = "global_ranking"; | |
| 39 const size_t kNumTopHosts = 100; | 40 const size_t kNumTopHosts = 100; |
| 40 | 41 |
| 41 } // namespace | 42 } // namespace |
| 42 | 43 |
| 43 namespace precache { | 44 namespace precache { |
| 44 | 45 |
| 45 size_t NumTopHosts() { | 46 size_t NumTopHosts() { |
| 46 return kNumTopHosts; | 47 return kNumTopHosts; |
| 47 } | 48 } |
| 48 | 49 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 BrowserThread::PostTaskAndReplyWithResult( | 132 BrowserThread::PostTaskAndReplyWithResult( |
| 132 BrowserThread::DB, | 133 BrowserThread::DB, |
| 133 FROM_HERE, | 134 FROM_HERE, |
| 134 base::Bind(&PrecacheDatabase::GetUnfinishedWork, | 135 base::Bind(&PrecacheDatabase::GetUnfinishedWork, |
| 135 base::Unretained(precache_database_.get())), | 136 base::Unretained(precache_database_.get())), |
| 136 base::Bind(&PrecacheManager::OnGetUnfinishedWorkDone, AsWeakPtr())); | 137 base::Bind(&PrecacheManager::OnGetUnfinishedWorkDone, AsWeakPtr())); |
| 137 } | 138 } |
| 138 | 139 |
| 139 void PrecacheManager::OnGetUnfinishedWorkDone( | 140 void PrecacheManager::OnGetUnfinishedWorkDone( |
| 140 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work) { | 141 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work) { |
| 141 if (!unfinished_work->has_start_time() || | 142 if (!unfinished_work->has_start_time()) |
| 142 base::Time::Now() - base::Time::FromInternalValue( | 143 unfinished_work->set_start_time(base::Time::Now().ToInternalValue()); |
| 143 unfinished_work->start_time()) > base::TimeDelta::FromHours(6)) { | 144 if (base::Time::Now() - |
| 145 base::Time::FromInternalValue(unfinished_work->start_time()) > | |
| 146 base::TimeDelta::FromHours(6)) { | |
| 144 PrecacheFetcher::RecordCompletionStatistics( | 147 PrecacheFetcher::RecordCompletionStatistics( |
| 145 *unfinished_work, unfinished_work->top_host_size(), | 148 *unfinished_work, unfinished_work->top_host_size(), |
| 146 unfinished_work->resource_size()); | 149 unfinished_work->resource_size()); |
| 147 unfinished_work.reset(new PrecacheUnfinishedWork()); | 150 unfinished_work.reset(new PrecacheUnfinishedWork); |
| 148 unfinished_work->set_start_time(base::Time::Now().ToInternalValue()); | 151 unfinished_work->set_start_time(base::Time::Now().ToInternalValue()); |
|
bengr
2016/10/14 21:52:19
Why is start time being set here too?
twifkak
2016/10/14 22:41:45
The first one is what happens on a fresh precache
| |
| 149 } | 152 } |
| 150 unfinished_work_ = std::move(unfinished_work); | 153 unfinished_work_ = std::move(unfinished_work); |
| 151 bool needs_top_hosts = unfinished_work_->top_host_size() == 0; | 154 bool needs_top_hosts = unfinished_work_->top_host_size() == 0; |
| 152 | 155 |
| 153 if (IsInExperimentGroup()) { | 156 if (IsInExperimentGroup()) { |
| 154 BrowserThread::PostTask( | 157 BrowserThread::PostTask( |
| 155 BrowserThread::DB, FROM_HERE, | 158 BrowserThread::DB, FROM_HERE, |
| 156 base::Bind(&PrecacheDatabase::DeleteExpiredPrecacheHistory, | 159 base::Bind(&PrecacheDatabase::DeleteExpiredPrecacheHistory, |
| 157 base::Unretained(precache_database_.get()), | 160 base::Unretained(precache_database_.get()), |
| 158 base::Time::Now())); | 161 base::Time::Now())); |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 313 precache_completion_callback_.Reset(); | 316 precache_completion_callback_.Reset(); |
| 314 } | 317 } |
| 315 | 318 |
| 316 is_precaching_ = false; | 319 is_precaching_ = false; |
| 317 } | 320 } |
| 318 | 321 |
| 319 void PrecacheManager::OnHostsReceived( | 322 void PrecacheManager::OnHostsReceived( |
| 320 const history::TopHostsList& host_counts) { | 323 const history::TopHostsList& host_counts) { |
| 321 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 324 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 322 | 325 |
| 323 std::vector<std::string> hosts; | 326 for (const auto& host_count : host_counts) { |
| 324 for (const auto& host_count : host_counts) | 327 TopHost* top_host = unfinished_work_->add_top_host(); |
| 325 unfinished_work_->add_top_host()->set_hostname(host_count.first); | 328 top_host->set_hostname(host_count.first); |
| 329 top_host->set_visits(host_count.second); | |
| 330 } | |
| 326 InitializeAndStartFetcher(); | 331 InitializeAndStartFetcher(); |
| 327 } | 332 } |
| 328 | 333 |
| 329 void PrecacheManager::InitializeAndStartFetcher() { | 334 void PrecacheManager::InitializeAndStartFetcher() { |
| 330 if (!is_precaching_) { | 335 if (!is_precaching_) { |
| 331 // Don't start precaching if it was canceled while waiting for the list of | 336 // Don't start precaching if it was canceled while waiting for the list of |
| 332 // hosts. | 337 // hosts. |
| 333 return; | 338 return; |
| 334 } | 339 } |
| 335 // Start precaching. | 340 // Start precaching. |
| 336 precache_fetcher_.reset(new PrecacheFetcher( | 341 precache_fetcher_.reset(new PrecacheFetcher( |
| 337 content::BrowserContext::GetDefaultStoragePartition(browser_context_) | 342 content::BrowserContext::GetDefaultStoragePartition(browser_context_) |
| 338 ->GetURLRequestContext(), | 343 ->GetURLRequestContext(), |
| 339 GURL(variations::GetVariationParamValue(kPrecacheFieldTrialName, | 344 GURL(variations::GetVariationParamValue(kPrecacheFieldTrialName, |
| 340 kConfigURLParam)), | 345 kConfigURLParam)), |
| 341 variations::GetVariationParamValue(kPrecacheFieldTrialName, | 346 variations::GetVariationParamValue(kPrecacheFieldTrialName, |
| 342 kManifestURLPrefixParam), | 347 kManifestURLPrefixParam), |
| 348 !variations::GetVariationParamValue(kPrecacheFieldTrialName, | |
| 349 kGlobalRankingParam) | |
| 350 .empty(), | |
| 343 std::move(unfinished_work_), | 351 std::move(unfinished_work_), |
| 344 metrics::HashName( | 352 metrics::HashName( |
| 345 base::FieldTrialList::FindFullName(kPrecacheFieldTrialName)), | 353 base::FieldTrialList::FindFullName(kPrecacheFieldTrialName)), |
| 346 precache_database_->GetWeakPtr(), | 354 precache_database_->GetWeakPtr(), |
| 347 content::BrowserThread::GetTaskRunnerForThread( | 355 content::BrowserThread::GetTaskRunnerForThread( |
| 348 content::BrowserThread::DB), | 356 content::BrowserThread::DB), |
| 349 this)); | 357 this)); |
| 350 precache_fetcher_->Start(); | 358 precache_fetcher_->Start(); |
| 351 } | 359 } |
| 352 | 360 |
| 353 void PrecacheManager::OnHostsReceivedThenDone( | 361 void PrecacheManager::OnHostsReceivedThenDone( |
| 354 const history::TopHostsList& host_counts) { | 362 const history::TopHostsList& host_counts) { |
| 355 OnDone(); | 363 OnDone(); |
| 356 } | 364 } |
| 357 | 365 |
| 358 } // namespace precache | 366 } // namespace precache |
| OLD | NEW |