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

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

Issue 2508933002: tools: Local tests for the speculative prefetch predictor. (Closed)
Patch Set: Rebase/ Created 4 years, 1 month 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
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
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 if (config_.IsURLPrefetchingEnabled(profile_)) 386 if (config_.IsURLPrefetchingEnabled(profile_))
387 DCHECK(config_.IsURLLearningEnabled()); 387 DCHECK(config_.IsURLLearningEnabled());
388 if (config_.IsHostPrefetchingEnabled(profile_)) 388 if (config_.IsHostPrefetchingEnabled(profile_))
389 DCHECK(config_.IsHostLearningEnabled()); 389 DCHECK(config_.IsHostLearningEnabled());
390 } 390 }
391 391
392 ResourcePrefetchPredictor::~ResourcePrefetchPredictor() {} 392 ResourcePrefetchPredictor::~ResourcePrefetchPredictor() {}
393 393
394 void ResourcePrefetchPredictor::StartInitialization() { 394 void ResourcePrefetchPredictor::StartInitialization() {
395 DCHECK_CURRENTLY_ON(BrowserThread::UI); 395 DCHECK_CURRENTLY_ON(BrowserThread::UI);
396 TRACE_EVENT0("browser", "ResourcePrefetchPredictor::StartInitialization");
396 397
397 DCHECK_EQ(NOT_INITIALIZED, initialization_state_); 398 if (initialization_state_ != NOT_INITIALIZED)
399 return;
398 initialization_state_ = INITIALIZING; 400 initialization_state_ = INITIALIZING;
399 401
400 // Create local caches using the database as loaded. 402 // Create local caches using the database as loaded.
401 auto url_data_map = base::MakeUnique<PrefetchDataMap>(); 403 auto url_data_map = base::MakeUnique<PrefetchDataMap>();
402 auto host_data_map = base::MakeUnique<PrefetchDataMap>(); 404 auto host_data_map = base::MakeUnique<PrefetchDataMap>();
403 auto url_redirect_data_map = base::MakeUnique<RedirectDataMap>(); 405 auto url_redirect_data_map = base::MakeUnique<RedirectDataMap>();
404 auto host_redirect_data_map = base::MakeUnique<RedirectDataMap>(); 406 auto host_redirect_data_map = base::MakeUnique<RedirectDataMap>();
405 407
406 // Get raw pointers to pass to the first task. Ownership of the unique_ptrs 408 // Get raw pointers to pass to the first task. Ownership of the unique_ptrs
407 // will be passed to the reply task. 409 // will be passed to the reply task.
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 } 516 }
515 history_service_observer_.RemoveAll(); 517 history_service_observer_.RemoveAll();
516 } 518 }
517 519
518 void ResourcePrefetchPredictor::OnMainFrameRequest( 520 void ResourcePrefetchPredictor::OnMainFrameRequest(
519 const URLRequestSummary& request) { 521 const URLRequestSummary& request) {
520 DCHECK_CURRENTLY_ON(BrowserThread::UI); 522 DCHECK_CURRENTLY_ON(BrowserThread::UI);
521 DCHECK_EQ(INITIALIZED, initialization_state_); 523 DCHECK_EQ(INITIALIZED, initialization_state_);
522 524
523 const GURL& main_frame_url = request.navigation_id.main_frame_url; 525 const GURL& main_frame_url = request.navigation_id.main_frame_url;
524 StartPrefetching(main_frame_url); 526 if (!config_.ExternalPrefetchingOnly())
527 StartPrefetching(main_frame_url);
525 528
526 // Cleanup older navigations. 529 // Cleanup older navigations.
527 CleanupAbandonedNavigations(request.navigation_id); 530 CleanupAbandonedNavigations(request.navigation_id);
528 531
529 // New empty navigation entry. 532 // New empty navigation entry.
530 inflight_navigations_.insert( 533 inflight_navigations_.insert(
531 std::make_pair(request.navigation_id, 534 std::make_pair(request.navigation_id,
532 base::MakeUnique<PageRequestSummary>(main_frame_url))); 535 base::MakeUnique<PageRequestSummary>(main_frame_url)));
533 } 536 }
534 537
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after
1168 TestObserver::~TestObserver() { 1171 TestObserver::~TestObserver() {
1169 predictor_->SetObserverForTesting(nullptr); 1172 predictor_->SetObserverForTesting(nullptr);
1170 } 1173 }
1171 1174
1172 TestObserver::TestObserver(ResourcePrefetchPredictor* predictor) 1175 TestObserver::TestObserver(ResourcePrefetchPredictor* predictor)
1173 : predictor_(predictor) { 1176 : predictor_(predictor) {
1174 predictor_->SetObserverForTesting(this); 1177 predictor_->SetObserverForTesting(this);
1175 } 1178 }
1176 1179
1177 } // namespace predictors 1180 } // namespace predictors
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698