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

Side by Side Diff: chrome/browser/predictors/resource_prefetch_predictor.cc

Issue 2802053002: precache: Extract common methods for PrecacheManifest into util. (Closed)
Patch Set: Copyright. Created 3 years, 8 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
« no previous file with comments | « chrome/browser/BUILD.gn ('k') | components/precache/core/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/browser/predictors/resource_prefetch_predictor.h" 5 #include "chrome/browser/predictors/resource_prefetch_predictor.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/metrics/histogram_macros.h" 13 #include "base/metrics/histogram_macros.h"
14 #include "base/rand_util.h" 14 #include "base/rand_util.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "base/trace_event/trace_event.h" 16 #include "base/trace_event/trace_event.h"
17 #include "chrome/browser/history/history_service_factory.h" 17 #include "chrome/browser/history/history_service_factory.h"
18 #include "chrome/browser/predictors/predictor_database.h" 18 #include "chrome/browser/predictors/predictor_database.h"
19 #include "chrome/browser/predictors/predictor_database_factory.h" 19 #include "chrome/browser/predictors/predictor_database_factory.h"
20 #include "chrome/browser/predictors/resource_prefetcher_manager.h" 20 #include "chrome/browser/predictors/resource_prefetcher_manager.h"
21 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
22 #include "components/history/core/browser/history_database.h" 22 #include "components/history/core/browser/history_database.h"
23 #include "components/history/core/browser/history_service.h" 23 #include "components/history/core/browser/history_service.h"
24 #include "components/history/core/browser/url_utils.h" 24 #include "components/history/core/browser/url_utils.h"
25 #include "components/mime_util/mime_util.h" 25 #include "components/mime_util/mime_util.h"
26 #include "components/precache/core/precache_manifest_util.h"
26 #include "content/public/browser/browser_thread.h" 27 #include "content/public/browser/browser_thread.h"
27 #include "content/public/browser/resource_request_info.h" 28 #include "content/public/browser/resource_request_info.h"
28 #include "content/public/browser/web_contents.h" 29 #include "content/public/browser/web_contents.h"
29 #include "net/http/http_response_headers.h" 30 #include "net/http/http_response_headers.h"
30 #include "net/url_request/url_request.h" 31 #include "net/url_request/url_request.h"
31 32
32 using content::BrowserThread; 33 using content::BrowserThread;
33 34
34 namespace predictors { 35 namespace predictors {
35 36
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 precision_percentage); 215 precision_percentage);
215 UMA_HISTOGRAM_PERCENTAGE(internal::kResourcePrefetchPredictorRecallHistogram, 216 UMA_HISTOGRAM_PERCENTAGE(internal::kResourcePrefetchPredictorRecallHistogram,
216 recall_percentage); 217 recall_percentage);
217 UMA_HISTOGRAM_COUNTS_100(internal::kResourcePrefetchPredictorCountHistogram, 218 UMA_HISTOGRAM_COUNTS_100(internal::kResourcePrefetchPredictorCountHistogram,
218 predicted_urls.size()); 219 predicted_urls.size());
219 UMA_HISTOGRAM_ENUMERATION( 220 UMA_HISTOGRAM_ENUMERATION(
220 internal::kResourcePrefetchPredictorRedirectStatusHistogram, 221 internal::kResourcePrefetchPredictorRedirectStatusHistogram,
221 static_cast<int>(redirect_status), static_cast<int>(RedirectStatus::MAX)); 222 static_cast<int>(redirect_status), static_cast<int>(RedirectStatus::MAX));
222 } 223 }
223 224
224 void RemoveUnknownFieldsFromPrecacheManifest(
225 precache::PrecacheManifest* manifest) {
226 manifest->mutable_unknown_fields()->clear();
227 for (auto& resource : *manifest->mutable_resource())
228 resource.mutable_unknown_fields()->clear();
229 if (manifest->has_experiments()) {
230 manifest->mutable_experiments()->mutable_unknown_fields()->clear();
231 for (auto& kv : *manifest->mutable_experiments()
232 ->mutable_resources_by_experiment_group()) {
233 kv.second.mutable_unknown_fields()->clear();
234 }
235 }
236 if (manifest->has_id())
237 manifest->mutable_id()->mutable_unknown_fields()->clear();
238 }
239
240 } // namespace 225 } // namespace
241 226
242 //////////////////////////////////////////////////////////////////////////////// 227 ////////////////////////////////////////////////////////////////////////////////
243 // ResourcePrefetchPredictor static functions. 228 // ResourcePrefetchPredictor static functions.
244 229
245 // static 230 // static
246 bool ResourcePrefetchPredictor::ShouldRecordRequest( 231 bool ResourcePrefetchPredictor::ShouldRecordRequest(
247 net::URLRequest* request, 232 net::URLRequest* request,
248 content::ResourceType resource_type) { 233 content::ResourceType resource_type) {
249 const content::ResourceRequestInfo* request_info = 234 const content::ResourceRequestInfo* request_info =
(...skipping 1225 matching lines...) Expand 10 before | Expand all | Expand 10 after
1475 auto cache_entry = manifest_table_cache_->find(host); 1460 auto cache_entry = manifest_table_cache_->find(host);
1476 if (cache_entry == manifest_table_cache_->end()) { 1461 if (cache_entry == manifest_table_cache_->end()) {
1477 if (manifest_table_cache_->size() >= config_.max_hosts_to_track) 1462 if (manifest_table_cache_->size() >= config_.max_hosts_to_track)
1478 RemoveOldestEntryInManifestDataMap(manifest_table_cache_.get()); 1463 RemoveOldestEntryInManifestDataMap(manifest_table_cache_.get());
1479 cache_entry = 1464 cache_entry =
1480 manifest_table_cache_->insert(std::make_pair(host, manifest)).first; 1465 manifest_table_cache_->insert(std::make_pair(host, manifest)).first;
1481 } else { 1466 } else {
1482 cache_entry->second = manifest; 1467 cache_entry->second = manifest;
1483 } 1468 }
1484 1469
1485 RemoveUnknownFieldsFromPrecacheManifest(&cache_entry->second); 1470 precache::RemoveUnknownFields(&cache_entry->second);
1486 1471
1487 BrowserThread::PostTask( 1472 BrowserThread::PostTask(
1488 BrowserThread::DB, FROM_HERE, 1473 BrowserThread::DB, FROM_HERE,
1489 base::Bind(&ResourcePrefetchPredictorTables::UpdateManifestData, tables_, 1474 base::Bind(&ResourcePrefetchPredictorTables::UpdateManifestData, tables_,
1490 host, cache_entry->second)); 1475 host, cache_entry->second));
1491 } 1476 }
1492 1477
1493 void ResourcePrefetchPredictor::ConnectToHistoryService() { 1478 void ResourcePrefetchPredictor::ConnectToHistoryService() {
1494 // Register for HistoryServiceLoading if it is not ready. 1479 // Register for HistoryServiceLoading if it is not ready.
1495 history::HistoryService* history_service = 1480 history::HistoryService* history_service =
(...skipping 15 matching lines...) Expand all
1511 TestObserver::~TestObserver() { 1496 TestObserver::~TestObserver() {
1512 predictor_->SetObserverForTesting(nullptr); 1497 predictor_->SetObserverForTesting(nullptr);
1513 } 1498 }
1514 1499
1515 TestObserver::TestObserver(ResourcePrefetchPredictor* predictor) 1500 TestObserver::TestObserver(ResourcePrefetchPredictor* predictor)
1516 : predictor_(predictor) { 1501 : predictor_(predictor) {
1517 predictor_->SetObserverForTesting(this); 1502 predictor_->SetObserverForTesting(this);
1518 } 1503 }
1519 1504
1520 } // namespace predictors 1505 } // namespace predictors
OLDNEW
« no previous file with comments | « chrome/browser/BUILD.gn ('k') | components/precache/core/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698