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

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

Issue 4821005: Make FileSystemOperation's lifetime more explicit. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: simple_file_writer fix Created 10 years 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/sandboxed_file_system_operation.h" 5 #include "webkit/fileapi/sandboxed_file_system_operation.h"
6 6
7 #include "net/url_request/url_request_context.h" 7 #include "net/url_request/url_request_context.h"
8 #include "webkit/fileapi/file_system_callback_dispatcher.h" 8 #include "webkit/fileapi/file_system_callback_dispatcher.h"
9 #include "webkit/fileapi/file_system_path_manager.h" 9 #include "webkit/fileapi/file_system_path_manager.h"
10 #include "webkit/fileapi/file_system_quota_manager.h" 10 #include "webkit/fileapi/file_system_quota_manager.h"
(...skipping 20 matching lines...) Expand all
31 #endif 31 #endif
32 32
33 file_system_context_->path_manager()->GetFileSystemRootPath( 33 file_system_context_->path_manager()->GetFileSystemRootPath(
34 origin_url, type, create, 34 origin_url, type, create,
35 callback_factory_.NewCallback( 35 callback_factory_.NewCallback(
36 &SandboxedFileSystemOperation::DidGetRootPath)); 36 &SandboxedFileSystemOperation::DidGetRootPath));
37 } 37 }
38 38
39 void SandboxedFileSystemOperation::CreateFile( 39 void SandboxedFileSystemOperation::CreateFile(
40 const FilePath& path, bool exclusive) { 40 const FilePath& path, bool exclusive) {
41 if (!VerifyFileSystemPathForWrite(path, true /* create */, 0)) 41 if (!VerifyFileSystemPathForWrite(path, true /* create */, 0)) {
42 delete this;
42 return; 43 return;
44 }
43 FileSystemOperation::CreateFile(path, exclusive); 45 FileSystemOperation::CreateFile(path, exclusive);
44 } 46 }
45 47
46 void SandboxedFileSystemOperation::CreateDirectory( 48 void SandboxedFileSystemOperation::CreateDirectory(
47 const FilePath& path, bool exclusive, bool recursive) { 49 const FilePath& path, bool exclusive, bool recursive) {
48 if (!VerifyFileSystemPathForWrite(path, true /* create */, 0)) 50 if (!VerifyFileSystemPathForWrite(path, true /* create */, 0)) {
51 delete this;
49 return; 52 return;
53 }
50 FileSystemOperation::CreateDirectory(path, exclusive, recursive); 54 FileSystemOperation::CreateDirectory(path, exclusive, recursive);
51 } 55 }
52 56
53 void SandboxedFileSystemOperation::Copy( 57 void SandboxedFileSystemOperation::Copy(
54 const FilePath& src_path, const FilePath& dest_path) { 58 const FilePath& src_path, const FilePath& dest_path) {
55 if (!VerifyFileSystemPathForRead(src_path) || 59 if (!VerifyFileSystemPathForRead(src_path) ||
56 !VerifyFileSystemPathForWrite(dest_path, true /* create */, 60 !VerifyFileSystemPathForWrite(dest_path, true /* create */,
57 FileSystemQuotaManager::kUnknownSize)) 61 FileSystemQuotaManager::kUnknownSize)) {
62 delete this;
58 return; 63 return;
64 }
59 FileSystemOperation::Copy(src_path, dest_path); 65 FileSystemOperation::Copy(src_path, dest_path);
60 } 66 }
61 67
62 void SandboxedFileSystemOperation::Move( 68 void SandboxedFileSystemOperation::Move(
63 const FilePath& src_path, const FilePath& dest_path) { 69 const FilePath& src_path, const FilePath& dest_path) {
64 if (!VerifyFileSystemPathForRead(src_path) || 70 if (!VerifyFileSystemPathForRead(src_path) ||
65 !VerifyFileSystemPathForWrite(dest_path, true /* create */, 71 !VerifyFileSystemPathForWrite(dest_path, true /* create */,
66 FileSystemQuotaManager::kUnknownSize)) 72 FileSystemQuotaManager::kUnknownSize)) {
73 delete this;
67 return; 74 return;
75 }
68 FileSystemOperation::Move(src_path, dest_path); 76 FileSystemOperation::Move(src_path, dest_path);
69 } 77 }
70 78
71 void SandboxedFileSystemOperation::DirectoryExists(const FilePath& path) { 79 void SandboxedFileSystemOperation::DirectoryExists(const FilePath& path) {
72 if (!VerifyFileSystemPathForRead(path)) 80 if (!VerifyFileSystemPathForRead(path)) {
81 delete this;
73 return; 82 return;
83 }
74 FileSystemOperation::DirectoryExists(path); 84 FileSystemOperation::DirectoryExists(path);
75 } 85 }
76 86
77 void SandboxedFileSystemOperation::FileExists(const FilePath& path) { 87 void SandboxedFileSystemOperation::FileExists(const FilePath& path) {
78 if (!VerifyFileSystemPathForRead(path)) 88 if (!VerifyFileSystemPathForRead(path)) {
89 delete this;
79 return; 90 return;
91 }
80 FileSystemOperation::FileExists(path); 92 FileSystemOperation::FileExists(path);
81 } 93 }
82 94
83 void SandboxedFileSystemOperation::GetMetadata(const FilePath& path) { 95 void SandboxedFileSystemOperation::GetMetadata(const FilePath& path) {
84 if (!VerifyFileSystemPathForRead(path)) 96 if (!VerifyFileSystemPathForRead(path)) {
97 delete this;
85 return; 98 return;
99 }
86 FileSystemOperation::GetMetadata(path); 100 FileSystemOperation::GetMetadata(path);
87 } 101 }
88 102
89 void SandboxedFileSystemOperation::ReadDirectory(const FilePath& path) { 103 void SandboxedFileSystemOperation::ReadDirectory(const FilePath& path) {
90 if (!VerifyFileSystemPathForRead(path)) 104 if (!VerifyFileSystemPathForRead(path)) {
105 delete this;
91 return; 106 return;
107 }
92 FileSystemOperation::ReadDirectory(path); 108 FileSystemOperation::ReadDirectory(path);
93 } 109 }
94 110
95 void SandboxedFileSystemOperation::Remove( 111 void SandboxedFileSystemOperation::Remove(
96 const FilePath& path, bool recursive) { 112 const FilePath& path, bool recursive) {
97 if (!VerifyFileSystemPathForWrite(path, false /* create */, 0)) 113 if (!VerifyFileSystemPathForWrite(path, false /* create */, 0)) {
114 delete this;
98 return; 115 return;
116 }
99 FileSystemOperation::Remove(path, recursive); 117 FileSystemOperation::Remove(path, recursive);
100 } 118 }
101 119
102 void SandboxedFileSystemOperation::Write( 120 void SandboxedFileSystemOperation::Write(
103 scoped_refptr<URLRequestContext> url_request_context, 121 scoped_refptr<URLRequestContext> url_request_context,
104 const FilePath& path, const GURL& blob_url, int64 offset) { 122 const FilePath& path, const GURL& blob_url, int64 offset) {
105 if (!VerifyFileSystemPathForWrite(path, true /* create */, 123 if (!VerifyFileSystemPathForWrite(path, true /* create */,
106 FileSystemQuotaManager::kUnknownSize)) 124 FileSystemQuotaManager::kUnknownSize)) {
125 delete this;
107 return; 126 return;
127 }
108 FileSystemOperation::Write(url_request_context, path, blob_url, offset); 128 FileSystemOperation::Write(url_request_context, path, blob_url, offset);
109 } 129 }
110 130
111 void SandboxedFileSystemOperation::Truncate( 131 void SandboxedFileSystemOperation::Truncate(
112 const FilePath& path, int64 length) { 132 const FilePath& path, int64 length) {
113 if (!VerifyFileSystemPathForWrite(path, false /* create */, 0)) 133 if (!VerifyFileSystemPathForWrite(path, false /* create */, 0)) {
134 delete this;
114 return; 135 return;
136 }
115 FileSystemOperation::Truncate(path, length); 137 FileSystemOperation::Truncate(path, length);
116 } 138 }
117 139
118 void SandboxedFileSystemOperation::TouchFile( 140 void SandboxedFileSystemOperation::TouchFile(
119 const FilePath& path, 141 const FilePath& path,
120 const base::Time& last_access_time, 142 const base::Time& last_access_time,
121 const base::Time& last_modified_time) { 143 const base::Time& last_modified_time) {
122 if (!VerifyFileSystemPathForWrite(path, true /* create */, 0)) 144 if (!VerifyFileSystemPathForWrite(path, true /* create */, 0)) {
145 delete this;
123 return; 146 return;
147 }
124 FileSystemOperation::TouchFile(path, last_access_time, last_modified_time); 148 FileSystemOperation::TouchFile(path, last_access_time, last_modified_time);
125 } 149 }
126 150
127 void SandboxedFileSystemOperation::DidGetRootPath( 151 void SandboxedFileSystemOperation::DidGetRootPath(
128 bool success, const FilePath& path, const std::string& name) { 152 bool success, const FilePath& path, const std::string& name) {
129 DCHECK(success || path.empty()); 153 DCHECK(success || path.empty());
130 dispatcher()->DidOpenFileSystem(name, path); 154 dispatcher()->DidOpenFileSystem(name, path);
155 delete this;
131 } 156 }
132 157
133 bool SandboxedFileSystemOperation::VerifyFileSystemPathForRead( 158 bool SandboxedFileSystemOperation::VerifyFileSystemPathForRead(
134 const FilePath& path) { 159 const FilePath& path) {
135 // We may want do more checks, but for now it just checks if the given 160 // We may want do more checks, but for now it just checks if the given
136 // |path| is under the valid FileSystem root path for this host context. 161 // |path| is under the valid FileSystem root path for this host context.
137 if (!file_system_context_->path_manager()->CrackFileSystemPath( 162 if (!file_system_context_->path_manager()->CrackFileSystemPath(
138 path, NULL, NULL, NULL)) { 163 path, NULL, NULL, NULL)) {
139 dispatcher()->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); 164 dispatcher()->DidFail(base::PLATFORM_FILE_ERROR_SECURITY);
140 return false; 165 return false;
(...skipping 25 matching lines...) Expand all
166 // need to resolve what amount of size it's going to write. 191 // need to resolve what amount of size it's going to write.
167 if (!file_system_context_->quota_manager()->CheckOriginQuota( 192 if (!file_system_context_->quota_manager()->CheckOriginQuota(
168 origin_url, growth)) { 193 origin_url, growth)) {
169 dispatcher()->DidFail(base::PLATFORM_FILE_ERROR_NO_SPACE); 194 dispatcher()->DidFail(base::PLATFORM_FILE_ERROR_NO_SPACE);
170 return false; 195 return false;
171 } 196 }
172 return true; 197 return true;
173 } 198 }
174 199
175 } // namespace fileapi 200 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/sandboxed_file_system_operation.h ('k') | webkit/tools/test_shell/simple_file_system.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698