| 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 |
| 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/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/metrics/field_trial.h" | 15 #include "base/metrics/field_trial.h" |
| 16 #include "base/metrics/histogram_macros.h" | 16 #include "base/metrics/histogram_macros.h" |
| 17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 18 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
| 19 #include "base/time/time.h" | 19 #include "base/time/time.h" |
| 20 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett
ings.h" | 20 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett
ings.h" |
| 21 #include "components/history/core/browser/history_service.h" | 21 #include "components/history/core/browser/history_service.h" |
| 22 #include "components/precache/core/precache_database.h" | 22 #include "components/precache/core/precache_database.h" |
| 23 #include "components/precache/core/precache_switches.h" | 23 #include "components/precache/core/precache_switches.h" |
| 24 #include "components/precache/core/proto/precache.pb.h" |
| 24 #include "components/precache/core/proto/unfinished_work.pb.h" | 25 #include "components/precache/core/proto/unfinished_work.pb.h" |
| 25 #include "components/prefs/pref_service.h" | 26 #include "components/prefs/pref_service.h" |
| 26 #include "components/sync/driver/sync_service.h" | 27 #include "components/sync/driver/sync_service.h" |
| 27 #include "components/variations/metrics_util.h" | 28 #include "components/variations/metrics_util.h" |
| 28 #include "components/variations/variations_associated_data.h" | 29 #include "components/variations/variations_associated_data.h" |
| 29 #include "content/public/browser/browser_context.h" | 30 #include "content/public/browser/browser_context.h" |
| 30 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
| 31 #include "content/public/browser/storage_partition.h" | 32 #include "content/public/browser/storage_partition.h" |
| 32 #include "net/base/network_change_notifier.h" | 33 #include "net/base/network_change_notifier.h" |
| 33 #include "net/http/http_cache.h" | 34 #include "net/http/http_cache.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 55 size_t NumTopHosts() { | 56 size_t NumTopHosts() { |
| 56 return kNumTopHosts; | 57 return kNumTopHosts; |
| 57 } | 58 } |
| 58 | 59 |
| 59 PrecacheManager::PrecacheManager( | 60 PrecacheManager::PrecacheManager( |
| 60 content::BrowserContext* browser_context, | 61 content::BrowserContext* browser_context, |
| 61 const syncer::SyncService* const sync_service, | 62 const syncer::SyncService* const sync_service, |
| 62 const history::HistoryService* const history_service, | 63 const history::HistoryService* const history_service, |
| 63 const data_reduction_proxy::DataReductionProxySettings* | 64 const data_reduction_proxy::DataReductionProxySettings* |
| 64 data_reduction_proxy_settings, | 65 data_reduction_proxy_settings, |
| 66 Delegate* delegate, |
| 65 const base::FilePath& db_path, | 67 const base::FilePath& db_path, |
| 66 std::unique_ptr<PrecacheDatabase> precache_database) | 68 std::unique_ptr<PrecacheDatabase> precache_database) |
| 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), |
| 73 delegate_(delegate), |
| 71 is_precaching_(false) { | 74 is_precaching_(false) { |
| 72 precache_database_ = std::move(precache_database); | 75 precache_database_ = std::move(precache_database); |
| 73 BrowserThread::PostTask( | 76 BrowserThread::PostTask( |
| 74 BrowserThread::DB, FROM_HERE, | 77 BrowserThread::DB, FROM_HERE, |
| 75 base::Bind(base::IgnoreResult(&PrecacheDatabase::Init), | 78 base::Bind(base::IgnoreResult(&PrecacheDatabase::Init), |
| 76 base::Unretained(precache_database_.get()), db_path)); | 79 base::Unretained(precache_database_.get()), db_path)); |
| 77 } | 80 } |
| 78 | 81 |
| 79 PrecacheManager::~PrecacheManager() { | 82 PrecacheManager::~PrecacheManager() { |
| 80 // DeleteSoon posts a non-nestable task to the task runner, so any previously | 83 // DeleteSoon posts a non-nestable task to the task runner, so any previously |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 // finishes. | 452 // finishes. |
| 450 if (!precache_completion_callback_.is_null()) { | 453 if (!precache_completion_callback_.is_null()) { |
| 451 precache_completion_callback_.Run(!is_precaching_); | 454 precache_completion_callback_.Run(!is_precaching_); |
| 452 // Uninitialize the callback so that any scoped_refptrs in it are released. | 455 // Uninitialize the callback so that any scoped_refptrs in it are released. |
| 453 precache_completion_callback_.Reset(); | 456 precache_completion_callback_.Reset(); |
| 454 } | 457 } |
| 455 | 458 |
| 456 is_precaching_ = false; | 459 is_precaching_ = false; |
| 457 } | 460 } |
| 458 | 461 |
| 462 void PrecacheManager::OnManifestFetched(const std::string& host, |
| 463 const PrecacheManifest& manifest) { |
| 464 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 465 if (delegate_) |
| 466 delegate_->OnManifestFetched(host, manifest); |
| 467 } |
| 468 |
| 459 void PrecacheManager::OnHostsReceived( | 469 void PrecacheManager::OnHostsReceived( |
| 460 const history::TopHostsList& host_counts) { | 470 const history::TopHostsList& host_counts) { |
| 461 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 471 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 462 | 472 |
| 463 for (const auto& host_count : host_counts) { | 473 for (const auto& host_count : host_counts) { |
| 464 TopHost* top_host = unfinished_work_->add_top_host(); | 474 TopHost* top_host = unfinished_work_->add_top_host(); |
| 465 top_host->set_hostname(host_count.first); | 475 top_host->set_hostname(host_count.first); |
| 466 top_host->set_visits(host_count.second); | 476 top_host->set_visits(host_count.second); |
| 467 } | 477 } |
| 468 InitializeAndStartFetcher(); | 478 InitializeAndStartFetcher(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 491 this)); | 501 this)); |
| 492 precache_fetcher_->Start(); | 502 precache_fetcher_->Start(); |
| 493 } | 503 } |
| 494 | 504 |
| 495 void PrecacheManager::OnHostsReceivedThenDone( | 505 void PrecacheManager::OnHostsReceivedThenDone( |
| 496 const history::TopHostsList& host_counts) { | 506 const history::TopHostsList& host_counts) { |
| 497 OnDone(); | 507 OnDone(); |
| 498 } | 508 } |
| 499 | 509 |
| 500 } // namespace precache | 510 } // namespace precache |
| OLD | NEW |