| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "webkit/browser/fileapi/recursive_operation_delegate.h" | 5 #include "webkit/browser/fileapi/recursive_operation_delegate.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/files/scoped_temp_dir.h" | 12 #include "base/files/scoped_temp_dir.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/message_loop/message_loop_proxy.h" | 14 #include "base/message_loop/message_loop_proxy.h" |
| 15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 16 #include "content/public/test/sandbox_file_system_test_helper.h" | 16 #include "content/public/test/sandbox_file_system_test_helper.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "webkit/browser/fileapi/file_system_file_util.h" | 18 #include "webkit/browser/fileapi/file_system_file_util.h" |
| 19 #include "webkit/browser/fileapi/file_system_operation.h" | 19 #include "webkit/browser/fileapi/file_system_operation.h" |
| 20 #include "webkit/browser/fileapi/file_system_operation_runner.h" | 20 #include "webkit/browser/fileapi/file_system_operation_runner.h" |
| 21 | 21 |
| 22 using fileapi::FileSystemContext; | 22 using storage::FileSystemContext; |
| 23 using fileapi::FileSystemOperationContext; | 23 using storage::FileSystemOperationContext; |
| 24 using fileapi::FileSystemURL; | 24 using storage::FileSystemURL; |
| 25 | 25 |
| 26 namespace content { | 26 namespace content { |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 class LoggingRecursiveOperation : public fileapi::RecursiveOperationDelegate { | 29 class LoggingRecursiveOperation : public storage::RecursiveOperationDelegate { |
| 30 public: | 30 public: |
| 31 struct LogEntry { | 31 struct LogEntry { |
| 32 enum Type { | 32 enum Type { |
| 33 PROCESS_FILE, | 33 PROCESS_FILE, |
| 34 PROCESS_DIRECTORY, | 34 PROCESS_DIRECTORY, |
| 35 POST_PROCESS_DIRECTORY | 35 POST_PROCESS_DIRECTORY |
| 36 }; | 36 }; |
| 37 Type type; | 37 Type type; |
| 38 FileSystemURL url; | 38 FileSystemURL url; |
| 39 }; | 39 }; |
| 40 | 40 |
| 41 LoggingRecursiveOperation(FileSystemContext* file_system_context, | 41 LoggingRecursiveOperation(FileSystemContext* file_system_context, |
| 42 const FileSystemURL& root, | 42 const FileSystemURL& root, |
| 43 const StatusCallback& callback) | 43 const StatusCallback& callback) |
| 44 : fileapi::RecursiveOperationDelegate(file_system_context), | 44 : storage::RecursiveOperationDelegate(file_system_context), |
| 45 root_(root), | 45 root_(root), |
| 46 callback_(callback), | 46 callback_(callback), |
| 47 weak_factory_(this) { | 47 weak_factory_(this) {} |
| 48 } | |
| 49 virtual ~LoggingRecursiveOperation() {} | 48 virtual ~LoggingRecursiveOperation() {} |
| 50 | 49 |
| 51 const std::vector<LogEntry>& log_entries() const { return log_entries_; } | 50 const std::vector<LogEntry>& log_entries() const { return log_entries_; } |
| 52 | 51 |
| 53 // RecursiveOperationDelegate overrides. | 52 // RecursiveOperationDelegate overrides. |
| 54 virtual void Run() OVERRIDE { | 53 virtual void Run() OVERRIDE { |
| 55 NOTREACHED(); | 54 NOTREACHED(); |
| 56 } | 55 } |
| 57 | 56 |
| 58 virtual void RunRecursively() OVERRIDE { | 57 virtual void RunRecursively() OVERRIDE { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 }; | 109 }; |
| 111 | 110 |
| 112 void ReportStatus(base::File::Error* out_error, | 111 void ReportStatus(base::File::Error* out_error, |
| 113 base::File::Error error) { | 112 base::File::Error error) { |
| 114 DCHECK(out_error); | 113 DCHECK(out_error); |
| 115 *out_error = error; | 114 *out_error = error; |
| 116 } | 115 } |
| 117 | 116 |
| 118 // To test the Cancel() during operation, calls Cancel() of |operation| | 117 // To test the Cancel() during operation, calls Cancel() of |operation| |
| 119 // after |counter| times message posting. | 118 // after |counter| times message posting. |
| 120 void CallCancelLater(fileapi::RecursiveOperationDelegate* operation, | 119 void CallCancelLater(storage::RecursiveOperationDelegate* operation, |
| 121 int counter) { | 120 int counter) { |
| 122 if (counter > 0) { | 121 if (counter > 0) { |
| 123 base::MessageLoopProxy::current()->PostTask( | 122 base::MessageLoopProxy::current()->PostTask( |
| 124 FROM_HERE, | 123 FROM_HERE, |
| 125 base::Bind(&CallCancelLater, base::Unretained(operation), counter - 1)); | 124 base::Bind(&CallCancelLater, base::Unretained(operation), counter - 1)); |
| 126 return; | 125 return; |
| 127 } | 126 } |
| 128 | 127 |
| 129 operation->Cancel(); | 128 operation->Cancel(); |
| 130 } | 129 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 143 } | 142 } |
| 144 | 143 |
| 145 scoped_ptr<FileSystemOperationContext> NewContext() { | 144 scoped_ptr<FileSystemOperationContext> NewContext() { |
| 146 FileSystemOperationContext* context = | 145 FileSystemOperationContext* context = |
| 147 sandbox_file_system_.NewOperationContext(); | 146 sandbox_file_system_.NewOperationContext(); |
| 148 // Grant enough quota for all test cases. | 147 // Grant enough quota for all test cases. |
| 149 context->set_allowed_bytes_growth(1000000); | 148 context->set_allowed_bytes_growth(1000000); |
| 150 return make_scoped_ptr(context); | 149 return make_scoped_ptr(context); |
| 151 } | 150 } |
| 152 | 151 |
| 153 fileapi::FileSystemFileUtil* file_util() { | 152 storage::FileSystemFileUtil* file_util() { |
| 154 return sandbox_file_system_.file_util(); | 153 return sandbox_file_system_.file_util(); |
| 155 } | 154 } |
| 156 | 155 |
| 157 FileSystemURL URLForPath(const std::string& path) const { | 156 FileSystemURL URLForPath(const std::string& path) const { |
| 158 return sandbox_file_system_.CreateURLFromUTF8(path); | 157 return sandbox_file_system_.CreateURLFromUTF8(path); |
| 159 } | 158 } |
| 160 | 159 |
| 161 FileSystemURL CreateFile(const std::string& path) { | 160 FileSystemURL CreateFile(const std::string& path) { |
| 162 FileSystemURL url = URLForPath(path); | 161 FileSystemURL url = URLForPath(path); |
| 163 bool created = false; | 162 bool created = false; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 base::Bind(&ReportStatus, &error))); | 275 base::Bind(&ReportStatus, &error))); |
| 277 operation->RunRecursively(); | 276 operation->RunRecursively(); |
| 278 | 277 |
| 279 // Invoke Cancel(), after 5 times message posting. | 278 // Invoke Cancel(), after 5 times message posting. |
| 280 CallCancelLater(operation.get(), 5); | 279 CallCancelLater(operation.get(), 5); |
| 281 base::RunLoop().RunUntilIdle(); | 280 base::RunLoop().RunUntilIdle(); |
| 282 ASSERT_EQ(base::File::FILE_ERROR_ABORT, error); | 281 ASSERT_EQ(base::File::FILE_ERROR_ABORT, error); |
| 283 } | 282 } |
| 284 | 283 |
| 285 } // namespace content | 284 } // namespace content |
| OLD | NEW |