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

Side by Side Diff: webkit/tools/test_shell/simple_file_system.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/tools/test_shell/simple_file_system.h" 5 #include "webkit/tools/test_shell/simple_file_system.h"
6 6
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/message_loop_proxy.h" 8 #include "base/message_loop_proxy.h"
9 #include "base/scoped_callback_factory.h" 9 #include "base/scoped_callback_factory.h"
10 #include "base/time.h" 10 #include "base/time.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 : public FileSystemCallbackDispatcher { 47 : public FileSystemCallbackDispatcher {
48 public: 48 public:
49 SimpleFileSystemCallbackDispatcher( 49 SimpleFileSystemCallbackDispatcher(
50 const WeakPtr<SimpleFileSystem>& file_system, 50 const WeakPtr<SimpleFileSystem>& file_system,
51 WebFileSystemCallbacks* callbacks) 51 WebFileSystemCallbacks* callbacks)
52 : file_system_(file_system), 52 : file_system_(file_system),
53 callbacks_(callbacks) { 53 callbacks_(callbacks) {
54 } 54 }
55 55
56 ~SimpleFileSystemCallbackDispatcher() { 56 ~SimpleFileSystemCallbackDispatcher() {
57 DCHECK(!operation_.get());
58 }
59
60 void set_operation(SandboxedFileSystemOperation* operation) {
61 operation_.reset(operation);
62 } 57 }
63 58
64 virtual void DidSucceed() { 59 virtual void DidSucceed() {
65 if (file_system_) 60 DCHECK(file_system_);
66 callbacks_->didSucceed(); 61 callbacks_->didSucceed();
67 RemoveOperation();
68 } 62 }
69 63
70 virtual void DidReadMetadata(const base::PlatformFileInfo& info) { 64 virtual void DidReadMetadata(const base::PlatformFileInfo& info) {
71 DCHECK(file_system_); 65 DCHECK(file_system_);
72 WebFileInfo web_file_info; 66 WebFileInfo web_file_info;
73 web_file_info.length = info.size; 67 web_file_info.length = info.size;
74 web_file_info.modificationTime = info.last_modified.ToDoubleT(); 68 web_file_info.modificationTime = info.last_modified.ToDoubleT();
75 web_file_info.type = info.is_directory ? 69 web_file_info.type = info.is_directory ?
76 WebFileInfo::TypeDirectory : WebFileInfo::TypeFile; 70 WebFileInfo::TypeDirectory : WebFileInfo::TypeFile;
77 callbacks_->didReadMetadata(web_file_info); 71 callbacks_->didReadMetadata(web_file_info);
78 RemoveOperation();
79 } 72 }
80 73
81 virtual void DidReadDirectory( 74 virtual void DidReadDirectory(
82 const std::vector<base::FileUtilProxy::Entry>& entries, 75 const std::vector<base::FileUtilProxy::Entry>& entries,
83 bool has_more) { 76 bool has_more) {
84 DCHECK(file_system_); 77 DCHECK(file_system_);
85 std::vector<WebFileSystemEntry> web_entries_vector; 78 std::vector<WebFileSystemEntry> web_entries_vector;
86 for (std::vector<base::FileUtilProxy::Entry>::const_iterator it = 79 for (std::vector<base::FileUtilProxy::Entry>::const_iterator it =
87 entries.begin(); it != entries.end(); ++it) { 80 entries.begin(); it != entries.end(); ++it) {
88 WebFileSystemEntry entry; 81 WebFileSystemEntry entry;
89 entry.name = webkit_glue::FilePathStringToWebString(it->name); 82 entry.name = webkit_glue::FilePathStringToWebString(it->name);
90 entry.isDirectory = it->is_directory; 83 entry.isDirectory = it->is_directory;
91 web_entries_vector.push_back(entry); 84 web_entries_vector.push_back(entry);
92 } 85 }
93 WebVector<WebKit::WebFileSystemEntry> web_entries = 86 WebVector<WebKit::WebFileSystemEntry> web_entries =
94 web_entries_vector; 87 web_entries_vector;
95 callbacks_->didReadDirectory(web_entries, has_more); 88 callbacks_->didReadDirectory(web_entries, has_more);
96 RemoveOperation();
97 } 89 }
98 90
99 virtual void DidOpenFileSystem( 91 virtual void DidOpenFileSystem(
100 const std::string& name, const FilePath& path) { 92 const std::string& name, const FilePath& path) {
101 DCHECK(file_system_); 93 DCHECK(file_system_);
102 if (path.empty()) 94 if (path.empty())
103 callbacks_->didFail(WebKit::WebFileErrorSecurity); 95 callbacks_->didFail(WebKit::WebFileErrorSecurity);
104 else 96 else
105 callbacks_->didOpenFileSystem( 97 callbacks_->didOpenFileSystem(
106 UTF8ToUTF16(name), webkit_glue::FilePathToWebString(path)); 98 UTF8ToUTF16(name), webkit_glue::FilePathToWebString(path));
107 RemoveOperation();
108 } 99 }
109 100
110 virtual void DidFail(base::PlatformFileError error_code) { 101 virtual void DidFail(base::PlatformFileError error_code) {
111 DCHECK(file_system_); 102 DCHECK(file_system_);
112 callbacks_->didFail( 103 callbacks_->didFail(
113 webkit_glue::PlatformFileErrorToWebFileError(error_code)); 104 webkit_glue::PlatformFileErrorToWebFileError(error_code));
114 RemoveOperation();
115 } 105 }
116 106
117 virtual void DidWrite(int64, bool) { 107 virtual void DidWrite(int64, bool) {
118 NOTREACHED(); 108 NOTREACHED();
119 } 109 }
120 110
121 private: 111 private:
122 void RemoveOperation() {
123 // We need to make sure operation_ is null when we delete the operation
124 // (which in turn deletes this dispatcher instance).
125 scoped_ptr<SandboxedFileSystemOperation> operation;
126 operation.swap(operation_);
127 operation.reset();
128 }
129
130 WeakPtr<SimpleFileSystem> file_system_; 112 WeakPtr<SimpleFileSystem> file_system_;
131 WebFileSystemCallbacks* callbacks_; 113 WebFileSystemCallbacks* callbacks_;
132 scoped_ptr<SandboxedFileSystemOperation> operation_;
133 }; 114 };
134 115
135 } // namespace 116 } // namespace
136 117
137 SimpleFileSystem::SimpleFileSystem() { 118 SimpleFileSystem::SimpleFileSystem() {
138 if (file_system_dir_.CreateUniqueTempDir()) { 119 if (file_system_dir_.CreateUniqueTempDir()) {
139 sandboxed_context_.reset(new SandboxedFileSystemContext( 120 sandboxed_context_.reset(new SandboxedFileSystemContext(
140 base::MessageLoopProxy::CreateForCurrentThread(), 121 base::MessageLoopProxy::CreateForCurrentThread(),
141 file_system_dir_.path(), 122 file_system_dir_.path(),
142 false /* incognito */, 123 false /* incognito */,
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 return new SimpleFileWriter(path, client); 236 return new SimpleFileWriter(path, client);
256 } 237 }
257 238
258 SandboxedFileSystemOperation* SimpleFileSystem::GetNewOperation( 239 SandboxedFileSystemOperation* SimpleFileSystem::GetNewOperation(
259 WebFileSystemCallbacks* callbacks) { 240 WebFileSystemCallbacks* callbacks) {
260 SimpleFileSystemCallbackDispatcher* dispatcher = 241 SimpleFileSystemCallbackDispatcher* dispatcher =
261 new SimpleFileSystemCallbackDispatcher(AsWeakPtr(), callbacks); 242 new SimpleFileSystemCallbackDispatcher(AsWeakPtr(), callbacks);
262 SandboxedFileSystemOperation* operation = new SandboxedFileSystemOperation( 243 SandboxedFileSystemOperation* operation = new SandboxedFileSystemOperation(
263 dispatcher, base::MessageLoopProxy::CreateForCurrentThread(), 244 dispatcher, base::MessageLoopProxy::CreateForCurrentThread(),
264 sandboxed_context_.get()); 245 sandboxed_context_.get());
265 dispatcher->set_operation(operation);
266 return operation; 246 return operation;
267 } 247 }
OLDNEW
« no previous file with comments | « webkit/fileapi/sandboxed_file_system_operation.cc ('k') | webkit/tools/test_shell/simple_file_writer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698