 Chromium Code Reviews
 Chromium Code Reviews Issue 2261073002:
  Make HistoryBackend a client of memory coordinator  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 2261073002:
  Make HistoryBackend a client of memory coordinator  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| 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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 const HistoryDatabaseParams& history_database_params) { | 246 const HistoryDatabaseParams& history_database_params) { | 
| 246 // HistoryBackend is created on the UI thread by HistoryService, then the | 247 // HistoryBackend is created on the UI thread by HistoryService, then the | 
| 247 // HistoryBackend::Init() method is called on the DB thread. Create the | 248 // HistoryBackend::Init() method is called on the DB thread. Create the | 
| 248 // base::SupportsUserData on the DB thread since it is not thread-safe. | 249 // base::SupportsUserData on the DB thread since it is not thread-safe. | 
| 249 supports_user_data_helper_.reset(new HistoryBackendHelper); | 250 supports_user_data_helper_.reset(new HistoryBackendHelper); | 
| 250 | 251 | 
| 251 if (!force_fail) | 252 if (!force_fail) | 
| 252 InitImpl(history_database_params); | 253 InitImpl(history_database_params); | 
| 253 delegate_->DBLoaded(); | 254 delegate_->DBLoaded(); | 
| 254 typed_url_syncable_service_.reset(new TypedUrlSyncableService(this)); | 255 typed_url_syncable_service_.reset(new TypedUrlSyncableService(this)); | 
| 255 memory_pressure_listener_.reset(new base::MemoryPressureListener( | 256 if (memory_coordinator::MemoryCoordinator::GetInstance()) { | 
| 256 base::Bind(&HistoryBackend::OnMemoryPressure, base::Unretained(this)))); | 257 memory_coordinator::MemoryCoordinator::GetInstance()->RegisterClient(this); | 
| 
sky
2016/08/24 23:48:21
Shouldn't you unregister in the destructor?
 
bashi
2016/08/24 23:57:53
Yes. Done.
 | |
| 258 } else { | |
| 259 memory_pressure_listener_.reset(new base::MemoryPressureListener( | |
| 260 base::Bind(&HistoryBackend::OnMemoryPressure, base::Unretained(this)))); | |
| 261 } | |
| 257 } | 262 } | 
| 258 | 263 | 
| 259 void HistoryBackend::SetOnBackendDestroyTask(base::MessageLoop* message_loop, | 264 void HistoryBackend::SetOnBackendDestroyTask(base::MessageLoop* message_loop, | 
| 260 const base::Closure& task) { | 265 const base::Closure& task) { | 
| 261 if (!backend_destroy_task_.is_null()) | 266 if (!backend_destroy_task_.is_null()) | 
| 262 DLOG(WARNING) << "Setting more than one destroy task, overriding"; | 267 DLOG(WARNING) << "Setting more than one destroy task, overriding"; | 
| 263 backend_destroy_message_loop_ = message_loop; | 268 backend_destroy_message_loop_ = message_loop; | 
| 264 backend_destroy_task_ = task; | 269 backend_destroy_task_ = task; | 
| 265 } | 270 } | 
| 266 | 271 | 
| (...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 730 #if defined(OS_ANDROID) | 735 #if defined(OS_ANDROID) | 
| 731 if (backend_client_) { | 736 if (backend_client_) { | 
| 732 backend_client_->OnHistoryBackendInitialized( | 737 backend_client_->OnHistoryBackendInitialized( | 
| 733 this, db_.get(), thumbnail_db_.get(), history_dir_); | 738 this, db_.get(), thumbnail_db_.get(), history_dir_); | 
| 734 } | 739 } | 
| 735 #endif | 740 #endif | 
| 736 | 741 | 
| 737 LOCAL_HISTOGRAM_TIMES("History.InitTime", TimeTicks::Now() - beginning_time); | 742 LOCAL_HISTOGRAM_TIMES("History.InitTime", TimeTicks::Now() - beginning_time); | 
| 738 } | 743 } | 
| 739 | 744 | 
| 745 void HistoryBackend::TrimMemory(bool trim_aggressively) { | |
| 746 if (db_) | |
| 747 db_->TrimMemory(trim_aggressively); | |
| 748 if (thumbnail_db_) | |
| 749 thumbnail_db_->TrimMemory(trim_aggressively); | |
| 750 } | |
| 751 | |
| 740 void HistoryBackend::OnMemoryPressure( | 752 void HistoryBackend::OnMemoryPressure( | 
| 741 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { | 753 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { | 
| 742 bool trim_aggressively = | 754 bool trim_aggressively = | 
| 743 memory_pressure_level == | 755 memory_pressure_level == | 
| 744 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL; | 756 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL; | 
| 745 if (db_) | 757 TrimMemory(trim_aggressively); | 
| 746 db_->TrimMemory(trim_aggressively); | 758 } | 
| 747 if (thumbnail_db_) | 759 | 
| 748 thumbnail_db_->TrimMemory(trim_aggressively); | 760 void HistoryBackend::OnMemoryStateChange( | 
| 
sky
2016/08/24 23:48:21
Make position match that of header.
 
bashi
2016/08/24 23:57:53
Done.
 | |
| 761 memory_coordinator::MemoryState state) { | |
| 762 bool trim_aggressively = state == memory_coordinator::MemoryState::SUSPENDED; | |
| 763 TrimMemory(trim_aggressively); | |
| 749 } | 764 } | 
| 750 | 765 | 
| 751 void HistoryBackend::CloseAllDatabases() { | 766 void HistoryBackend::CloseAllDatabases() { | 
| 752 if (db_) { | 767 if (db_) { | 
| 753 // Commit the long-running transaction. | 768 // Commit the long-running transaction. | 
| 754 db_->CommitTransaction(); | 769 db_->CommitTransaction(); | 
| 755 db_.reset(); | 770 db_.reset(); | 
| 756 // Forget the first recorded time since the database is closed. | 771 // Forget the first recorded time since the database is closed. | 
| 757 first_recorded_time_ = base::Time(); | 772 first_recorded_time_ = base::Time(); | 
| 758 } | 773 } | 
| (...skipping 1870 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2629 // transaction is currently open. | 2644 // transaction is currently open. | 
| 2630 db_->CommitTransaction(); | 2645 db_->CommitTransaction(); | 
| 2631 db_->Vacuum(); | 2646 db_->Vacuum(); | 
| 2632 db_->BeginTransaction(); | 2647 db_->BeginTransaction(); | 
| 2633 db_->GetStartDate(&first_recorded_time_); | 2648 db_->GetStartDate(&first_recorded_time_); | 
| 2634 | 2649 | 
| 2635 return true; | 2650 return true; | 
| 2636 } | 2651 } | 
| 2637 | 2652 | 
| 2638 } // namespace history | 2653 } // namespace history | 
| OLD | NEW |