Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(575)

Side by Side Diff: components/history/core/browser/history_backend.cc

Issue 2314833002: Remove some uses of stl_util's STLDeleteContainerPointers. (Closed)
Patch Set: remove more Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "build/build_config.h" 28 #include "build/build_config.h"
28 #include "components/favicon_base/select_favicon_frames.h" 29 #include "components/favicon_base/select_favicon_frames.h"
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 scheduled_kill_db_(false), 212 scheduled_kill_db_(false),
212 expirer_(this, backend_client.get(), task_runner), 213 expirer_(this, backend_client.get(), task_runner),
213 recent_redirects_(kMaxRedirectCount), 214 recent_redirects_(kMaxRedirectCount),
214 backend_destroy_message_loop_(nullptr), 215 backend_destroy_message_loop_(nullptr),
215 segment_queried_(false), 216 segment_queried_(false),
216 backend_client_(std::move(backend_client)), 217 backend_client_(std::move(backend_client)),
217 task_runner_(task_runner) {} 218 task_runner_(task_runner) {}
218 219
219 HistoryBackend::~HistoryBackend() { 220 HistoryBackend::~HistoryBackend() {
220 DCHECK(!scheduled_commit_) << "Deleting without cleanup"; 221 DCHECK(!scheduled_commit_) << "Deleting without cleanup";
221 base::STLDeleteContainerPointers(queued_history_db_tasks_.begin(),
222 queued_history_db_tasks_.end());
223 queued_history_db_tasks_.clear(); 222 queued_history_db_tasks_.clear();
224 223
225 // Release stashed embedder object before cleaning up the databases. 224 // Release stashed embedder object before cleaning up the databases.
226 supports_user_data_helper_.reset(); 225 supports_user_data_helper_.reset();
227 226
228 // First close the databases before optionally running the "destroy" task. 227 // First close the databases before optionally running the "destroy" task.
229 CloseAllDatabases(); 228 CloseAllDatabases();
230 229
231 if (!backend_destroy_task_.is_null()) { 230 if (!backend_destroy_task_.is_null()) {
232 // Notify an interested party (typically a unit test) that we're done. 231 // Notify an interested party (typically a unit test) that we're done.
(...skipping 2031 matching lines...) Expand 10 before | Expand all | Expand 10 after
2264 void HistoryBackend::CancelScheduledCommit() { 2263 void HistoryBackend::CancelScheduledCommit() {
2265 if (scheduled_commit_) { 2264 if (scheduled_commit_) {
2266 scheduled_commit_->Cancel(); 2265 scheduled_commit_->Cancel();
2267 scheduled_commit_ = nullptr; 2266 scheduled_commit_ = nullptr;
2268 } 2267 }
2269 } 2268 }
2270 2269
2271 void HistoryBackend::ProcessDBTaskImpl() { 2270 void HistoryBackend::ProcessDBTaskImpl() {
2272 if (!db_) { 2271 if (!db_) {
2273 // db went away, release all the refs. 2272 // db went away, release all the refs.
2274 base::STLDeleteContainerPointers(queued_history_db_tasks_.begin(),
2275 queued_history_db_tasks_.end());
2276 queued_history_db_tasks_.clear(); 2273 queued_history_db_tasks_.clear();
2277 return; 2274 return;
2278 } 2275 }
2279 2276
2280 // Remove any canceled tasks. 2277 // Remove any canceled tasks.
2281 while (!queued_history_db_tasks_.empty()) { 2278 while (!queued_history_db_tasks_.empty()) {
2282 QueuedHistoryDBTask* task = queued_history_db_tasks_.front(); 2279 QueuedHistoryDBTask* task = queued_history_db_tasks_.front().get();
2283 if (!task->is_canceled()) 2280 if (!task->is_canceled())
2284 break; 2281 break;
2285 2282
2286 delete task;
2287 queued_history_db_tasks_.pop_front(); 2283 queued_history_db_tasks_.pop_front();
2288 } 2284 }
2289 if (queued_history_db_tasks_.empty()) 2285 if (queued_history_db_tasks_.empty())
2290 return; 2286 return;
2291 2287
2292 // Run the first task. 2288 // Run the first task.
2293 std::unique_ptr<QueuedHistoryDBTask> task(queued_history_db_tasks_.front()); 2289 std::unique_ptr<QueuedHistoryDBTask> task =
2290 std::move(queued_history_db_tasks_.front());
2294 queued_history_db_tasks_.pop_front(); 2291 queued_history_db_tasks_.pop_front();
2295 if (task->Run(this, db_.get())) { 2292 if (task->Run(this, db_.get())) {
2296 // The task is done, notify the callback. 2293 // The task is done, notify the callback.
2297 task->DoneRun(); 2294 task->DoneRun();
2298 } else { 2295 } else {
2299 // The task wants to run some more. Schedule it at the end of the current 2296 // The task wants to run some more. Schedule it at the end of the current
2300 // tasks, and process it after an invoke later. 2297 // tasks, and process it after an invoke later.
2301 queued_history_db_tasks_.push_back(task.release()); 2298 queued_history_db_tasks_.push_back(std::move(task));
2302 task_runner_->PostTask( 2299 task_runner_->PostTask(
2303 FROM_HERE, base::Bind(&HistoryBackend::ProcessDBTaskImpl, this)); 2300 FROM_HERE, base::Bind(&HistoryBackend::ProcessDBTaskImpl, this));
2304 } 2301 }
2305 } 2302 }
2306 2303
2307 //////////////////////////////////////////////////////////////////////////////// 2304 ////////////////////////////////////////////////////////////////////////////////
2308 // 2305 //
2309 // Generic operations 2306 // Generic operations
2310 // 2307 //
2311 //////////////////////////////////////////////////////////////////////////////// 2308 ////////////////////////////////////////////////////////////////////////////////
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
2486 base::SupportsUserData::Data* data) { 2483 base::SupportsUserData::Data* data) {
2487 DCHECK(supports_user_data_helper_); 2484 DCHECK(supports_user_data_helper_);
2488 supports_user_data_helper_->SetUserData(key, data); 2485 supports_user_data_helper_->SetUserData(key, data);
2489 } 2486 }
2490 2487
2491 void HistoryBackend::ProcessDBTask( 2488 void HistoryBackend::ProcessDBTask(
2492 std::unique_ptr<HistoryDBTask> task, 2489 std::unique_ptr<HistoryDBTask> task,
2493 scoped_refptr<base::SingleThreadTaskRunner> origin_loop, 2490 scoped_refptr<base::SingleThreadTaskRunner> origin_loop,
2494 const base::CancelableTaskTracker::IsCanceledCallback& is_canceled) { 2491 const base::CancelableTaskTracker::IsCanceledCallback& is_canceled) {
2495 bool scheduled = !queued_history_db_tasks_.empty(); 2492 bool scheduled = !queued_history_db_tasks_.empty();
2496 queued_history_db_tasks_.push_back( 2493 queued_history_db_tasks_.push_back(base::MakeUnique<QueuedHistoryDBTask>(
2497 new QueuedHistoryDBTask(std::move(task), origin_loop, is_canceled)); 2494 std::move(task), origin_loop, is_canceled));
2498 if (!scheduled) 2495 if (!scheduled)
2499 ProcessDBTaskImpl(); 2496 ProcessDBTaskImpl();
2500 } 2497 }
2501 2498
2502 void HistoryBackend::NotifyFaviconsChanged(const std::set<GURL>& page_urls, 2499 void HistoryBackend::NotifyFaviconsChanged(const std::set<GURL>& page_urls,
2503 const GURL& icon_url) { 2500 const GURL& icon_url) {
2504 if (delegate_) 2501 if (delegate_)
2505 delegate_->NotifyFaviconsChanged(page_urls, icon_url); 2502 delegate_->NotifyFaviconsChanged(page_urls, icon_url);
2506 } 2503 }
2507 2504
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
2657 // transaction is currently open. 2654 // transaction is currently open.
2658 db_->CommitTransaction(); 2655 db_->CommitTransaction();
2659 db_->Vacuum(); 2656 db_->Vacuum();
2660 db_->BeginTransaction(); 2657 db_->BeginTransaction();
2661 db_->GetStartDate(&first_recorded_time_); 2658 db_->GetStartDate(&first_recorded_time_);
2662 2659
2663 return true; 2660 return true;
2664 } 2661 }
2665 2662
2666 } // namespace history 2663 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698