| 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 "components/history/core/browser/history_backend.h" | 5 #include "components/history/core/browser/history_backend.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 #include <list> | 9 #include <list> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 | 417 |
| 418 auto top_hosts = db_->TopHosts(num_hosts); | 418 auto top_hosts = db_->TopHosts(num_hosts); |
| 419 | 419 |
| 420 host_ranks_.clear(); | 420 host_ranks_.clear(); |
| 421 int i = 0; | 421 int i = 0; |
| 422 for (const auto& host_count : top_hosts) | 422 for (const auto& host_count : top_hosts) |
| 423 host_ranks_[host_count.first] = i++; | 423 host_ranks_[host_count.first] = i++; |
| 424 return top_hosts; | 424 return top_hosts; |
| 425 } | 425 } |
| 426 | 426 |
| 427 OriginCountMap HistoryBackend::GetCountsForOrigins( | 427 OriginCountAndLastVisitMap HistoryBackend::GetCountsAndLastVisitForOrigins( |
| 428 const std::set<GURL>& origins) const { | 428 const std::set<GURL>& origins) const { |
| 429 if (!db_) | 429 if (!db_) |
| 430 return OriginCountMap(); | 430 return OriginCountAndLastVisitMap(); |
| 431 | 431 |
| 432 URLDatabase::URLEnumerator it; | 432 URLDatabase::URLEnumerator it; |
| 433 if (!db_->InitURLEnumeratorForEverything(&it)) | 433 if (!db_->InitURLEnumeratorForEverything(&it)) |
| 434 return OriginCountMap(); | 434 return OriginCountAndLastVisitMap(); |
| 435 | 435 |
| 436 OriginCountMap origin_count_map; | 436 OriginCountAndLastVisitMap origin_count_map; |
| 437 for (const GURL& origin : origins) | 437 for (const GURL& origin : origins) |
| 438 origin_count_map[origin] = 0; | 438 origin_count_map[origin] = std::make_pair(0, base::Time()); |
| 439 | 439 |
| 440 URLRow row; | 440 URLRow row; |
| 441 while (it.GetNextURL(&row)) { | 441 while (it.GetNextURL(&row)) { |
| 442 GURL origin = row.url().GetOrigin(); | 442 GURL origin = row.url().GetOrigin(); |
| 443 if (ContainsValue(origins, origin)) | 443 auto iter = origin_count_map.find(origin); |
| 444 ++origin_count_map[origin]; | 444 if (iter != origin_count_map.end()) { |
| 445 std::pair<int, base::Time>& value = iter->second; |
| 446 ++(value.first); |
| 447 if (value.second.is_null() || value.second < row.last_visit()) |
| 448 value.second = row.last_visit(); |
| 449 } |
| 445 } | 450 } |
| 446 | 451 |
| 447 return origin_count_map; | 452 return origin_count_map; |
| 448 } | 453 } |
| 449 | 454 |
| 450 int HistoryBackend::HostRankIfAvailable(const GURL& url) const { | 455 int HistoryBackend::HostRankIfAvailable(const GURL& url) const { |
| 451 auto it = host_ranks_.find(HostForTopHosts(url)); | 456 auto it = host_ranks_.find(HostForTopHosts(url)); |
| 452 return it != host_ranks_.end() ? it->second : kMaxTopHosts; | 457 return it != host_ranks_.end() ? it->second : kMaxTopHosts; |
| 453 } | 458 } |
| 454 | 459 |
| (...skipping 2167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2622 // transaction is currently open. | 2627 // transaction is currently open. |
| 2623 db_->CommitTransaction(); | 2628 db_->CommitTransaction(); |
| 2624 db_->Vacuum(); | 2629 db_->Vacuum(); |
| 2625 db_->BeginTransaction(); | 2630 db_->BeginTransaction(); |
| 2626 db_->GetStartDate(&first_recorded_time_); | 2631 db_->GetStartDate(&first_recorded_time_); |
| 2627 | 2632 |
| 2628 return true; | 2633 return true; |
| 2629 } | 2634 } |
| 2630 | 2635 |
| 2631 } // namespace history | 2636 } // namespace history |
| OLD | NEW |