| 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 namespace fileapi { | 22 using fileapi::FileSystemContext; |
| 23 using fileapi::FileSystemOperationContext; |
| 24 using fileapi::FileSystemURL; |
| 25 |
| 26 namespace content { |
| 23 namespace { | 27 namespace { |
| 24 | 28 |
| 25 class LoggingRecursiveOperation : public RecursiveOperationDelegate { | 29 class LoggingRecursiveOperation : public fileapi::RecursiveOperationDelegate { |
| 26 public: | 30 public: |
| 27 struct LogEntry { | 31 struct LogEntry { |
| 28 enum Type { | 32 enum Type { |
| 29 PROCESS_FILE, | 33 PROCESS_FILE, |
| 30 PROCESS_DIRECTORY, | 34 PROCESS_DIRECTORY, |
| 31 POST_PROCESS_DIRECTORY | 35 POST_PROCESS_DIRECTORY |
| 32 }; | 36 }; |
| 33 Type type; | 37 Type type; |
| 34 FileSystemURL url; | 38 FileSystemURL url; |
| 35 }; | 39 }; |
| 36 | 40 |
| 37 LoggingRecursiveOperation(FileSystemContext* file_system_context, | 41 LoggingRecursiveOperation(FileSystemContext* file_system_context, |
| 38 const FileSystemURL& root, | 42 const FileSystemURL& root, |
| 39 const StatusCallback& callback) | 43 const StatusCallback& callback) |
| 40 : RecursiveOperationDelegate(file_system_context), | 44 : fileapi::RecursiveOperationDelegate(file_system_context), |
| 41 root_(root), | 45 root_(root), |
| 42 callback_(callback), | 46 callback_(callback), |
| 43 weak_factory_(this) { | 47 weak_factory_(this) { |
| 44 } | 48 } |
| 45 virtual ~LoggingRecursiveOperation() {} | 49 virtual ~LoggingRecursiveOperation() {} |
| 46 | 50 |
| 47 const std::vector<LogEntry>& log_entries() const { return log_entries_; } | 51 const std::vector<LogEntry>& log_entries() const { return log_entries_; } |
| 48 | 52 |
| 49 // RecursiveOperationDelegate overrides. | 53 // RecursiveOperationDelegate overrides. |
| 50 virtual void Run() OVERRIDE { | 54 virtual void Run() OVERRIDE { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 }; | 110 }; |
| 107 | 111 |
| 108 void ReportStatus(base::PlatformFileError* out_error, | 112 void ReportStatus(base::PlatformFileError* out_error, |
| 109 base::PlatformFileError error) { | 113 base::PlatformFileError error) { |
| 110 DCHECK(out_error); | 114 DCHECK(out_error); |
| 111 *out_error = error; | 115 *out_error = error; |
| 112 } | 116 } |
| 113 | 117 |
| 114 // To test the Cancel() during operation, calls Cancel() of |operation| | 118 // To test the Cancel() during operation, calls Cancel() of |operation| |
| 115 // after |counter| times message posting. | 119 // after |counter| times message posting. |
| 116 void CallCancelLater(RecursiveOperationDelegate* operation, int counter) { | 120 void CallCancelLater(fileapi::RecursiveOperationDelegate* operation, |
| 121 int counter) { |
| 117 if (counter > 0) { | 122 if (counter > 0) { |
| 118 base::MessageLoopProxy::current()->PostTask( | 123 base::MessageLoopProxy::current()->PostTask( |
| 119 FROM_HERE, | 124 FROM_HERE, |
| 120 base::Bind(&CallCancelLater, base::Unretained(operation), counter - 1)); | 125 base::Bind(&CallCancelLater, base::Unretained(operation), counter - 1)); |
| 121 return; | 126 return; |
| 122 } | 127 } |
| 123 | 128 |
| 124 operation->Cancel(); | 129 operation->Cancel(); |
| 125 } | 130 } |
| 126 | 131 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 138 } | 143 } |
| 139 | 144 |
| 140 scoped_ptr<FileSystemOperationContext> NewContext() { | 145 scoped_ptr<FileSystemOperationContext> NewContext() { |
| 141 FileSystemOperationContext* context = | 146 FileSystemOperationContext* context = |
| 142 sandbox_file_system_.NewOperationContext(); | 147 sandbox_file_system_.NewOperationContext(); |
| 143 // Grant enough quota for all test cases. | 148 // Grant enough quota for all test cases. |
| 144 context->set_allowed_bytes_growth(1000000); | 149 context->set_allowed_bytes_growth(1000000); |
| 145 return make_scoped_ptr(context); | 150 return make_scoped_ptr(context); |
| 146 } | 151 } |
| 147 | 152 |
| 148 FileSystemFileUtil* file_util() { | 153 fileapi::FileSystemFileUtil* file_util() { |
| 149 return sandbox_file_system_.file_util(); | 154 return sandbox_file_system_.file_util(); |
| 150 } | 155 } |
| 151 | 156 |
| 152 FileSystemURL URLForPath(const std::string& path) const { | 157 FileSystemURL URLForPath(const std::string& path) const { |
| 153 return sandbox_file_system_.CreateURLFromUTF8(path); | 158 return sandbox_file_system_.CreateURLFromUTF8(path); |
| 154 } | 159 } |
| 155 | 160 |
| 156 FileSystemURL CreateFile(const std::string& path) { | 161 FileSystemURL CreateFile(const std::string& path) { |
| 157 FileSystemURL url = URLForPath(path); | 162 FileSystemURL url = URLForPath(path); |
| 158 bool created = false; | 163 bool created = false; |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 context->file_system_context(), src_root, | 275 context->file_system_context(), src_root, |
| 271 base::Bind(&ReportStatus, &error))); | 276 base::Bind(&ReportStatus, &error))); |
| 272 operation->RunRecursively(); | 277 operation->RunRecursively(); |
| 273 | 278 |
| 274 // Invoke Cancel(), after 5 times message posting. | 279 // Invoke Cancel(), after 5 times message posting. |
| 275 CallCancelLater(operation.get(), 5); | 280 CallCancelLater(operation.get(), 5); |
| 276 base::RunLoop().RunUntilIdle(); | 281 base::RunLoop().RunUntilIdle(); |
| 277 ASSERT_EQ(base::PLATFORM_FILE_ERROR_ABORT, error); | 282 ASSERT_EQ(base::PLATFORM_FILE_ERROR_ABORT, error); |
| 278 } | 283 } |
| 279 | 284 |
| 280 } // namespace fileapi | 285 } // namespace content |
| OLD | NEW |