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

Side by Side Diff: components/browsing_data/conditional_cache_deletion_helper.cc

Issue 2008323002: Add tests for the cache deletion in BrowsingDataRemover (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix memory leak Created 4 years, 6 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/browsing_data/conditional_cache_deletion_helper.h" 5 #include "components/browsing_data/conditional_cache_deletion_helper.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "content/public/browser/browser_thread.h" 8 #include "content/public/browser/browser_thread.h"
9 9
10 namespace { 10 namespace {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 55
56 IterateOverEntries(net::OK); 56 IterateOverEntries(net::OK);
57 return net::ERR_IO_PENDING; 57 return net::ERR_IO_PENDING;
58 } 58 }
59 59
60 ConditionalCacheDeletionHelper::~ConditionalCacheDeletionHelper() { 60 ConditionalCacheDeletionHelper::~ConditionalCacheDeletionHelper() {
61 } 61 }
62 62
63 void ConditionalCacheDeletionHelper::IterateOverEntries(int error) { 63 void ConditionalCacheDeletionHelper::IterateOverEntries(int error) {
64 while (error != net::ERR_IO_PENDING) { 64 while (error != net::ERR_IO_PENDING) {
65 // Delete the entry obtained in the previous iteration. The iterator is 65 // If the entry obtained in the previous iteration matches the condition,
66 // already one step forward, so it won't be invalidated. 66 // mark it for deletion. The iterator is already one step forward, so it
67 if (previous_entry_ && condition_.Run(previous_entry_)) 67 // won't be invalidated. Always close the previous entry so it does not
68 // leak.
69 if (previous_entry_) {
70 if (condition_.Run(previous_entry_))
68 previous_entry_->Doom(); 71 previous_entry_->Doom();
72 previous_entry_->Close();
73 }
69 74
70 if (error == net::ERR_FAILED) { 75 if (error == net::ERR_FAILED) {
71 // The iteration finished successfuly or we can no longer iterate 76 // The iteration finished successfuly or we can no longer iterate
72 // (e.g. the cache was destroyed). We cannot distinguish between the two, 77 // (e.g. the cache was destroyed). We cannot distinguish between the two,
73 // but we know that there is nothing more that we can do, so we return OK. 78 // but we know that there is nothing more that we can do, so we return OK.
74 base::MessageLoop::current()->task_runner()->PostTask( 79 base::MessageLoop::current()->task_runner()->PostTask(
75 FROM_HERE, base::Bind(completion_callback_, net::OK)); 80 FROM_HERE, base::Bind(completion_callback_, net::OK));
76 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); 81 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);
77 return; 82 return;
78 } 83 }
79 84
80 previous_entry_ = current_entry_; 85 previous_entry_ = current_entry_;
81 error = iterator_->OpenNextEntry( 86 error = iterator_->OpenNextEntry(
82 &current_entry_, 87 &current_entry_,
83 base::Bind(&ConditionalCacheDeletionHelper::IterateOverEntries, 88 base::Bind(&ConditionalCacheDeletionHelper::IterateOverEntries,
84 base::Unretained(this))); 89 base::Unretained(this)));
85 } 90 }
86 } 91 }
87 92
88 } // namespace browsing_data 93 } // namespace browsing_data
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698