OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 NULL); | 105 NULL); |
106 | 106 |
107 DCHECK(file_system_context_->path_manager()); | 107 DCHECK(file_system_context_->path_manager()); |
108 DCHECK(file_system_context_->path_manager()->sandbox_provider()); | 108 DCHECK(file_system_context_->path_manager()->sandbox_provider()); |
109 | 109 |
110 // Prepare the origin's root directory. | 110 // Prepare the origin's root directory. |
111 file_system_context_->path_manager()-> | 111 file_system_context_->path_manager()-> |
112 ValidateFileSystemRootAndGetPathOnFileThread( | 112 ValidateFileSystemRootAndGetPathOnFileThread( |
113 origin_, type_, FilePath(), true /* create */); | 113 origin_, type_, FilePath(), true /* create */); |
114 | 114 |
115 // Initialize the usage cache file. | 115 // Initialize the usage cache file. This code assumes that we're either using |
| 116 // OFSFU or we've mocked it out in the sandbox provider. |
116 FilePath usage_cache_path = file_system_context_->path_manager() | 117 FilePath usage_cache_path = file_system_context_->path_manager() |
117 ->sandbox_provider()->GetUsageCachePathForOriginAndType(origin_, type_); | 118 ->sandbox_provider()->GetUsageCachePathForOriginAndType(origin_, type_); |
118 FileSystemUsageCache::UpdateUsage(usage_cache_path, 0); | 119 FileSystemUsageCache::UpdateUsage(usage_cache_path, 0); |
119 | |
120 // We expect the origin directory to be always empty, except for possibly | |
121 // the usage cache file. We record the initial usage file size here | |
122 // (it will be either 0 or kUsageFileSize) so that later we can compute | |
123 // how much the size of the origin directory has grown. | |
124 initial_usage_size_ = file_util::ComputeDirectorySize( | |
125 GetOriginRootPath()); | |
126 | |
127 FileSystemUsageCache::UpdateUsage(usage_cache_path, initial_usage_size_); | |
128 } | 120 } |
129 | 121 |
130 void FileSystemTestOriginHelper::TearDown() { | 122 void FileSystemTestOriginHelper::TearDown() { |
131 file_system_context_ = NULL; | 123 file_system_context_ = NULL; |
132 MessageLoop::current()->RunAllPending(); | 124 MessageLoop::current()->RunAllPending(); |
133 } | 125 } |
134 | 126 |
135 FilePath FileSystemTestOriginHelper::GetOriginRootPath() const { | 127 FilePath FileSystemTestOriginHelper::GetOriginRootPath() const { |
136 return file_system_context_->path_manager()-> | 128 return file_system_context_->path_manager()-> |
137 ValidateFileSystemRootAndGetPathOnFileThread( | 129 ValidateFileSystemRootAndGetPathOnFileThread( |
(...skipping 25 matching lines...) Expand all Loading... |
163 | 155 |
164 int64 FileSystemTestOriginHelper::GetCachedOriginUsage() const { | 156 int64 FileSystemTestOriginHelper::GetCachedOriginUsage() const { |
165 return FileSystemUsageCache::GetUsage(GetUsageCachePath()); | 157 return FileSystemUsageCache::GetUsage(GetUsageCachePath()); |
166 } | 158 } |
167 | 159 |
168 bool FileSystemTestOriginHelper::RevokeUsageCache() const { | 160 bool FileSystemTestOriginHelper::RevokeUsageCache() const { |
169 return file_util::Delete(GetUsageCachePath(), false); | 161 return file_util::Delete(GetUsageCachePath(), false); |
170 } | 162 } |
171 | 163 |
172 int64 FileSystemTestOriginHelper::ComputeCurrentOriginUsage() const { | 164 int64 FileSystemTestOriginHelper::ComputeCurrentOriginUsage() const { |
173 // Depending on the file_util GetOriginRootPath() may include usage | 165 int64 size = file_util::ComputeDirectorySize(GetOriginRootPath()); |
174 // cache file size or may not. Here we subtract the initial size to | 166 if (file_util::PathExists(GetUsageCachePath())) |
175 // make it work for multiple file_utils. | 167 size -= FileSystemUsageCache::kUsageFileSize; |
176 return file_util::ComputeDirectorySize(GetOriginRootPath()) - | 168 return size; |
177 initial_usage_size_; | |
178 } | 169 } |
179 | 170 |
180 FileSystemOperation* FileSystemTestOriginHelper::NewOperation( | 171 FileSystemOperation* FileSystemTestOriginHelper::NewOperation( |
181 FileSystemCallbackDispatcher* callback_dispatcher) { | 172 FileSystemCallbackDispatcher* callback_dispatcher) { |
182 DCHECK(file_system_context_.get()); | 173 DCHECK(file_system_context_.get()); |
183 DCHECK(file_util_); | 174 DCHECK(file_util_); |
184 FileSystemOperation* operation = | 175 FileSystemOperation* operation = |
185 new FileSystemOperation(callback_dispatcher, | 176 new FileSystemOperation(callback_dispatcher, |
186 base::MessageLoopProxy::current(), | 177 base::MessageLoopProxy::current(), |
187 file_system_context_.get(), | 178 file_system_context_.get(), |
(...skipping 14 matching lines...) Expand all Loading... |
202 void FileSystemTestOriginHelper::InitializeOperationContext( | 193 void FileSystemTestOriginHelper::InitializeOperationContext( |
203 FileSystemOperationContext* context) { | 194 FileSystemOperationContext* context) { |
204 DCHECK(context); | 195 DCHECK(context); |
205 context->set_src_origin_url(origin_); | 196 context->set_src_origin_url(origin_); |
206 context->set_src_type(type_); | 197 context->set_src_type(type_); |
207 context->set_dest_origin_url(origin_); | 198 context->set_dest_origin_url(origin_); |
208 context->set_dest_type(type_); | 199 context->set_dest_type(type_); |
209 } | 200 } |
210 | 201 |
211 } // namespace fileapi | 202 } // namespace fileapi |
OLD | NEW |