| 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> |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <set> | 12 #include <set> |
| 13 #include <utility> | 13 #include <utility> |
| 14 #include <vector> | 14 #include <vector> |
| 15 | 15 |
| 16 #include "base/bind.h" | 16 #include "base/bind.h" |
| 17 #include "base/compiler_specific.h" | 17 #include "base/compiler_specific.h" |
| 18 #include "base/files/file_enumerator.h" | 18 #include "base/files/file_enumerator.h" |
| 19 #include "base/memory/ptr_util.h" | 19 #include "base/memory/ptr_util.h" |
| 20 #include "base/message_loop/message_loop.h" | |
| 21 #include "base/metrics/histogram_macros.h" | 20 #include "base/metrics/histogram_macros.h" |
| 22 #include "base/rand_util.h" | 21 #include "base/rand_util.h" |
| 23 #include "base/sequenced_task_runner.h" | 22 #include "base/sequenced_task_runner.h" |
| 24 #include "base/single_thread_task_runner.h" | 23 #include "base/single_thread_task_runner.h" |
| 25 #include "base/strings/string_util.h" | 24 #include "base/strings/string_util.h" |
| 26 #include "base/strings/utf_string_conversions.h" | 25 #include "base/strings/utf_string_conversions.h" |
| 27 #include "base/time/time.h" | 26 #include "base/time/time.h" |
| 28 #include "base/trace_event/trace_event.h" | 27 #include "base/trace_event/trace_event.h" |
| 29 #include "build/build_config.h" | 28 #include "build/build_config.h" |
| 30 #include "components/favicon_base/favicon_util.h" | 29 #include "components/favicon_base/favicon_util.h" |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 // HistoryBackend -------------------------------------------------------------- | 205 // HistoryBackend -------------------------------------------------------------- |
| 207 | 206 |
| 208 HistoryBackend::HistoryBackend( | 207 HistoryBackend::HistoryBackend( |
| 209 Delegate* delegate, | 208 Delegate* delegate, |
| 210 std::unique_ptr<HistoryBackendClient> backend_client, | 209 std::unique_ptr<HistoryBackendClient> backend_client, |
| 211 scoped_refptr<base::SequencedTaskRunner> task_runner) | 210 scoped_refptr<base::SequencedTaskRunner> task_runner) |
| 212 : delegate_(delegate), | 211 : delegate_(delegate), |
| 213 scheduled_kill_db_(false), | 212 scheduled_kill_db_(false), |
| 214 expirer_(this, backend_client.get(), task_runner), | 213 expirer_(this, backend_client.get(), task_runner), |
| 215 recent_redirects_(kMaxRedirectCount), | 214 recent_redirects_(kMaxRedirectCount), |
| 216 backend_destroy_message_loop_(nullptr), | |
| 217 segment_queried_(false), | 215 segment_queried_(false), |
| 218 backend_client_(std::move(backend_client)), | 216 backend_client_(std::move(backend_client)), |
| 219 task_runner_(task_runner) {} | 217 task_runner_(task_runner) {} |
| 220 | 218 |
| 221 HistoryBackend::~HistoryBackend() { | 219 HistoryBackend::~HistoryBackend() { |
| 222 DCHECK(!scheduled_commit_) << "Deleting without cleanup"; | 220 DCHECK(!scheduled_commit_) << "Deleting without cleanup"; |
| 223 queued_history_db_tasks_.clear(); | 221 queued_history_db_tasks_.clear(); |
| 224 | 222 |
| 225 // Release stashed embedder object before cleaning up the databases. | 223 // Release stashed embedder object before cleaning up the databases. |
| 226 supports_user_data_helper_.reset(); | 224 supports_user_data_helper_.reset(); |
| 227 | 225 |
| 228 // First close the databases before optionally running the "destroy" task. | 226 // First close the databases before optionally running the "destroy" task. |
| 229 CloseAllDatabases(); | 227 CloseAllDatabases(); |
| 230 | 228 |
| 231 if (!backend_destroy_task_.is_null()) { | 229 if (!backend_destroy_task_.is_null()) { |
| 232 // Notify an interested party (typically a unit test) that we're done. | 230 // Notify an interested party (typically a unit test) that we're done. |
| 233 DCHECK(backend_destroy_message_loop_); | 231 DCHECK(backend_destroy_task_runner_); |
| 234 backend_destroy_message_loop_->task_runner()->PostTask( | 232 backend_destroy_task_runner_->PostTask(FROM_HERE, backend_destroy_task_); |
| 235 FROM_HERE, backend_destroy_task_); | |
| 236 } | 233 } |
| 237 | 234 |
| 238 #if defined(OS_ANDROID) | 235 #if defined(OS_ANDROID) |
| 239 if (backend_client_ && !history_dir_.empty()) | 236 if (backend_client_ && !history_dir_.empty()) |
| 240 backend_client_->OnHistoryBackendDestroyed(this, history_dir_); | 237 backend_client_->OnHistoryBackendDestroyed(this, history_dir_); |
| 241 #endif | 238 #endif |
| 242 } | 239 } |
| 243 | 240 |
| 244 void HistoryBackend::Init( | 241 void HistoryBackend::Init( |
| 245 bool force_fail, | 242 bool force_fail, |
| 246 const HistoryDatabaseParams& history_database_params) { | 243 const HistoryDatabaseParams& history_database_params) { |
| 247 // HistoryBackend is created on the UI thread by HistoryService, then the | 244 // HistoryBackend is created on the UI thread by HistoryService, then the |
| 248 // HistoryBackend::Init() method is called on the DB thread. Create the | 245 // HistoryBackend::Init() method is called on the DB thread. Create the |
| 249 // base::SupportsUserData on the DB thread since it is not thread-safe. | 246 // base::SupportsUserData on the DB thread since it is not thread-safe. |
| 250 supports_user_data_helper_.reset(new HistoryBackendHelper); | 247 supports_user_data_helper_.reset(new HistoryBackendHelper); |
| 251 | 248 |
| 252 if (!force_fail) | 249 if (!force_fail) |
| 253 InitImpl(history_database_params); | 250 InitImpl(history_database_params); |
| 254 delegate_->DBLoaded(); | 251 delegate_->DBLoaded(); |
| 255 typed_url_syncable_service_.reset(new TypedUrlSyncableService(this)); | 252 typed_url_syncable_service_.reset(new TypedUrlSyncableService(this)); |
| 256 memory_pressure_listener_.reset(new base::MemoryPressureListener( | 253 memory_pressure_listener_.reset(new base::MemoryPressureListener( |
| 257 base::Bind(&HistoryBackend::OnMemoryPressure, base::Unretained(this)))); | 254 base::Bind(&HistoryBackend::OnMemoryPressure, base::Unretained(this)))); |
| 258 } | 255 } |
| 259 | 256 |
| 260 void HistoryBackend::SetOnBackendDestroyTask(base::MessageLoop* message_loop, | 257 void HistoryBackend::SetOnBackendDestroyTask( |
| 261 const base::Closure& task) { | 258 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 259 const base::Closure& task) { |
| 262 if (!backend_destroy_task_.is_null()) | 260 if (!backend_destroy_task_.is_null()) |
| 263 DLOG(WARNING) << "Setting more than one destroy task, overriding"; | 261 DLOG(WARNING) << "Setting more than one destroy task, overriding"; |
| 264 backend_destroy_message_loop_ = message_loop; | 262 backend_destroy_task_runner_ = std::move(task_runner); |
| 265 backend_destroy_task_ = task; | 263 backend_destroy_task_ = task; |
| 266 } | 264 } |
| 267 | 265 |
| 268 void HistoryBackend::Closing() { | 266 void HistoryBackend::Closing() { |
| 269 // Any scheduled commit will have a reference to us, we must make it | 267 // Any scheduled commit will have a reference to us, we must make it |
| 270 // release that reference before we can be destroyed. | 268 // release that reference before we can be destroyed. |
| 271 CancelScheduledCommit(); | 269 CancelScheduledCommit(); |
| 272 | 270 |
| 273 // Release our reference to the delegate, this reference will be keeping the | 271 // Release our reference to the delegate, this reference will be keeping the |
| 274 // history service alive. | 272 // history service alive. |
| (...skipping 2367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2642 // transaction is currently open. | 2640 // transaction is currently open. |
| 2643 db_->CommitTransaction(); | 2641 db_->CommitTransaction(); |
| 2644 db_->Vacuum(); | 2642 db_->Vacuum(); |
| 2645 db_->BeginTransaction(); | 2643 db_->BeginTransaction(); |
| 2646 db_->GetStartDate(&first_recorded_time_); | 2644 db_->GetStartDate(&first_recorded_time_); |
| 2647 | 2645 |
| 2648 return true; | 2646 return true; |
| 2649 } | 2647 } |
| 2650 | 2648 |
| 2651 } // namespace history | 2649 } // namespace history |
| OLD | NEW |