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