OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/fileapi/file_system_test_helper.h" | 5 #include "webkit/fileapi/file_system_test_helper.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
10 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
| 11 #include "webkit/fileapi/file_system_callback_dispatcher.h" |
11 #include "webkit/fileapi/file_system_context.h" | 12 #include "webkit/fileapi/file_system_context.h" |
12 #include "webkit/fileapi/file_system_operation.h" | 13 #include "webkit/fileapi/file_system_operation.h" |
13 #include "webkit/fileapi/file_system_operation_context.h" | 14 #include "webkit/fileapi/file_system_operation_context.h" |
14 #include "webkit/fileapi/file_system_usage_cache.h" | 15 #include "webkit/fileapi/file_system_usage_cache.h" |
15 #include "webkit/fileapi/file_system_util.h" | 16 #include "webkit/fileapi/file_system_util.h" |
16 #include "webkit/fileapi/mock_file_system_options.h" | 17 #include "webkit/fileapi/mock_file_system_options.h" |
17 #include "webkit/fileapi/sandbox_mount_point_provider.h" | 18 #include "webkit/fileapi/sandbox_mount_point_provider.h" |
18 #include "webkit/quota/mock_special_storage_policy.h" | 19 #include "webkit/quota/mock_special_storage_policy.h" |
19 | 20 |
20 namespace fileapi { | 21 namespace fileapi { |
(...skipping 22 matching lines...) Expand all Loading... |
43 DCHECK(file_system_context->sandbox_provider()); | 44 DCHECK(file_system_context->sandbox_provider()); |
44 | 45 |
45 file_util_ = file_util; | 46 file_util_ = file_util; |
46 file_system_context_ = file_system_context; | 47 file_system_context_ = file_system_context; |
47 if (!file_util_) | 48 if (!file_util_) |
48 file_util_ = file_system_context->sandbox_provider()->GetFileUtil(); | 49 file_util_ = file_system_context->sandbox_provider()->GetFileUtil(); |
49 DCHECK(file_util_); | 50 DCHECK(file_util_); |
50 | 51 |
51 // Prepare the origin's root directory. | 52 // Prepare the origin's root directory. |
52 file_system_context_->GetMountPointProvider(type_)-> | 53 file_system_context_->GetMountPointProvider(type_)-> |
53 ValidateFileSystemRootAndGetPathOnFileThread( | 54 GetFileSystemRootPathOnFileThread( |
54 origin_, type_, FilePath(), true /* create */); | 55 origin_, type_, FilePath(), true /* create */); |
55 | 56 |
56 // Initialize the usage cache file. | 57 // Initialize the usage cache file. |
57 FilePath usage_cache_path = file_system_context_-> | 58 FilePath usage_cache_path = file_system_context_-> |
58 sandbox_provider()->GetUsageCachePathForOriginAndType(origin_, type_); | 59 sandbox_provider()->GetUsageCachePathForOriginAndType(origin_, type_); |
59 FileSystemUsageCache::UpdateUsage(usage_cache_path, 0); | 60 FileSystemUsageCache::UpdateUsage(usage_cache_path, 0); |
60 } | 61 } |
61 | 62 |
62 void FileSystemTestOriginHelper::SetUp( | 63 void FileSystemTestOriginHelper::SetUp( |
63 const FilePath& base_dir, | 64 const FilePath& base_dir, |
(...skipping 10 matching lines...) Expand all Loading... |
74 base::MessageLoopProxy::current(), | 75 base::MessageLoopProxy::current(), |
75 special_storage_policy, | 76 special_storage_policy, |
76 quota_manager_proxy, | 77 quota_manager_proxy, |
77 base_dir, | 78 base_dir, |
78 CreateAllowFileAccessOptions()); | 79 CreateAllowFileAccessOptions()); |
79 | 80 |
80 DCHECK(file_system_context_->sandbox_provider()); | 81 DCHECK(file_system_context_->sandbox_provider()); |
81 | 82 |
82 // Prepare the origin's root directory. | 83 // Prepare the origin's root directory. |
83 file_system_context_->GetMountPointProvider(type_)-> | 84 file_system_context_->GetMountPointProvider(type_)-> |
84 ValidateFileSystemRootAndGetPathOnFileThread( | 85 GetFileSystemRootPathOnFileThread( |
85 origin_, type_, FilePath(), true /* create */); | 86 origin_, type_, FilePath(), true /* create */); |
86 | 87 |
87 // Initialize the usage cache file. This code assumes that we're either using | 88 // Initialize the usage cache file. This code assumes that we're either using |
88 // OFSFU or we've mocked it out in the sandbox provider. | 89 // OFSFU or we've mocked it out in the sandbox provider. |
89 FilePath usage_cache_path = file_system_context_-> | 90 FilePath usage_cache_path = file_system_context_-> |
90 sandbox_provider()->GetUsageCachePathForOriginAndType(origin_, type_); | 91 sandbox_provider()->GetUsageCachePathForOriginAndType(origin_, type_); |
91 FileSystemUsageCache::UpdateUsage(usage_cache_path, 0); | 92 FileSystemUsageCache::UpdateUsage(usage_cache_path, 0); |
92 } | 93 } |
93 | 94 |
94 void FileSystemTestOriginHelper::TearDown() { | 95 void FileSystemTestOriginHelper::TearDown() { |
95 file_system_context_ = NULL; | 96 file_system_context_ = NULL; |
96 MessageLoop::current()->RunAllPending(); | 97 MessageLoop::current()->RunAllPending(); |
97 } | 98 } |
98 | 99 |
99 FilePath FileSystemTestOriginHelper::GetOriginRootPath() const { | 100 FilePath FileSystemTestOriginHelper::GetOriginRootPath() const { |
100 return file_system_context_->GetMountPointProvider(type_)-> | 101 return file_system_context_->GetMountPointProvider(type_)-> |
101 ValidateFileSystemRootAndGetPathOnFileThread( | 102 GetFileSystemRootPathOnFileThread( |
102 origin_, type_, FilePath(), false); | 103 origin_, type_, FilePath(), false); |
103 } | 104 } |
104 | 105 |
105 FilePath FileSystemTestOriginHelper::GetLocalPath(const FilePath& path) { | 106 FilePath FileSystemTestOriginHelper::GetLocalPath(const FilePath& path) { |
106 DCHECK(file_util_); | 107 DCHECK(file_util_); |
107 FilePath local_path; | 108 FilePath local_path; |
108 scoped_ptr<FileSystemOperationContext> context(NewOperationContext()); | 109 scoped_ptr<FileSystemOperationContext> context(NewOperationContext()); |
109 file_util_->GetLocalFilePath(context.get(), path, &local_path); | 110 file_util_->GetLocalFilePath(context.get(), path, &local_path); |
110 return local_path; | 111 return local_path; |
111 } | 112 } |
(...skipping 26 matching lines...) Expand all Loading... |
138 if (file_util::PathExists(GetUsageCachePath())) | 139 if (file_util::PathExists(GetUsageCachePath())) |
139 size -= FileSystemUsageCache::kUsageFileSize; | 140 size -= FileSystemUsageCache::kUsageFileSize; |
140 return size; | 141 return size; |
141 } | 142 } |
142 | 143 |
143 FileSystemOperation* FileSystemTestOriginHelper::NewOperation( | 144 FileSystemOperation* FileSystemTestOriginHelper::NewOperation( |
144 FileSystemCallbackDispatcher* callback_dispatcher) { | 145 FileSystemCallbackDispatcher* callback_dispatcher) { |
145 DCHECK(file_system_context_.get()); | 146 DCHECK(file_system_context_.get()); |
146 DCHECK(file_util_); | 147 DCHECK(file_util_); |
147 FileSystemOperation* operation = | 148 FileSystemOperation* operation = |
148 new FileSystemOperation(callback_dispatcher, | 149 new FileSystemOperation(scoped_ptr<FileSystemCallbackDispatcher>( |
| 150 callback_dispatcher), |
149 base::MessageLoopProxy::current(), | 151 base::MessageLoopProxy::current(), |
150 file_system_context_.get()); | 152 file_system_context_.get()); |
151 operation->set_override_file_util(file_util_); | 153 operation->set_override_file_util(file_util_); |
152 InitializeOperationContext(operation->file_system_operation_context()); | 154 InitializeOperationContext(operation->file_system_operation_context()); |
153 return operation; | 155 return operation; |
154 } | 156 } |
155 | 157 |
156 FileSystemOperationContext* FileSystemTestOriginHelper::NewOperationContext() { | 158 FileSystemOperationContext* FileSystemTestOriginHelper::NewOperationContext() { |
157 DCHECK(file_system_context_.get()); | 159 DCHECK(file_system_context_.get()); |
158 DCHECK(file_util_); | 160 DCHECK(file_util_); |
159 FileSystemOperationContext* context = | 161 FileSystemOperationContext* context = |
160 new FileSystemOperationContext(file_system_context_.get(), file_util_); | 162 new FileSystemOperationContext(file_system_context_.get(), file_util_); |
161 InitializeOperationContext(context); | 163 InitializeOperationContext(context); |
162 return context; | 164 return context; |
163 } | 165 } |
164 | 166 |
165 void FileSystemTestOriginHelper::InitializeOperationContext( | 167 void FileSystemTestOriginHelper::InitializeOperationContext( |
166 FileSystemOperationContext* context) { | 168 FileSystemOperationContext* context) { |
167 DCHECK(context); | 169 DCHECK(context); |
168 context->set_src_origin_url(origin_); | 170 context->set_src_origin_url(origin_); |
169 context->set_src_type(type_); | 171 context->set_src_type(type_); |
170 context->set_dest_origin_url(origin_); | 172 context->set_dest_origin_url(origin_); |
171 context->set_dest_type(type_); | 173 context->set_dest_type(type_); |
172 } | 174 } |
173 | 175 |
174 } // namespace fileapi | 176 } // namespace fileapi |
OLD | NEW |