| 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 |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 const content::NotificationDetails& details) { | 195 const content::NotificationDetails& details) { |
| 196 switch (type) { | 196 switch (type) { |
| 197 case chrome::NOTIFICATION_HISTORY_URLS_DELETED: { | 197 case chrome::NOTIFICATION_HISTORY_URLS_DELETED: { |
| 198 DCHECK(initialized_); | 198 DCHECK(initialized_); |
| 199 const content::Details<const history::URLsDeletedDetails> | 199 const content::Details<const history::URLsDeletedDetails> |
| 200 urls_deleted_details = | 200 urls_deleted_details = |
| 201 content::Details<const history::URLsDeletedDetails>(details); | 201 content::Details<const history::URLsDeletedDetails>(details); |
| 202 if (urls_deleted_details->all_history) | 202 if (urls_deleted_details->all_history) |
| 203 DeleteAllRows(); | 203 DeleteAllRows(); |
| 204 else | 204 else |
| 205 DeleteRowsWithURLs(urls_deleted_details->urls); | 205 DeleteRowsWithURLs(urls_deleted_details->rows); |
| 206 break; | 206 break; |
| 207 } | 207 } |
| 208 | 208 |
| 209 // This notification does not catch all instances of the user navigating | 209 // This notification does not catch all instances of the user navigating |
| 210 // from the Omnibox, but it does catch the cases where the dropdown is open | 210 // from the Omnibox, but it does catch the cases where the dropdown is open |
| 211 // and those are the events we're most interested in. | 211 // and those are the events we're most interested in. |
| 212 case chrome::NOTIFICATION_OMNIBOX_OPENED_URL: { | 212 case chrome::NOTIFICATION_OMNIBOX_OPENED_URL: { |
| 213 DCHECK(initialized_); | 213 DCHECK(initialized_); |
| 214 | 214 |
| 215 // TODO(dominich): This doesn't need to be synchronous. Investigate | 215 // TODO(dominich): This doesn't need to be synchronous. Investigate |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 return; | 458 return; |
| 459 | 459 |
| 460 db_cache_.clear(); | 460 db_cache_.clear(); |
| 461 db_id_cache_.clear(); | 461 db_id_cache_.clear(); |
| 462 content::BrowserThread::PostTask(content::BrowserThread::DB, FROM_HERE, | 462 content::BrowserThread::PostTask(content::BrowserThread::DB, FROM_HERE, |
| 463 base::Bind(&NetworkActionPredictorDatabase::DeleteAllRows, db_)); | 463 base::Bind(&NetworkActionPredictorDatabase::DeleteAllRows, db_)); |
| 464 UMA_HISTOGRAM_ENUMERATION("NetworkActionPredictor.DatabaseAction", | 464 UMA_HISTOGRAM_ENUMERATION("NetworkActionPredictor.DatabaseAction", |
| 465 DATABASE_ACTION_DELETE_ALL, DATABASE_ACTION_COUNT); | 465 DATABASE_ACTION_DELETE_ALL, DATABASE_ACTION_COUNT); |
| 466 } | 466 } |
| 467 | 467 |
| 468 void NetworkActionPredictor::DeleteRowsWithURLs(const std::set<GURL>& urls) { | 468 void NetworkActionPredictor::DeleteRowsWithURLs(const history::URLRows& rows) { |
| 469 if (!initialized_) | 469 if (!initialized_) |
| 470 return; | 470 return; |
| 471 | 471 |
| 472 std::vector<NetworkActionPredictorDatabase::Row::Id> id_list; | 472 std::vector<NetworkActionPredictorDatabase::Row::Id> id_list; |
| 473 | 473 |
| 474 for (DBCacheMap::iterator it = db_cache_.begin(); it != db_cache_.end();) { | 474 for (DBCacheMap::iterator it = db_cache_.begin(); it != db_cache_.end();) { |
| 475 if (urls.find(it->first.url) != urls.end()) { | 475 if (std::find_if(rows.begin(), rows.end(), |
| 476 history::URLRow::URLRowHasURL(it->first.url)) != rows.end()) { |
| 476 const DBIdCacheMap::iterator id_it = db_id_cache_.find(it->first); | 477 const DBIdCacheMap::iterator id_it = db_id_cache_.find(it->first); |
| 477 DCHECK(id_it != db_id_cache_.end()); | 478 DCHECK(id_it != db_id_cache_.end()); |
| 478 id_list.push_back(id_it->second); | 479 id_list.push_back(id_it->second); |
| 479 db_id_cache_.erase(id_it); | 480 db_id_cache_.erase(id_it); |
| 480 db_cache_.erase(it++); | 481 db_cache_.erase(it++); |
| 481 } else { | 482 } else { |
| 482 ++it; | 483 ++it; |
| 483 } | 484 } |
| 484 } | 485 } |
| 485 | 486 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 503 | 504 |
| 504 content::BrowserThread::PostTask(content::BrowserThread::DB, FROM_HERE, | 505 content::BrowserThread::PostTask(content::BrowserThread::DB, FROM_HERE, |
| 505 base::Bind(&NetworkActionPredictorDatabase::CommitTransaction, db_)); | 506 base::Bind(&NetworkActionPredictorDatabase::CommitTransaction, db_)); |
| 506 } | 507 } |
| 507 | 508 |
| 508 NetworkActionPredictor::TransitionalMatch::TransitionalMatch() { | 509 NetworkActionPredictor::TransitionalMatch::TransitionalMatch() { |
| 509 } | 510 } |
| 510 | 511 |
| 511 NetworkActionPredictor::TransitionalMatch::~TransitionalMatch() { | 512 NetworkActionPredictor::TransitionalMatch::~TransitionalMatch() { |
| 512 } | 513 } |
| OLD | NEW |