| OLD | NEW |
| 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/autocomplete/network_action_predictor.h" | 5 #include "chrome/browser/autocomplete/network_action_predictor.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/i18n/case_conversion.h" | 12 #include "base/i18n/case_conversion.h" |
| 13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 16 #include "chrome/browser/autocomplete/autocomplete.h" | 16 #include "chrome/browser/autocomplete/autocomplete.h" |
| 17 #include "chrome/browser/autocomplete/autocomplete_match.h" | 17 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 18 #include "chrome/browser/autocomplete/network_action_predictor_database.h" | 18 #include "chrome/browser/autocomplete/network_action_predictor_database.h" |
| 19 #include "chrome/browser/history/history.h" | 19 #include "chrome/browser/history/history.h" |
| 20 #include "chrome/browser/history/history_notifications.h" | 20 #include "chrome/browser/history/history_notifications.h" |
| 21 #include "chrome/browser/history/in_memory_database.h" | 21 #include "chrome/browser/history/in_memory_database.h" |
| 22 #include "chrome/browser/prerender/prerender_field_trial.h" | 22 #include "chrome/browser/prerender/prerender_field_trial.h" |
| 23 #include "chrome/browser/prerender/prerender_manager.h" |
| 24 #include "chrome/browser/prerender/prerender_manager_factory.h" |
| 23 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/common/chrome_notification_types.h" | 26 #include "chrome/common/chrome_notification_types.h" |
| 25 #include "chrome/common/guid.h" | 27 #include "chrome/common/guid.h" |
| 26 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
| 27 #include "content/public/browser/notification_details.h" | 29 #include "content/public/browser/notification_details.h" |
| 28 #include "content/public/browser/notification_service.h" | 30 #include "content/public/browser/notification_service.h" |
| 29 #include "content/public/browser/notification_source.h" | 31 #include "content/public/browser/notification_source.h" |
| 30 | 32 |
| 31 namespace { | 33 namespace { |
| 32 | 34 |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 if (log.text.length() < kMinimumUserTextLength) | 230 if (log.text.length() < kMinimumUserTextLength) |
| 229 return; | 231 return; |
| 230 | 232 |
| 231 const AutocompleteMatch& match = log.result.match_at(log.selected_index); | 233 const AutocompleteMatch& match = log.result.match_at(log.selected_index); |
| 232 | 234 |
| 233 UMA_HISTOGRAM_BOOLEAN("Prerender.OmniboxNavigationsCouldPrerender", | 235 UMA_HISTOGRAM_BOOLEAN("Prerender.OmniboxNavigationsCouldPrerender", |
| 234 prerender::IsOmniboxEnabled(profile_)); | 236 prerender::IsOmniboxEnabled(profile_)); |
| 235 | 237 |
| 236 const GURL& opened_url = match.destination_url; | 238 const GURL& opened_url = match.destination_url; |
| 237 | 239 |
| 240 // If the Omnibox triggered a prerender but the URL doesn't match the one the |
| 241 // user is navigating to, cancel the prerender. |
| 242 prerender::PrerenderManager* prerender_manager = |
| 243 prerender::PrerenderManagerFactory::GetForProfile(profile_); |
| 244 // |prerender_manager| can be NULL in incognito mode or if prerendering is |
| 245 // otherwise disabled. |
| 246 if (prerender_manager && !prerender_manager->IsPrerendering(opened_url)) |
| 247 prerender_manager->CancelOmniboxPrerenders(); |
| 248 |
| 238 const string16 lower_user_text(base::i18n::ToLower(log.text)); | 249 const string16 lower_user_text(base::i18n::ToLower(log.text)); |
| 239 | 250 |
| 240 BeginTransaction(); | 251 BeginTransaction(); |
| 241 // Traverse transitional matches for those that have a user_text that is a | 252 // Traverse transitional matches for those that have a user_text that is a |
| 242 // prefix of |lower_user_text|. | 253 // prefix of |lower_user_text|. |
| 243 for (std::vector<TransitionalMatch>::const_iterator it = | 254 for (std::vector<TransitionalMatch>::const_iterator it = |
| 244 transitional_matches_.begin(); it != transitional_matches_.end(); | 255 transitional_matches_.begin(); it != transitional_matches_.end(); |
| 245 ++it) { | 256 ++it) { |
| 246 if (!StartsWith(lower_user_text, it->user_text, true)) | 257 if (!StartsWith(lower_user_text, it->user_text, true)) |
| 247 continue; | 258 continue; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 tracked_urls_.begin(); it != tracked_urls_.end(); | 295 tracked_urls_.begin(); it != tracked_urls_.end(); |
| 285 ++it) { | 296 ++it) { |
| 286 if (opened_url == it->first) { | 297 if (opened_url == it->first) { |
| 287 UMA_HISTOGRAM_COUNTS_100("NetworkActionPredictor.AccurateCount", | 298 UMA_HISTOGRAM_COUNTS_100("NetworkActionPredictor.AccurateCount", |
| 288 it->second * 100); | 299 it->second * 100); |
| 289 } | 300 } |
| 290 } | 301 } |
| 291 tracked_urls_.clear(); | 302 tracked_urls_.clear(); |
| 292 } | 303 } |
| 293 | 304 |
| 294 | |
| 295 void NetworkActionPredictor::DeleteOldIdsFromCaches( | 305 void NetworkActionPredictor::DeleteOldIdsFromCaches( |
| 296 history::URLDatabase* url_db, | 306 history::URLDatabase* url_db, |
| 297 std::vector<NetworkActionPredictorDatabase::Row::Id>* id_list) { | 307 std::vector<NetworkActionPredictorDatabase::Row::Id>* id_list) { |
| 298 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 308 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 299 DCHECK(url_db); | 309 DCHECK(url_db); |
| 300 DCHECK(id_list); | 310 DCHECK(id_list); |
| 301 id_list->clear(); | 311 id_list->clear(); |
| 302 for (DBCacheMap::iterator it = db_cache_.begin(); it != db_cache_.end();) { | 312 for (DBCacheMap::iterator it = db_cache_.begin(); it != db_cache_.end();) { |
| 303 history::URLRow url_row; | 313 history::URLRow url_row; |
| 304 | 314 |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 | 483 |
| 474 content::BrowserThread::PostTask(content::BrowserThread::DB, FROM_HERE, | 484 content::BrowserThread::PostTask(content::BrowserThread::DB, FROM_HERE, |
| 475 base::Bind(&NetworkActionPredictorDatabase::CommitTransaction, db_)); | 485 base::Bind(&NetworkActionPredictorDatabase::CommitTransaction, db_)); |
| 476 } | 486 } |
| 477 | 487 |
| 478 NetworkActionPredictor::TransitionalMatch::TransitionalMatch() { | 488 NetworkActionPredictor::TransitionalMatch::TransitionalMatch() { |
| 479 } | 489 } |
| 480 | 490 |
| 481 NetworkActionPredictor::TransitionalMatch::~TransitionalMatch() { | 491 NetworkActionPredictor::TransitionalMatch::~TransitionalMatch() { |
| 482 } | 492 } |
| OLD | NEW |