| 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/history/text_database_manager.h" | 5 #include "chrome/browser/history/text_database_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 return new_db; | 552 return new_db; |
| 553 } | 553 } |
| 554 | 554 |
| 555 TextDatabase* TextDatabaseManager::GetDBForTime(Time time, | 555 TextDatabase* TextDatabaseManager::GetDBForTime(Time time, |
| 556 bool create_if_necessary) { | 556 bool create_if_necessary) { |
| 557 return GetDB(TimeToID(time), create_if_necessary); | 557 return GetDB(TimeToID(time), create_if_necessary); |
| 558 } | 558 } |
| 559 | 559 |
| 560 void TextDatabaseManager::ScheduleFlushOldChanges() { | 560 void TextDatabaseManager::ScheduleFlushOldChanges() { |
| 561 weak_factory_.InvalidateWeakPtrs(); | 561 weak_factory_.InvalidateWeakPtrs(); |
| 562 MessageLoop::current()->PostDelayedTask( | 562 base::MessageLoop::current()->PostDelayedTask( |
| 563 FROM_HERE, | 563 FROM_HERE, |
| 564 base::Bind(&TextDatabaseManager::FlushOldChanges, | 564 base::Bind(&TextDatabaseManager::FlushOldChanges, |
| 565 weak_factory_.GetWeakPtr()), | 565 weak_factory_.GetWeakPtr()), |
| 566 base::TimeDelta::FromSeconds(kExpirationSeconds)); | 566 base::TimeDelta::FromSeconds(kExpirationSeconds)); |
| 567 } | 567 } |
| 568 | 568 |
| 569 void TextDatabaseManager::FlushOldChanges() { | 569 void TextDatabaseManager::FlushOldChanges() { |
| 570 FlushOldChangesForTime(TimeTicks::Now()); | 570 FlushOldChangesForTime(TimeTicks::Now()); |
| 571 } | 571 } |
| 572 | 572 |
| 573 void TextDatabaseManager::FlushOldChangesForTime(TimeTicks now) { | 573 void TextDatabaseManager::FlushOldChangesForTime(TimeTicks now) { |
| 574 // The end of the list is the oldest, so we just start from there committing | 574 // The end of the list is the oldest, so we just start from there committing |
| 575 // things until we get something too new. | 575 // things until we get something too new. |
| 576 RecentChangeList::reverse_iterator i = recent_changes_.rbegin(); | 576 RecentChangeList::reverse_iterator i = recent_changes_.rbegin(); |
| 577 while (i != recent_changes_.rend() && i->second.Expired(now)) { | 577 while (i != recent_changes_.rend() && i->second.Expired(now)) { |
| 578 AddPageData(i->first, i->second.url_id(), i->second.visit_id(), | 578 AddPageData(i->first, i->second.url_id(), i->second.visit_id(), |
| 579 i->second.visit_time(), i->second.title(), i->second.body()); | 579 i->second.visit_time(), i->second.title(), i->second.body()); |
| 580 i = recent_changes_.Erase(i); | 580 i = recent_changes_.Erase(i); |
| 581 } | 581 } |
| 582 | 582 |
| 583 ScheduleFlushOldChanges(); | 583 ScheduleFlushOldChanges(); |
| 584 } | 584 } |
| 585 | 585 |
| 586 } // namespace history | 586 } // namespace history |
| OLD | NEW |