Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(270)

Side by Side Diff: webkit/fileapi/quota_file_util.cc

Issue 7470037: [Refactor] to rename and re-layer the file_util stack layers. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Rebased. Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/quota_file_util.h" 5 #include "webkit/fileapi/quota_file_util.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "webkit/fileapi/file_system_context.h" 9 #include "webkit/fileapi/file_system_context.h"
10 #include "webkit/fileapi/file_system_operation_context.h" 10 #include "webkit/fileapi/file_system_operation_context.h"
11 #include "webkit/fileapi/file_system_path_manager.h" 11 #include "webkit/fileapi/file_system_path_manager.h"
12 #include "webkit/fileapi/file_system_quota_util.h" 12 #include "webkit/fileapi/file_system_quota_util.h"
13 #include "webkit/fileapi/native_file_util.h"
13 #include "webkit/quota/quota_manager.h" 14 #include "webkit/quota/quota_manager.h"
14 15
15 using quota::QuotaManagerProxy; 16 using quota::QuotaManagerProxy;
16 17
17 namespace fileapi { 18 namespace fileapi {
18 19
19 const int64 QuotaFileUtil::kNoLimit = kint64max; 20 const int64 QuotaFileUtil::kNoLimit = kint64max;
20 21
21 namespace { 22 namespace {
22 23
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 FileSystemQuotaUtil* quota_util_; 85 FileSystemQuotaUtil* quota_util_;
85 QuotaManagerProxy* quota_manager_proxy_; 86 QuotaManagerProxy* quota_manager_proxy_;
86 const GURL& origin_url_; 87 const GURL& origin_url_;
87 FileSystemType type_; 88 FileSystemType type_;
88 DISALLOW_COPY_AND_ASSIGN(ScopedOriginUpdateHelper); 89 DISALLOW_COPY_AND_ASSIGN(ScopedOriginUpdateHelper);
89 }; 90 };
90 91
91 } // namespace (anonymous) 92 } // namespace (anonymous)
92 93
93 QuotaFileUtil::QuotaFileUtil(FileSystemFileUtil* underlying_file_util) 94 QuotaFileUtil::QuotaFileUtil(FileSystemFileUtil* underlying_file_util)
94 : underlying_file_util_(underlying_file_util) { 95 : FileSystemFileUtil(underlying_file_util) {
95 } 96 }
96 97
97 QuotaFileUtil::~QuotaFileUtil() { 98 QuotaFileUtil::~QuotaFileUtil() {
98 } 99 }
99 100
100 // static 101 // static
101 QuotaFileUtil* QuotaFileUtil::CreateDefault() { 102 QuotaFileUtil* QuotaFileUtil::CreateDefault() {
102 return new QuotaFileUtil(new FileSystemFileUtil()); 103 return new QuotaFileUtil(new NativeFileUtil());
104 }
105
106 base::PlatformFileError QuotaFileUtil::Truncate(
107 FileSystemOperationContext* fs_context,
108 const FilePath& path,
109 int64 length) {
110 int64 allowed_bytes_growth = fs_context->allowed_bytes_growth();
111 ScopedOriginUpdateHelper helper(
112 fs_context,
113 fs_context->src_origin_url(),
114 fs_context->src_type());
115
116 int64 growth = 0;
117 base::PlatformFileInfo file_info;
118 if (!file_util::GetFileInfo(path, &file_info))
119 return base::PLATFORM_FILE_ERROR_FAILED;
120
121 growth = length - file_info.size;
122 if (allowed_bytes_growth != kNoLimit &&
123 growth > 0 && growth > allowed_bytes_growth)
124 return base::PLATFORM_FILE_ERROR_NO_SPACE;
125
126 base::PlatformFileError error = underlying_file_util()->Truncate(
127 fs_context, path, length);
128
129 if (error == base::PLATFORM_FILE_OK)
130 helper.NotifyUpdate(growth);
131
132 return error;
103 } 133 }
104 134
105 base::PlatformFileError QuotaFileUtil::CopyOrMoveFile( 135 base::PlatformFileError QuotaFileUtil::CopyOrMoveFile(
106 FileSystemOperationContext* fs_context, 136 FileSystemOperationContext* fs_context,
107 const FilePath& src_file_path, 137 const FilePath& src_file_path,
108 const FilePath& dest_file_path, 138 const FilePath& dest_file_path,
109 bool copy) { 139 bool copy) {
110 DCHECK(fs_context); 140 DCHECK(fs_context);
111 141
112 // TODO(kinuko): For cross-filesystem move case we need 2 helpers, one for 142 // TODO(kinuko): For cross-filesystem move case we need 2 helpers, one for
(...skipping 12 matching lines...) Expand all
125 // The third argument (growth) is not used for now. 155 // The third argument (growth) is not used for now.
126 if (!CanCopy(src_file_path, dest_file_path, allowed_bytes_growth, &growth)) 156 if (!CanCopy(src_file_path, dest_file_path, allowed_bytes_growth, &growth))
127 return base::PLATFORM_FILE_ERROR_NO_SPACE; 157 return base::PLATFORM_FILE_ERROR_NO_SPACE;
128 } else { 158 } else {
129 base::PlatformFileInfo dest_file_info; 159 base::PlatformFileInfo dest_file_info;
130 if (!file_util::GetFileInfo(dest_file_path, &dest_file_info)) 160 if (!file_util::GetFileInfo(dest_file_path, &dest_file_info))
131 dest_file_info.size = 0; 161 dest_file_info.size = 0;
132 growth = -dest_file_info.size; 162 growth = -dest_file_info.size;
133 } 163 }
134 164
135 base::PlatformFileError error = underlying_file_util_->CopyOrMoveFile( 165 base::PlatformFileError error = underlying_file_util()->CopyOrMoveFile(
136 fs_context, src_file_path, dest_file_path, copy); 166 fs_context, src_file_path, dest_file_path, copy);
137 167
138 if (error == base::PLATFORM_FILE_OK) { 168 if (error == base::PLATFORM_FILE_OK) {
139 // TODO(kinuko): For cross-filesystem move case, call this with -growth 169 // TODO(kinuko): For cross-filesystem move case, call this with -growth
140 // for source and growth for dest. 170 // for source and growth for dest.
141 helper.NotifyUpdate(growth); 171 helper.NotifyUpdate(growth);
142 } 172 }
143 173
144 return error; 174 return error;
145 } 175 }
146 176
147 base::PlatformFileError QuotaFileUtil::DeleteFile( 177 base::PlatformFileError QuotaFileUtil::DeleteFile(
148 FileSystemOperationContext* fs_context, 178 FileSystemOperationContext* fs_context,
149 const FilePath& file_path) { 179 const FilePath& file_path) {
150 DCHECK(fs_context); 180 DCHECK(fs_context);
151 ScopedOriginUpdateHelper helper( 181 ScopedOriginUpdateHelper helper(
152 fs_context, 182 fs_context,
153 fs_context->src_origin_url(), 183 fs_context->src_origin_url(),
154 fs_context->src_type()); 184 fs_context->src_type());
155 185
156 int64 growth = 0; 186 int64 growth = 0;
157 base::PlatformFileInfo file_info; 187 base::PlatformFileInfo file_info;
158 if (!file_util::GetFileInfo(file_path, &file_info)) 188 if (!file_util::GetFileInfo(file_path, &file_info))
159 file_info.size = 0; 189 file_info.size = 0;
160 growth = -file_info.size; 190 growth = -file_info.size;
161 191
162 base::PlatformFileError error = underlying_file_util_->DeleteFile( 192 base::PlatformFileError error = underlying_file_util()->DeleteFile(
163 fs_context, file_path); 193 fs_context, file_path);
164 194
165 if (error == base::PLATFORM_FILE_OK) 195 if (error == base::PLATFORM_FILE_OK)
166 helper.NotifyUpdate(growth); 196 helper.NotifyUpdate(growth);
167 197
168 return error; 198 return error;
169 } 199 }
170 200
171 base::PlatformFileError QuotaFileUtil::Truncate(
172 FileSystemOperationContext* fs_context,
173 const FilePath& path,
174 int64 length) {
175 int64 allowed_bytes_growth = fs_context->allowed_bytes_growth();
176 ScopedOriginUpdateHelper helper(
177 fs_context,
178 fs_context->src_origin_url(),
179 fs_context->src_type());
180
181 int64 growth = 0;
182 base::PlatformFileInfo file_info;
183 if (!file_util::GetFileInfo(path, &file_info))
184 return base::PLATFORM_FILE_ERROR_FAILED;
185
186 growth = length - file_info.size;
187 if (allowed_bytes_growth != kNoLimit &&
188 growth > 0 && growth > allowed_bytes_growth)
189 return base::PLATFORM_FILE_ERROR_NO_SPACE;
190
191 base::PlatformFileError error = underlying_file_util_->Truncate(
192 fs_context, path, length);
193
194 if (error == base::PLATFORM_FILE_OK)
195 helper.NotifyUpdate(growth);
196
197 return error;
198 }
199
200 } // namespace fileapi 201 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698