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

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

Issue 10831103: Removing usage of profile_->GetHistory() from the codebase in order to remove that function. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 4 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 | Annotate | Revision Log
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/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/command_line.h" 11 #include "base/command_line.h"
12 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "base/stl_util.h" 13 #include "base/stl_util.h"
14 #include "base/time.h" 14 #include "base/time.h"
15 #include "chrome/browser/history/history.h" 15 #include "chrome/browser/history/history.h"
16 #include "chrome/browser/history/history_notifications.h" 16 #include "chrome/browser/history/history_notifications.h"
17 #include "chrome/browser/history/history_service_factory.h"
17 #include "chrome/browser/history/in_memory_database.h" 18 #include "chrome/browser/history/in_memory_database.h"
18 #include "chrome/browser/history/url_database.h" 19 #include "chrome/browser/history/url_database.h"
19 #include "chrome/browser/predictors/predictor_database.h" 20 #include "chrome/browser/predictors/predictor_database.h"
20 #include "chrome/browser/predictors/predictor_database_factory.h" 21 #include "chrome/browser/predictors/predictor_database_factory.h"
21 #include "chrome/browser/prerender/prerender_field_trial.h" 22 #include "chrome/browser/prerender/prerender_field_trial.h"
22 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/common/chrome_notification_types.h" 24 #include "chrome/common/chrome_notification_types.h"
24 #include "chrome/common/chrome_switches.h" 25 #include "chrome/common/chrome_switches.h"
25 #include "chrome/common/url_constants.h" 26 #include "chrome/common/url_constants.h"
26 #include "content/public/browser/browser_thread.h" 27 #include "content/public/browser/browser_thread.h"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 } 121 }
121 122
122 void ResourcePrefetchPredictor::LazilyInitialize() { 123 void ResourcePrefetchPredictor::LazilyInitialize() {
123 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 124 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
124 125
125 DCHECK_EQ(initialization_state_, NOT_INITIALIZED); 126 DCHECK_EQ(initialization_state_, NOT_INITIALIZED);
126 initialization_state_ = INITIALIZING; 127 initialization_state_ = INITIALIZING;
127 128
128 // Request the in-memory database from the history to force it to load so it's 129 // Request the in-memory database from the history to force it to load so it's
129 // available as soon as possible. 130 // available as soon as possible.
130 HistoryService* history_service = 131 HistoryService* history_service = HistoryServiceFactory::GetForProfile(
131 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); 132 profile_, Profile::EXPLICIT_ACCESS);
132 if (history_service) 133 if (history_service)
133 history_service->InMemoryDatabase(); 134 history_service->InMemoryDatabase();
134 135
135 // Create local caches using the database as loaded. 136 // Create local caches using the database as loaded.
136 std::vector<UrlTableRow>* url_rows = new std::vector<UrlTableRow>(); 137 std::vector<UrlTableRow>* url_rows = new std::vector<UrlTableRow>();
137 BrowserThread::PostTaskAndReply( 138 BrowserThread::PostTaskAndReply(
138 BrowserThread::DB, FROM_HERE, 139 BrowserThread::DB, FROM_HERE,
139 base::Bind(&ResourcePrefetchPredictorTables::GetAllRows, 140 base::Bind(&ResourcePrefetchPredictorTables::GetAllRows,
140 tables_, url_rows), 141 tables_, url_rows),
141 base::Bind(&ResourcePrefetchPredictor::CreateCaches, AsWeakPtr(), 142 base::Bind(&ResourcePrefetchPredictor::CreateCaches, AsWeakPtr(),
(...skipping 18 matching lines...) Expand all
160 // TODO(shishir): The following would be much more efficient if we used 161 // TODO(shishir): The following would be much more efficient if we used
161 // pointers. 162 // pointers.
162 for (UrlTableCacheMap::iterator it = url_table_cache_.begin(); 163 for (UrlTableCacheMap::iterator it = url_table_cache_.begin();
163 it != url_table_cache_.end(); ++it) { 164 it != url_table_cache_.end(); ++it) {
164 std::sort(it->second.rows.begin(), 165 std::sort(it->second.rows.begin(),
165 it->second.rows.end(), 166 it->second.rows.end(),
166 ResourcePrefetchPredictorTables::UrlTableRowSorter()); 167 ResourcePrefetchPredictorTables::UrlTableRowSorter());
167 } 168 }
168 169
169 // Add notifications for history loading if it is not ready. 170 // Add notifications for history loading if it is not ready.
170 if (!profile_->GetHistoryService(Profile::EXPLICIT_ACCESS)) { 171 HistoryService* history_service = HistoryServiceFactory::GetForProfile(
172 profile_, Profile::EXPLICIT_ACCESS);
173 if (!history_service) {
171 notification_registrar_.Add(this, chrome::NOTIFICATION_HISTORY_LOADED, 174 notification_registrar_.Add(this, chrome::NOTIFICATION_HISTORY_LOADED,
172 content::Source<Profile>(profile_)); 175 content::Source<Profile>(profile_));
173 } else { 176 } else {
174 OnHistoryAndCacheLoaded(); 177 OnHistoryAndCacheLoaded();
175 } 178 }
176 } 179 }
177 180
178 // static 181 // static
179 bool ResourcePrefetchPredictor::ShouldRecordRequest( 182 bool ResourcePrefetchPredictor::ShouldRecordRequest(
180 net::URLRequest* request, 183 net::URLRequest* request,
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 NOTREACHED() << "Unexpected notification observed."; 458 NOTREACHED() << "Unexpected notification observed.";
456 break; 459 break;
457 } 460 }
458 } 461 }
459 462
460 void ResourcePrefetchPredictor::OnHistoryAndCacheLoaded() { 463 void ResourcePrefetchPredictor::OnHistoryAndCacheLoaded() {
461 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 464 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
462 DCHECK_EQ(initialization_state_, INITIALIZING); 465 DCHECK_EQ(initialization_state_, INITIALIZING);
463 466
464 // Update the data with last visit info from in memory history db. 467 // Update the data with last visit info from in memory history db.
465 HistoryService* history_service = 468 HistoryService* history_service = HistoryServiceFactory::GetForProfile(
466 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); 469 profile_, Profile::EXPLICIT_ACCESS);
467 DCHECK(history_service); 470 DCHECK(history_service);
468 history::URLDatabase* url_db = history_service->InMemoryDatabase(); 471 history::URLDatabase* url_db = history_service->InMemoryDatabase();
469 if (url_db) { 472 if (url_db) {
470 std::vector<GURL> urls_to_delete; 473 std::vector<GURL> urls_to_delete;
471 for (UrlTableCacheMap::iterator it = url_table_cache_.begin(); 474 for (UrlTableCacheMap::iterator it = url_table_cache_.begin();
472 it != url_table_cache_.end();) { 475 it != url_table_cache_.end();) {
473 history::URLRow url_row; 476 history::URLRow url_row;
474 if (url_db->GetRowForURL(it->first, &url_row) == 0) { 477 if (url_db->GetRowForURL(it->first, &url_row) == 0) {
475 urls_to_delete.push_back(it->first); 478 urls_to_delete.push_back(it->first);
476 url_table_cache_.erase(it++); 479 url_table_cache_.erase(it++);
(...skipping 22 matching lines...) Expand all
499 // TODO(shishir): Maybe listen for notifications for navigation being 502 // TODO(shishir): Maybe listen for notifications for navigation being
500 // abandoned and cleanup the inflight_navigations_. 503 // abandoned and cleanup the inflight_navigations_.
501 504
502 initialization_state_ = INITIALIZED; 505 initialization_state_ = INITIALIZED;
503 } 506 }
504 507
505 bool ResourcePrefetchPredictor::ShouldTrackUrl(const GURL& url) { 508 bool ResourcePrefetchPredictor::ShouldTrackUrl(const GURL& url) {
506 if (url_table_cache_.find(url) != url_table_cache_.end()) 509 if (url_table_cache_.find(url) != url_table_cache_.end())
507 return true; 510 return true;
508 511
509 HistoryService* history_service = 512 HistoryService* history_service = HistoryServiceFactory::GetForProfile(
510 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); 513 profile_, Profile::EXPLICIT_ACCESS);
511 DCHECK(history_service); 514 DCHECK(history_service);
512 history::URLDatabase* url_db = history_service->InMemoryDatabase(); 515 history::URLDatabase* url_db = history_service->InMemoryDatabase();
513 if (!url_db) 516 if (!url_db)
514 return false; 517 return false;
515 518
516 history::URLRow url_row; 519 history::URLRow url_row;
517 return url_db->GetRowForURL(url, &url_row) != 0 && 520 return url_db->GetRowForURL(url, &url_row) != 0 &&
518 url_row.visit_count() >= config_.min_url_visit_count; 521 url_row.visit_count() >= config_.min_url_visit_count;
519 } 522 }
520 523
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 tables_, 760 tables_,
758 urls_to_delete)); 761 urls_to_delete));
759 } 762 }
760 763
761 void ResourcePrefetchPredictor::SetTablesForTesting( 764 void ResourcePrefetchPredictor::SetTablesForTesting(
762 scoped_refptr<ResourcePrefetchPredictorTables> tables) { 765 scoped_refptr<ResourcePrefetchPredictorTables> tables) {
763 tables_ = tables; 766 tables_ = tables;
764 } 767 }
765 768
766 } // namespace predictors 769 } // namespace predictors
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698