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