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

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

Issue 2314833002: Remove some uses of stl_util's STLDeleteContainerPointers. (Closed)
Patch Set: cleanup 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 "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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 scheduled_kill_db_(false), 213 scheduled_kill_db_(false),
213 expirer_(this, backend_client.get(), task_runner), 214 expirer_(this, backend_client.get(), task_runner),
214 recent_redirects_(kMaxRedirectCount), 215 recent_redirects_(kMaxRedirectCount),
215 backend_destroy_message_loop_(nullptr), 216 backend_destroy_message_loop_(nullptr),
216 segment_queried_(false), 217 segment_queried_(false),
217 backend_client_(std::move(backend_client)), 218 backend_client_(std::move(backend_client)),
218 task_runner_(task_runner) {} 219 task_runner_(task_runner) {}
219 220
220 HistoryBackend::~HistoryBackend() { 221 HistoryBackend::~HistoryBackend() {
221 DCHECK(!scheduled_commit_) << "Deleting without cleanup"; 222 DCHECK(!scheduled_commit_) << "Deleting without cleanup";
222 base::STLDeleteContainerPointers(queued_history_db_tasks_.begin(),
223 queued_history_db_tasks_.end());
224 queued_history_db_tasks_.clear(); 223 queued_history_db_tasks_.clear();
225 224
226 // Release stashed embedder object before cleaning up the databases. 225 // Release stashed embedder object before cleaning up the databases.
227 supports_user_data_helper_.reset(); 226 supports_user_data_helper_.reset();
228 227
229 // First close the databases before optionally running the "destroy" task. 228 // First close the databases before optionally running the "destroy" task.
230 CloseAllDatabases(); 229 CloseAllDatabases();
231 230
232 if (!backend_destroy_task_.is_null()) { 231 if (!backend_destroy_task_.is_null()) {
233 // Notify an interested party (typically a unit test) that we're done. 232 // Notify an interested party (typically a unit test) that we're done.
(...skipping 2021 matching lines...) Expand 10 before | Expand all | Expand 10 after
2255 void HistoryBackend::CancelScheduledCommit() { 2254 void HistoryBackend::CancelScheduledCommit() {
2256 if (scheduled_commit_) { 2255 if (scheduled_commit_) {
2257 scheduled_commit_->Cancel(); 2256 scheduled_commit_->Cancel();
2258 scheduled_commit_ = nullptr; 2257 scheduled_commit_ = nullptr;
2259 } 2258 }
2260 } 2259 }
2261 2260
2262 void HistoryBackend::ProcessDBTaskImpl() { 2261 void HistoryBackend::ProcessDBTaskImpl() {
2263 if (!db_) { 2262 if (!db_) {
2264 // db went away, release all the refs. 2263 // db went away, release all the refs.
2265 base::STLDeleteContainerPointers(queued_history_db_tasks_.begin(),
2266 queued_history_db_tasks_.end());
2267 queued_history_db_tasks_.clear(); 2264 queued_history_db_tasks_.clear();
2268 return; 2265 return;
2269 } 2266 }
2270 2267
2271 // Remove any canceled tasks. 2268 // Remove any canceled tasks.
2272 while (!queued_history_db_tasks_.empty()) { 2269 while (!queued_history_db_tasks_.empty()) {
2273 QueuedHistoryDBTask* task = queued_history_db_tasks_.front(); 2270 QueuedHistoryDBTask* task = queued_history_db_tasks_.front().get();
2274 if (!task->is_canceled()) 2271 if (!task->is_canceled())
2275 break; 2272 break;
2276 2273
2277 delete task;
2278 queued_history_db_tasks_.pop_front(); 2274 queued_history_db_tasks_.pop_front();
2279 } 2275 }
2280 if (queued_history_db_tasks_.empty()) 2276 if (queued_history_db_tasks_.empty())
2281 return; 2277 return;
2282 2278
2283 // Run the first task. 2279 // Run the first task.
2284 std::unique_ptr<QueuedHistoryDBTask> task(queued_history_db_tasks_.front()); 2280 std::unique_ptr<QueuedHistoryDBTask> task =
2281 std::move(queued_history_db_tasks_.front());
2285 queued_history_db_tasks_.pop_front(); 2282 queued_history_db_tasks_.pop_front();
2286 if (task->Run(this, db_.get())) { 2283 if (task->Run(this, db_.get())) {
2287 // The task is done, notify the callback. 2284 // The task is done, notify the callback.
2288 task->DoneRun(); 2285 task->DoneRun();
2289 } else { 2286 } else {
2290 // The task wants to run some more. Schedule it at the end of the current 2287 // The task wants to run some more. Schedule it at the end of the current
2291 // tasks, and process it after an invoke later. 2288 // tasks, and process it after an invoke later.
2292 queued_history_db_tasks_.push_back(task.release()); 2289 queued_history_db_tasks_.push_back(std::move(task));
2293 task_runner_->PostTask( 2290 task_runner_->PostTask(
2294 FROM_HERE, base::Bind(&HistoryBackend::ProcessDBTaskImpl, this)); 2291 FROM_HERE, base::Bind(&HistoryBackend::ProcessDBTaskImpl, this));
2295 } 2292 }
2296 } 2293 }
2297 2294
2298 //////////////////////////////////////////////////////////////////////////////// 2295 ////////////////////////////////////////////////////////////////////////////////
2299 // 2296 //
2300 // Generic operations 2297 // Generic operations
2301 // 2298 //
2302 //////////////////////////////////////////////////////////////////////////////// 2299 ////////////////////////////////////////////////////////////////////////////////
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
2477 base::SupportsUserData::Data* data) { 2474 base::SupportsUserData::Data* data) {
2478 DCHECK(supports_user_data_helper_); 2475 DCHECK(supports_user_data_helper_);
2479 supports_user_data_helper_->SetUserData(key, data); 2476 supports_user_data_helper_->SetUserData(key, data);
2480 } 2477 }
2481 2478
2482 void HistoryBackend::ProcessDBTask( 2479 void HistoryBackend::ProcessDBTask(
2483 std::unique_ptr<HistoryDBTask> task, 2480 std::unique_ptr<HistoryDBTask> task,
2484 scoped_refptr<base::SingleThreadTaskRunner> origin_loop, 2481 scoped_refptr<base::SingleThreadTaskRunner> origin_loop,
2485 const base::CancelableTaskTracker::IsCanceledCallback& is_canceled) { 2482 const base::CancelableTaskTracker::IsCanceledCallback& is_canceled) {
2486 bool scheduled = !queued_history_db_tasks_.empty(); 2483 bool scheduled = !queued_history_db_tasks_.empty();
2487 queued_history_db_tasks_.push_back( 2484 queued_history_db_tasks_.push_back(base::MakeUnique<QueuedHistoryDBTask>(
2488 new QueuedHistoryDBTask(std::move(task), origin_loop, is_canceled)); 2485 std::move(task), origin_loop, is_canceled));
2489 if (!scheduled) 2486 if (!scheduled)
2490 ProcessDBTaskImpl(); 2487 ProcessDBTaskImpl();
2491 } 2488 }
2492 2489
2493 void HistoryBackend::NotifyFaviconsChanged(const std::set<GURL>& page_urls, 2490 void HistoryBackend::NotifyFaviconsChanged(const std::set<GURL>& page_urls,
2494 const GURL& icon_url) { 2491 const GURL& icon_url) {
2495 if (delegate_) 2492 if (delegate_)
2496 delegate_->NotifyFaviconsChanged(page_urls, icon_url); 2493 delegate_->NotifyFaviconsChanged(page_urls, icon_url);
2497 } 2494 }
2498 2495
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
2648 // transaction is currently open. 2645 // transaction is currently open.
2649 db_->CommitTransaction(); 2646 db_->CommitTransaction();
2650 db_->Vacuum(); 2647 db_->Vacuum();
2651 db_->BeginTransaction(); 2648 db_->BeginTransaction();
2652 db_->GetStartDate(&first_recorded_time_); 2649 db_->GetStartDate(&first_recorded_time_);
2653 2650
2654 return true; 2651 return true;
2655 } 2652 }
2656 2653
2657 } // namespace history 2654 } // namespace history
OLDNEW
« no previous file with comments | « components/history/core/browser/history_backend.h ('k') | content/browser/appcache/appcache_update_job_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698