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

Side by Side Diff: chrome/browser/prerender/prerender_local_predictor.cc

Issue 573553004: Eliminate NOTIFICATION_HISTORY_LOADED notification (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add ScopedObserver to InMemoryHistoryBackend,PrerenderLocalPredictor,ChromeTemplateURLServiceClient Created 6 years 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/prerender/prerender_local_predictor.h" 5 #include "chrome/browser/prerender/prerender_local_predictor.h"
6 6
7 #include <ctype.h> 7 #include <ctype.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <map> 10 #include <map>
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 } 521 }
522 522
523 base::hash_map<string, ListEntry*> entries_; 523 base::hash_map<string, ListEntry*> entries_;
524 std::list<ListEntry*> entry_list_; 524 std::list<ListEntry*> entry_list_;
525 DISALLOW_COPY_AND_ASSIGN(PrefetchList); 525 DISALLOW_COPY_AND_ASSIGN(PrefetchList);
526 }; 526 };
527 527
528 PrerenderLocalPredictor::PrerenderLocalPredictor( 528 PrerenderLocalPredictor::PrerenderLocalPredictor(
529 PrerenderManager* prerender_manager) 529 PrerenderManager* prerender_manager)
530 : prerender_manager_(prerender_manager), 530 : prerender_manager_(prerender_manager),
531 is_history_service_observer_(false),
532 weak_factory_(this), 531 weak_factory_(this),
533 prefetch_list_(new PrefetchList()) { 532 prefetch_list_(new PrefetchList()),
533 history_service_observer_(this) {
534 RecordEvent(EVENT_CONSTRUCTED); 534 RecordEvent(EVENT_CONSTRUCTED);
535 if (base::MessageLoop::current()) { 535 if (base::MessageLoop::current()) {
536 timer_.Start(FROM_HERE, 536 timer_.Start(FROM_HERE,
537 base::TimeDelta::FromMilliseconds(kInitDelayMs), 537 base::TimeDelta::FromMilliseconds(kInitDelayMs),
538 this, 538 this,
539 &PrerenderLocalPredictor::Init); 539 &PrerenderLocalPredictor::Init);
540 RecordEvent(EVENT_INIT_SCHEDULED); 540 RecordEvent(EVENT_INIT_SCHEDULED);
541 } 541 }
542 542
543 static const size_t kChecksumHashSize = 32; 543 static const size_t kChecksumHashSize = 32;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 if (p->prerender_handle) 576 if (p->prerender_handle)
577 p->prerender_handle->OnCancel(); 577 p->prerender_handle->OnCancel();
578 } 578 }
579 STLDeleteContainerPairPointers( 579 STLDeleteContainerPairPointers(
580 outstanding_prerender_service_requests_.begin(), 580 outstanding_prerender_service_requests_.begin(),
581 outstanding_prerender_service_requests_.end()); 581 outstanding_prerender_service_requests_.end());
582 } 582 }
583 583
584 void PrerenderLocalPredictor::Shutdown() { 584 void PrerenderLocalPredictor::Shutdown() {
585 timer_.Stop(); 585 timer_.Stop();
586 if (is_history_service_observer_) { 586 history_service_observer_.RemoveAll();
587 HistoryService* history = GetHistoryIfExists();
588 CHECK(history);
589 history->RemoveObserver(this);
590 is_history_service_observer_ = false;
591 }
592 } 587 }
593 588
594 void PrerenderLocalPredictor::OnAddVisit(HistoryService* history_service, 589 void PrerenderLocalPredictor::OnAddVisit(HistoryService* history_service,
595 const history::BriefVisitInfo& info) { 590 const history::BriefVisitInfo& info) {
596 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 591 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
597 RecordEvent(EVENT_ADD_VISIT); 592 RecordEvent(EVENT_ADD_VISIT);
598 if (!visit_history_.get()) 593 if (!visit_history_.get())
599 return; 594 return;
600 visit_history_->push_back(info); 595 visit_history_->push_back(info);
601 if (static_cast<int>(visit_history_->size()) > kVisitHistoryPruneThreshold) { 596 if (static_cast<int>(visit_history_->size()) > kVisitHistoryPruneThreshold) {
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after
1132 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1127 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1133 RecordEvent(EVENT_INIT_STARTED); 1128 RecordEvent(EVENT_INIT_STARTED);
1134 Profile* profile = prerender_manager_->profile(); 1129 Profile* profile = prerender_manager_->profile();
1135 if (!profile || 1130 if (!profile ||
1136 ShouldDisableLocalPredictorBasedOnSyncAndConfiguration(profile)) { 1131 ShouldDisableLocalPredictorBasedOnSyncAndConfiguration(profile)) {
1137 RecordEvent(EVENT_INIT_FAILED_UNENCRYPTED_SYNC_NOT_ENABLED); 1132 RecordEvent(EVENT_INIT_FAILED_UNENCRYPTED_SYNC_NOT_ENABLED);
1138 return; 1133 return;
1139 } 1134 }
1140 HistoryService* history = GetHistoryIfExists(); 1135 HistoryService* history = GetHistoryIfExists();
1141 if (history) { 1136 if (history) {
1142 CHECK(!is_history_service_observer_); 1137 CHECK(!history_service_observer_.IsObserving(history));
1143 history->ScheduleDBTask( 1138 history->ScheduleDBTask(
1144 scoped_ptr<history::HistoryDBTask>( 1139 scoped_ptr<history::HistoryDBTask>(
1145 new GetVisitHistoryTask(this, kMaxVisitHistory)), 1140 new GetVisitHistoryTask(this, kMaxVisitHistory)),
1146 &history_db_tracker_); 1141 &history_db_tracker_);
1147 history->AddObserver(this); 1142 history_service_observer_.Add(history);
1148 is_history_service_observer_ = true;
1149 } else { 1143 } else {
1150 RecordEvent(EVENT_INIT_FAILED_NO_HISTORY); 1144 RecordEvent(EVENT_INIT_FAILED_NO_HISTORY);
1151 } 1145 }
1152 } 1146 }
1153 1147
1154 void PrerenderLocalPredictor::OnPLTEventForURL(const GURL& url, 1148 void PrerenderLocalPredictor::OnPLTEventForURL(const GURL& url,
1155 base::TimeDelta page_load_time) { 1149 base::TimeDelta page_load_time) {
1156 if (prefetch_list_->MarkPLTSeen(url, page_load_time)) { 1150 if (prefetch_list_->MarkPLTSeen(url, page_load_time)) {
1157 UMA_HISTOGRAM_CUSTOM_TIMES("Prerender.LocalPredictorPrefetchMatchPLT", 1151 UMA_HISTOGRAM_CUSTOM_TIMES("Prerender.LocalPredictorPrefetchMatchPLT",
1158 page_load_time, 1152 page_load_time,
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
1573 break; 1567 break;
1574 case content::SessionStorageNamespace::MERGE_RESULT_MERGEABLE: 1568 case content::SessionStorageNamespace::MERGE_RESULT_MERGEABLE:
1575 RecordEvent(EVENT_NAMESPACE_MISMATCH_MERGE_RESULT_MERGEABLE); 1569 RecordEvent(EVENT_NAMESPACE_MISMATCH_MERGE_RESULT_MERGEABLE);
1576 break; 1570 break;
1577 default: 1571 default:
1578 NOTREACHED(); 1572 NOTREACHED();
1579 } 1573 }
1580 } 1574 }
1581 1575
1582 } // namespace prerender 1576 } // namespace prerender
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698