Index: webkit/blob/scoped_file.cc |
diff --git a/webkit/blob/scoped_file.cc b/webkit/blob/scoped_file.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8f12c0d9b8c8e48347ee4dd78271e79a76719c87 |
--- /dev/null |
+++ b/webkit/blob/scoped_file.cc |
@@ -0,0 +1,71 @@ |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "webkit/blob/scoped_file.h" |
+ |
+#include "base/bind.h" |
+#include "base/callback.h" |
+#include "base/files/file_util_proxy.h" |
+#include "base/location.h" |
+#include "base/message_loop/message_loop_proxy.h" |
+#include "base/task_runner.h" |
+ |
+namespace webkit_blob { |
+ |
+ScopedFile::ScopedFile() { |
+} |
+ |
+ScopedFile::ScopedFile( |
+ const base::FilePath& path, ScopeOutPolicy policy, |
+ base::TaskRunner* file_task_runner) |
+ : path_(path), |
+ scope_out_policy_(policy), |
+ file_task_runner_(file_task_runner) { |
tzik
2013/04/24 02:37:42
DCHECK(path.empty() || policy != DELETE_ON_SCOPE_O
kinuko
2013/04/24 04:15:17
Done.
kinuko
2013/04/24 04:32:18
Fixed to:
DCHECK(path.empty() || policy != DELETE
|
+} |
+ |
+ScopedFile::ScopedFile(RValue other) { |
+ Swap(*other.object); |
+} |
+ |
+ScopedFile::~ScopedFile() { |
+ ScopeOut(); |
+} |
+ |
+void ScopedFile::AddScopeOutCallback( |
+ const ScopeOutCallback& callback, |
+ base::TaskRunner* callback_runner) { |
+ if (!callback_runner) |
+ callback_runner = base::MessageLoopProxy::current(); |
+ scope_out_callbacks_.push_back(std::make_pair(callback, callback_runner)); |
+} |
+ |
+base::FilePath ScopedFile::Release() { |
+ base::FilePath path = path_; |
+ path_.clear(); |
+ return path; |
+} |
+ |
+void ScopedFile::Swap(ScopedFile& other) { |
tzik
2013/04/24 02:37:42
This looks not swap function.
Can we rename this t
kinuko
2013/04/24 04:15:17
Renamed to MoveFrom.
|
+ path_ = other.Release(); |
+ scope_out_policy_ = other.scope_out_policy_; |
+ scope_out_callbacks_.swap(other.scope_out_callbacks_); |
+ file_task_runner_ = other.file_task_runner_; |
+} |
+ |
+void ScopedFile::ScopeOut() { |
+ if (path_.empty()) |
+ return; |
+ |
+ for (ScopeOutCallbackList::iterator iter = scope_out_callbacks_.begin(); |
+ iter != scope_out_callbacks_.end(); ++iter) { |
+ iter->second->PostTask(FROM_HERE, base::Bind(iter->first, path_)); |
+ } |
+ |
+ if (scope_out_policy_ == DELETE_ON_SCOPE_OUT) { |
+ base::FileUtilProxy::Delete(file_task_runner_, path_, false /* recursive */, |
+ base::FileUtilProxy::StatusCallback()); |
+ } |
+} |
+ |
+} // namespace webkit_blob |