| 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 21 matching lines...) Expand all Loading... |
| 32 #include "components/history/core/browser/history_backend_observer.h" | 32 #include "components/history/core/browser/history_backend_observer.h" |
| 33 #include "components/history/core/browser/history_constants.h" | 33 #include "components/history/core/browser/history_constants.h" |
| 34 #include "components/history/core/browser/history_database.h" | 34 #include "components/history/core/browser/history_database.h" |
| 35 #include "components/history/core/browser/history_database_params.h" | 35 #include "components/history/core/browser/history_database_params.h" |
| 36 #include "components/history/core/browser/history_db_task.h" | 36 #include "components/history/core/browser/history_db_task.h" |
| 37 #include "components/history/core/browser/in_memory_history_backend.h" | 37 #include "components/history/core/browser/in_memory_history_backend.h" |
| 38 #include "components/history/core/browser/keyword_search_term.h" | 38 #include "components/history/core/browser/keyword_search_term.h" |
| 39 #include "components/history/core/browser/page_usage_data.h" | 39 #include "components/history/core/browser/page_usage_data.h" |
| 40 #include "components/history/core/browser/typed_url_syncable_service.h" | 40 #include "components/history/core/browser/typed_url_syncable_service.h" |
| 41 #include "components/history/core/browser/url_utils.h" | 41 #include "components/history/core/browser/url_utils.h" |
| 42 #include "components/memory_coordinator/browser/memory_coordinator.h" | |
| 43 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 42 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 44 #include "sql/error_delegate_util.h" | 43 #include "sql/error_delegate_util.h" |
| 45 #include "third_party/skia/include/core/SkBitmap.h" | 44 #include "third_party/skia/include/core/SkBitmap.h" |
| 46 #include "ui/gfx/codec/png_codec.h" | 45 #include "ui/gfx/codec/png_codec.h" |
| 47 #include "url/gurl.h" | 46 #include "url/gurl.h" |
| 48 #include "url/url_constants.h" | 47 #include "url/url_constants.h" |
| 49 | 48 |
| 50 #if defined(OS_IOS) | 49 #if defined(OS_IOS) |
| 51 #include "base/ios/scoped_critical_action.h" | 50 #include "base/ios/scoped_critical_action.h" |
| 52 #endif | 51 #endif |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 // First close the databases before optionally running the "destroy" task. | 227 // First close the databases before optionally running the "destroy" task. |
| 229 CloseAllDatabases(); | 228 CloseAllDatabases(); |
| 230 | 229 |
| 231 if (!backend_destroy_task_.is_null()) { | 230 if (!backend_destroy_task_.is_null()) { |
| 232 // Notify an interested party (typically a unit test) that we're done. | 231 // Notify an interested party (typically a unit test) that we're done. |
| 233 DCHECK(backend_destroy_message_loop_); | 232 DCHECK(backend_destroy_message_loop_); |
| 234 backend_destroy_message_loop_->task_runner()->PostTask( | 233 backend_destroy_message_loop_->task_runner()->PostTask( |
| 235 FROM_HERE, backend_destroy_task_); | 234 FROM_HERE, backend_destroy_task_); |
| 236 } | 235 } |
| 237 | 236 |
| 238 if (memory_coordinator::MemoryCoordinator::GetInstance()) { | |
| 239 memory_coordinator::MemoryCoordinator::GetInstance()->UnregisterClient( | |
| 240 this); | |
| 241 } | |
| 242 | |
| 243 #if defined(OS_ANDROID) | 237 #if defined(OS_ANDROID) |
| 244 if (backend_client_ && !history_dir_.empty()) | 238 if (backend_client_ && !history_dir_.empty()) |
| 245 backend_client_->OnHistoryBackendDestroyed(this, history_dir_); | 239 backend_client_->OnHistoryBackendDestroyed(this, history_dir_); |
| 246 #endif | 240 #endif |
| 247 } | 241 } |
| 248 | 242 |
| 249 void HistoryBackend::Init( | 243 void HistoryBackend::Init( |
| 250 bool force_fail, | 244 bool force_fail, |
| 251 const HistoryDatabaseParams& history_database_params) { | 245 const HistoryDatabaseParams& history_database_params) { |
| 252 // HistoryBackend is created on the UI thread by HistoryService, then the | 246 // HistoryBackend is created on the UI thread by HistoryService, then the |
| 253 // HistoryBackend::Init() method is called on the DB thread. Create the | 247 // HistoryBackend::Init() method is called on the DB thread. Create the |
| 254 // base::SupportsUserData on the DB thread since it is not thread-safe. | 248 // base::SupportsUserData on the DB thread since it is not thread-safe. |
| 255 supports_user_data_helper_.reset(new HistoryBackendHelper); | 249 supports_user_data_helper_.reset(new HistoryBackendHelper); |
| 256 | 250 |
| 257 if (!force_fail) | 251 if (!force_fail) |
| 258 InitImpl(history_database_params); | 252 InitImpl(history_database_params); |
| 259 delegate_->DBLoaded(); | 253 delegate_->DBLoaded(); |
| 260 typed_url_syncable_service_.reset(new TypedUrlSyncableService(this)); | 254 typed_url_syncable_service_.reset(new TypedUrlSyncableService(this)); |
| 261 if (memory_coordinator::MemoryCoordinator::GetInstance()) { | 255 memory_pressure_listener_.reset(new base::MemoryPressureListener( |
| 262 memory_coordinator::MemoryCoordinator::GetInstance()->RegisterClient(this); | 256 base::Bind(&HistoryBackend::OnMemoryPressure, base::Unretained(this)))); |
| 263 } else { | |
| 264 memory_pressure_listener_.reset(new base::MemoryPressureListener( | |
| 265 base::Bind(&HistoryBackend::OnMemoryPressure, base::Unretained(this)))); | |
| 266 } | |
| 267 } | 257 } |
| 268 | 258 |
| 269 void HistoryBackend::SetOnBackendDestroyTask(base::MessageLoop* message_loop, | 259 void HistoryBackend::SetOnBackendDestroyTask(base::MessageLoop* message_loop, |
| 270 const base::Closure& task) { | 260 const base::Closure& task) { |
| 271 if (!backend_destroy_task_.is_null()) | 261 if (!backend_destroy_task_.is_null()) |
| 272 DLOG(WARNING) << "Setting more than one destroy task, overriding"; | 262 DLOG(WARNING) << "Setting more than one destroy task, overriding"; |
| 273 backend_destroy_message_loop_ = message_loop; | 263 backend_destroy_message_loop_ = message_loop; |
| 274 backend_destroy_task_ = task; | 264 backend_destroy_task_ = task; |
| 275 } | 265 } |
| 276 | 266 |
| (...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 740 #if defined(OS_ANDROID) | 730 #if defined(OS_ANDROID) |
| 741 if (backend_client_) { | 731 if (backend_client_) { |
| 742 backend_client_->OnHistoryBackendInitialized( | 732 backend_client_->OnHistoryBackendInitialized( |
| 743 this, db_.get(), thumbnail_db_.get(), history_dir_); | 733 this, db_.get(), thumbnail_db_.get(), history_dir_); |
| 744 } | 734 } |
| 745 #endif | 735 #endif |
| 746 | 736 |
| 747 LOCAL_HISTOGRAM_TIMES("History.InitTime", TimeTicks::Now() - beginning_time); | 737 LOCAL_HISTOGRAM_TIMES("History.InitTime", TimeTicks::Now() - beginning_time); |
| 748 } | 738 } |
| 749 | 739 |
| 750 void HistoryBackend::TrimMemory(bool trim_aggressively) { | |
| 751 if (db_) | |
| 752 db_->TrimMemory(trim_aggressively); | |
| 753 if (thumbnail_db_) | |
| 754 thumbnail_db_->TrimMemory(trim_aggressively); | |
| 755 } | |
| 756 | |
| 757 void HistoryBackend::OnMemoryPressure( | 740 void HistoryBackend::OnMemoryPressure( |
| 758 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { | 741 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { |
| 759 bool trim_aggressively = | 742 bool trim_aggressively = |
| 760 memory_pressure_level == | 743 memory_pressure_level == |
| 761 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL; | 744 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL; |
| 762 TrimMemory(trim_aggressively); | 745 if (db_) |
| 746 db_->TrimMemory(trim_aggressively); |
| 747 if (thumbnail_db_) |
| 748 thumbnail_db_->TrimMemory(trim_aggressively); |
| 763 } | 749 } |
| 764 | 750 |
| 765 void HistoryBackend::CloseAllDatabases() { | 751 void HistoryBackend::CloseAllDatabases() { |
| 766 if (db_) { | 752 if (db_) { |
| 767 // Commit the long-running transaction. | 753 // Commit the long-running transaction. |
| 768 db_->CommitTransaction(); | 754 db_->CommitTransaction(); |
| 769 db_.reset(); | 755 db_.reset(); |
| 770 // Forget the first recorded time since the database is closed. | 756 // Forget the first recorded time since the database is closed. |
| 771 first_recorded_time_ = base::Time(); | 757 first_recorded_time_ = base::Time(); |
| 772 } | 758 } |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 912 // TODO(brettw) bug 1140015: Add an "add page" notification so the history | 898 // TODO(brettw) bug 1140015: Add an "add page" notification so the history |
| 913 // views can keep in sync. | 899 // views can keep in sync. |
| 914 NotifyURLsModified(changed_urls); | 900 NotifyURLsModified(changed_urls); |
| 915 ScheduleCommit(); | 901 ScheduleCommit(); |
| 916 } | 902 } |
| 917 | 903 |
| 918 bool HistoryBackend::IsExpiredVisitTime(const base::Time& time) { | 904 bool HistoryBackend::IsExpiredVisitTime(const base::Time& time) { |
| 919 return time < expirer_.GetCurrentExpirationTime(); | 905 return time < expirer_.GetCurrentExpirationTime(); |
| 920 } | 906 } |
| 921 | 907 |
| 922 void HistoryBackend::OnMemoryStateChange( | |
| 923 memory_coordinator::MemoryState state) { | |
| 924 bool trim_aggressively = state == memory_coordinator::MemoryState::SUSPENDED; | |
| 925 TrimMemory(trim_aggressively); | |
| 926 } | |
| 927 | |
| 928 void HistoryBackend::SetPageTitle(const GURL& url, | 908 void HistoryBackend::SetPageTitle(const GURL& url, |
| 929 const base::string16& title) { | 909 const base::string16& title) { |
| 930 if (!db_) | 910 if (!db_) |
| 931 return; | 911 return; |
| 932 | 912 |
| 933 // Search for recent redirects which should get the same title. We make a | 913 // Search for recent redirects which should get the same title. We make a |
| 934 // dummy list containing the exact URL visited if there are no redirects so | 914 // dummy list containing the exact URL visited if there are no redirects so |
| 935 // the processing below can be the same. | 915 // the processing below can be the same. |
| 936 RedirectList dummy_list; | 916 RedirectList dummy_list; |
| 937 RedirectList* redirects; | 917 RedirectList* redirects; |
| (...skipping 1719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2657 // transaction is currently open. | 2637 // transaction is currently open. |
| 2658 db_->CommitTransaction(); | 2638 db_->CommitTransaction(); |
| 2659 db_->Vacuum(); | 2639 db_->Vacuum(); |
| 2660 db_->BeginTransaction(); | 2640 db_->BeginTransaction(); |
| 2661 db_->GetStartDate(&first_recorded_time_); | 2641 db_->GetStartDate(&first_recorded_time_); |
| 2662 | 2642 |
| 2663 return true; | 2643 return true; |
| 2664 } | 2644 } |
| 2665 | 2645 |
| 2666 } // namespace history | 2646 } // namespace history |
| OLD | NEW |