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

Side by Side Diff: content/browser/plugin_private_storage_helper.cc

Issue 2622403002: Clear data for origin if no files found (Closed)
Patch Set: Created 3 years, 11 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
« no previous file with comments | « no previous file | content/browser/storage_partition_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "content/browser/plugin_private_storage_helper.h" 5 #include "content/browser/plugin_private_storage_helper.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 const std::string plugin_name_; 105 const std::string plugin_name_;
106 const base::Time begin_; 106 const base::Time begin_;
107 const base::Time end_; 107 const base::Time end_;
108 const base::Callback<void(bool, const GURL&)> callback_; 108 const base::Callback<void(bool, const GURL&)> callback_;
109 std::string fsid_; 109 std::string fsid_;
110 int task_count_ = 0; 110 int task_count_ = 0;
111 111
112 // Keep track if the data for this origin needs to be deleted due to 112 // Keep track if the data for this origin needs to be deleted due to
113 // any file found that has last modified time between |begin_| and |end_|. 113 // any file found that has last modified time between |begin_| and |end_|.
114 bool delete_this_origin_data_ = false; 114 bool delete_this_origin_data_ = false;
115
116 // Keep track if any files exist for this origin.
117 bool files_found_ = false;
115 }; 118 };
116 119
117 void PluginPrivateDataByOriginChecker::CheckFilesOnIOThread() { 120 void PluginPrivateDataByOriginChecker::CheckFilesOnIOThread() {
118 DCHECK_CURRENTLY_ON(BrowserThread::IO); 121 DCHECK_CURRENTLY_ON(BrowserThread::IO);
119 DCHECK(storage::ValidateIsolatedFileSystemId(fsid_)); 122 DCHECK(storage::ValidateIsolatedFileSystemId(fsid_));
120 123
121 IncrementTaskCount(); 124 IncrementTaskCount();
122 filesystem_context_->OpenPluginPrivateFileSystem( 125 filesystem_context_->OpenPluginPrivateFileSystem(
123 origin_, storage::kFileSystemTypePluginPrivate, fsid_, plugin_name_, 126 origin_, storage::kFileSystemTypePluginPrivate, fsid_, plugin_name_,
124 storage::OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT, 127 storage::OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 << ", #files: " << file_list.size(); 164 << ", #files: " << file_list.size();
162 165
163 // Quit if there is an error. 166 // Quit if there is an error.
164 if (result != base::File::FILE_OK) { 167 if (result != base::File::FILE_OK) {
165 DLOG(ERROR) << "Unable to read directory for " << origin_ << ":" 168 DLOG(ERROR) << "Unable to read directory for " << origin_ << ":"
166 << plugin_name_; 169 << plugin_name_;
167 DecrementTaskCount(); 170 DecrementTaskCount();
168 return; 171 return;
169 } 172 }
170 173
174 // If there are files found, keep track of it.
175 if (!file_list.empty())
176 files_found_ = true;
177
171 // No error, process the files returned. No need to do this if we have 178 // No error, process the files returned. No need to do this if we have
172 // already decided to delete all the data for this origin. 179 // already decided to delete all the data for this origin.
173 if (!delete_this_origin_data_) { 180 if (!delete_this_origin_data_) {
174 storage::AsyncFileUtil* file_util = filesystem_context_->GetAsyncFileUtil( 181 storage::AsyncFileUtil* file_util = filesystem_context_->GetAsyncFileUtil(
175 storage::kFileSystemTypePluginPrivate); 182 storage::kFileSystemTypePluginPrivate);
176 for (const auto& file : file_list) { 183 for (const auto& file : file_list) {
177 DVLOG(3) << __func__ << " file: " << file.name; 184 DVLOG(3) << __func__ << " file: " << file.name;
178 DCHECK(!file.is_directory); // Nested directories not implemented. 185 DCHECK(!file.is_directory); // Nested directories not implemented.
179 186
180 std::unique_ptr<storage::FileSystemOperationContext> operation_context = 187 std::unique_ptr<storage::FileSystemOperationContext> operation_context =
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 ++task_count_; 228 ++task_count_;
222 } 229 }
223 230
224 void PluginPrivateDataByOriginChecker::DecrementTaskCount() { 231 void PluginPrivateDataByOriginChecker::DecrementTaskCount() {
225 DCHECK_CURRENTLY_ON(BrowserThread::IO); 232 DCHECK_CURRENTLY_ON(BrowserThread::IO);
226 DCHECK_GT(task_count_, 0); 233 DCHECK_GT(task_count_, 0);
227 --task_count_; 234 --task_count_;
228 if (task_count_) 235 if (task_count_)
229 return; 236 return;
230 237
238 // If no files exist for this origin, then we can safely delete it.
239 if (!files_found_)
240 delete_this_origin_data_ = true;
241
231 // If there are no more tasks in progress, then run |callback_| on the 242 // If there are no more tasks in progress, then run |callback_| on the
232 // proper thread. 243 // proper thread.
233 filesystem_context_->default_file_task_runner()->PostTask( 244 filesystem_context_->default_file_task_runner()->PostTask(
234 FROM_HERE, base::Bind(callback_, delete_this_origin_data_, origin_)); 245 FROM_HERE, base::Bind(callback_, delete_this_origin_data_, origin_));
235 delete this; 246 delete this;
236 } 247 }
237 248
238 // Helper for deleting the plugin private data. 249 // Helper for deleting the plugin private data.
239 // All of the operations in this class are done on the file task runner. 250 // All of the operations in this class are done on the file task runner.
240 class PluginPrivateDataDeletionHelper { 251 class PluginPrivateDataDeletionHelper {
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 origins.insert(storage_origin); 418 origins.insert(storage_origin);
408 } 419 }
409 420
410 PluginPrivateDataDeletionHelper* helper = new PluginPrivateDataDeletionHelper( 421 PluginPrivateDataDeletionHelper* helper = new PluginPrivateDataDeletionHelper(
411 std::move(filesystem_context), begin, end, callback); 422 std::move(filesystem_context), begin, end, callback);
412 helper->CheckOriginsOnFileTaskRunner(origins); 423 helper->CheckOriginsOnFileTaskRunner(origins);
413 // |helper| will delete itself when all origins have been checked. 424 // |helper| will delete itself when all origins have been checked.
414 } 425 }
415 426
416 } // namespace content 427 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/storage_partition_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698