| 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/message_loop/message_loop.h" | 20 #include "base/message_loop/message_loop.h" |
| 20 #include "base/metrics/histogram_macros.h" | 21 #include "base/metrics/histogram_macros.h" |
| 21 #include "base/rand_util.h" | 22 #include "base/rand_util.h" |
| 22 #include "base/sequenced_task_runner.h" | 23 #include "base/sequenced_task_runner.h" |
| 23 #include "base/single_thread_task_runner.h" | 24 #include "base/single_thread_task_runner.h" |
| 24 #include "base/strings/string_util.h" | 25 #include "base/strings/string_util.h" |
| 25 #include "base/strings/utf_string_conversions.h" | 26 #include "base/strings/utf_string_conversions.h" |
| 26 #include "base/time/time.h" | 27 #include "base/time/time.h" |
| 27 #include "base/trace_event/trace_event.h" | 28 #include "base/trace_event/trace_event.h" |
| 28 #include "build/build_config.h" | 29 #include "build/build_config.h" |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 scheduled_kill_db_(false), | 214 scheduled_kill_db_(false), |
| 214 expirer_(this, backend_client.get(), task_runner), | 215 expirer_(this, backend_client.get(), task_runner), |
| 215 recent_redirects_(kMaxRedirectCount), | 216 recent_redirects_(kMaxRedirectCount), |
| 216 backend_destroy_message_loop_(nullptr), | 217 backend_destroy_message_loop_(nullptr), |
| 217 segment_queried_(false), | 218 segment_queried_(false), |
| 218 backend_client_(std::move(backend_client)), | 219 backend_client_(std::move(backend_client)), |
| 219 task_runner_(task_runner) {} | 220 task_runner_(task_runner) {} |
| 220 | 221 |
| 221 HistoryBackend::~HistoryBackend() { | 222 HistoryBackend::~HistoryBackend() { |
| 222 DCHECK(!scheduled_commit_) << "Deleting without cleanup"; | 223 DCHECK(!scheduled_commit_) << "Deleting without cleanup"; |
| 223 base::STLDeleteContainerPointers(queued_history_db_tasks_.begin(), | |
| 224 queued_history_db_tasks_.end()); | |
| 225 queued_history_db_tasks_.clear(); | 224 queued_history_db_tasks_.clear(); |
| 226 | 225 |
| 227 // Release stashed embedder object before cleaning up the databases. | 226 // Release stashed embedder object before cleaning up the databases. |
| 228 supports_user_data_helper_.reset(); | 227 supports_user_data_helper_.reset(); |
| 229 | 228 |
| 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. |
| (...skipping 2040 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2275 void HistoryBackend::CancelScheduledCommit() { | 2274 void HistoryBackend::CancelScheduledCommit() { |
| 2276 if (scheduled_commit_) { | 2275 if (scheduled_commit_) { |
| 2277 scheduled_commit_->Cancel(); | 2276 scheduled_commit_->Cancel(); |
| 2278 scheduled_commit_ = nullptr; | 2277 scheduled_commit_ = nullptr; |
| 2279 } | 2278 } |
| 2280 } | 2279 } |
| 2281 | 2280 |
| 2282 void HistoryBackend::ProcessDBTaskImpl() { | 2281 void HistoryBackend::ProcessDBTaskImpl() { |
| 2283 if (!db_) { | 2282 if (!db_) { |
| 2284 // db went away, release all the refs. | 2283 // db went away, release all the refs. |
| 2285 base::STLDeleteContainerPointers(queued_history_db_tasks_.begin(), | |
| 2286 queued_history_db_tasks_.end()); | |
| 2287 queued_history_db_tasks_.clear(); | 2284 queued_history_db_tasks_.clear(); |
| 2288 return; | 2285 return; |
| 2289 } | 2286 } |
| 2290 | 2287 |
| 2291 // Remove any canceled tasks. | 2288 // Remove any canceled tasks. |
| 2292 while (!queued_history_db_tasks_.empty()) { | 2289 while (!queued_history_db_tasks_.empty()) { |
| 2293 QueuedHistoryDBTask* task = queued_history_db_tasks_.front(); | 2290 QueuedHistoryDBTask* task = queued_history_db_tasks_.front().get(); |
| 2294 if (!task->is_canceled()) | 2291 if (!task->is_canceled()) |
| 2295 break; | 2292 break; |
| 2296 | 2293 |
| 2297 delete task; | |
| 2298 queued_history_db_tasks_.pop_front(); | 2294 queued_history_db_tasks_.pop_front(); |
| 2299 } | 2295 } |
| 2300 if (queued_history_db_tasks_.empty()) | 2296 if (queued_history_db_tasks_.empty()) |
| 2301 return; | 2297 return; |
| 2302 | 2298 |
| 2303 // Run the first task. | 2299 // Run the first task. |
| 2304 std::unique_ptr<QueuedHistoryDBTask> task(queued_history_db_tasks_.front()); | 2300 std::unique_ptr<QueuedHistoryDBTask> task = |
| 2301 std::move(queued_history_db_tasks_.front()); |
| 2305 queued_history_db_tasks_.pop_front(); | 2302 queued_history_db_tasks_.pop_front(); |
| 2306 if (task->Run(this, db_.get())) { | 2303 if (task->Run(this, db_.get())) { |
| 2307 // The task is done, notify the callback. | 2304 // The task is done, notify the callback. |
| 2308 task->DoneRun(); | 2305 task->DoneRun(); |
| 2309 } else { | 2306 } else { |
| 2310 // The task wants to run some more. Schedule it at the end of the current | 2307 // The task wants to run some more. Schedule it at the end of the current |
| 2311 // tasks, and process it after an invoke later. | 2308 // tasks, and process it after an invoke later. |
| 2312 queued_history_db_tasks_.push_back(task.release()); | 2309 queued_history_db_tasks_.push_back(std::move(task)); |
| 2313 task_runner_->PostTask( | 2310 task_runner_->PostTask( |
| 2314 FROM_HERE, base::Bind(&HistoryBackend::ProcessDBTaskImpl, this)); | 2311 FROM_HERE, base::Bind(&HistoryBackend::ProcessDBTaskImpl, this)); |
| 2315 } | 2312 } |
| 2316 } | 2313 } |
| 2317 | 2314 |
| 2318 //////////////////////////////////////////////////////////////////////////////// | 2315 //////////////////////////////////////////////////////////////////////////////// |
| 2319 // | 2316 // |
| 2320 // Generic operations | 2317 // Generic operations |
| 2321 // | 2318 // |
| 2322 //////////////////////////////////////////////////////////////////////////////// | 2319 //////////////////////////////////////////////////////////////////////////////// |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2497 base::SupportsUserData::Data* data) { | 2494 base::SupportsUserData::Data* data) { |
| 2498 DCHECK(supports_user_data_helper_); | 2495 DCHECK(supports_user_data_helper_); |
| 2499 supports_user_data_helper_->SetUserData(key, data); | 2496 supports_user_data_helper_->SetUserData(key, data); |
| 2500 } | 2497 } |
| 2501 | 2498 |
| 2502 void HistoryBackend::ProcessDBTask( | 2499 void HistoryBackend::ProcessDBTask( |
| 2503 std::unique_ptr<HistoryDBTask> task, | 2500 std::unique_ptr<HistoryDBTask> task, |
| 2504 scoped_refptr<base::SingleThreadTaskRunner> origin_loop, | 2501 scoped_refptr<base::SingleThreadTaskRunner> origin_loop, |
| 2505 const base::CancelableTaskTracker::IsCanceledCallback& is_canceled) { | 2502 const base::CancelableTaskTracker::IsCanceledCallback& is_canceled) { |
| 2506 bool scheduled = !queued_history_db_tasks_.empty(); | 2503 bool scheduled = !queued_history_db_tasks_.empty(); |
| 2507 queued_history_db_tasks_.push_back( | 2504 queued_history_db_tasks_.push_back(base::MakeUnique<QueuedHistoryDBTask>( |
| 2508 new QueuedHistoryDBTask(std::move(task), origin_loop, is_canceled)); | 2505 std::move(task), origin_loop, is_canceled)); |
| 2509 if (!scheduled) | 2506 if (!scheduled) |
| 2510 ProcessDBTaskImpl(); | 2507 ProcessDBTaskImpl(); |
| 2511 } | 2508 } |
| 2512 | 2509 |
| 2513 void HistoryBackend::NotifyFaviconsChanged(const std::set<GURL>& page_urls, | 2510 void HistoryBackend::NotifyFaviconsChanged(const std::set<GURL>& page_urls, |
| 2514 const GURL& icon_url) { | 2511 const GURL& icon_url) { |
| 2515 if (delegate_) | 2512 if (delegate_) |
| 2516 delegate_->NotifyFaviconsChanged(page_urls, icon_url); | 2513 delegate_->NotifyFaviconsChanged(page_urls, icon_url); |
| 2517 } | 2514 } |
| 2518 | 2515 |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2668 // transaction is currently open. | 2665 // transaction is currently open. |
| 2669 db_->CommitTransaction(); | 2666 db_->CommitTransaction(); |
| 2670 db_->Vacuum(); | 2667 db_->Vacuum(); |
| 2671 db_->BeginTransaction(); | 2668 db_->BeginTransaction(); |
| 2672 db_->GetStartDate(&first_recorded_time_); | 2669 db_->GetStartDate(&first_recorded_time_); |
| 2673 | 2670 |
| 2674 return true; | 2671 return true; |
| 2675 } | 2672 } |
| 2676 | 2673 |
| 2677 } // namespace history | 2674 } // namespace history |
| OLD | NEW |