OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 32 matching lines...) Loading... | |
43 #include "modules/filesystem/FileWriterBaseCallback.h" | 43 #include "modules/filesystem/FileWriterBaseCallback.h" |
44 #include "modules/filesystem/FileWriterSync.h" | 44 #include "modules/filesystem/FileWriterSync.h" |
45 #include "platform/FileMetadata.h" | 45 #include "platform/FileMetadata.h" |
46 #include "public/platform/WebFileSystem.h" | 46 #include "public/platform/WebFileSystem.h" |
47 #include "public/platform/WebFileSystemCallbacks.h" | 47 #include "public/platform/WebFileSystemCallbacks.h" |
48 | 48 |
49 namespace WebCore { | 49 namespace WebCore { |
50 | 50 |
51 class FileWriterBase; | 51 class FileWriterBase; |
52 | 52 |
53 PassRefPtr<DOMFileSystemSync> DOMFileSystemSync::create(DOMFileSystemBase* fileS ystem) | 53 PassRefPtrWillBeRawPtr<DOMFileSystemSync> DOMFileSystemSync::create(DOMFileSyste mBase* fileSystem) |
54 { | 54 { |
55 return adoptRef(new DOMFileSystemSync(fileSystem->m_context, fileSystem->nam e(), fileSystem->type(), fileSystem->rootURL())); | 55 return adoptRefWillBeRefCountedGarbageCollected(new DOMFileSystemSync(fileSy stem->m_context, fileSystem->name(), fileSystem->type(), fileSystem->rootURL())) ; |
56 } | 56 } |
57 | 57 |
58 DOMFileSystemSync::DOMFileSystemSync(ExecutionContext* context, const String& na me, FileSystemType type, const KURL& rootURL) | 58 DOMFileSystemSync::DOMFileSystemSync(ExecutionContext* context, const String& na me, FileSystemType type, const KURL& rootURL) |
59 : DOMFileSystemBase(context, name, type, rootURL) | 59 : DOMFileSystemBase(context, name, type, rootURL) |
60 { | 60 { |
61 ScriptWrappable::init(this); | 61 ScriptWrappable::init(this); |
62 } | 62 } |
63 | 63 |
64 DOMFileSystemSync::~DOMFileSystemSync() | 64 DOMFileSystemSync::~DOMFileSystemSync() |
65 { | 65 { |
66 } | 66 } |
67 | 67 |
68 void DOMFileSystemSync::reportError(PassOwnPtr<ErrorCallback> errorCallback, Pas sRefPtrWillBeRawPtr<FileError> fileError) | 68 void DOMFileSystemSync::reportError(PassOwnPtr<ErrorCallback> errorCallback, Pas sRefPtrWillBeRawPtr<FileError> fileError) |
69 { | 69 { |
70 errorCallback->handleEvent(fileError.get()); | 70 errorCallback->handleEvent(fileError.get()); |
71 } | 71 } |
72 | 72 |
73 PassRefPtr<DirectoryEntrySync> DOMFileSystemSync::root() | 73 PassRefPtrWillBeRawPtr<DirectoryEntrySync> DOMFileSystemSync::root() |
74 { | 74 { |
75 return DirectoryEntrySync::create(this, DOMFilePath::root); | 75 return DirectoryEntrySync::create(this, DOMFilePath::root); |
76 } | 76 } |
77 | 77 |
78 | |
78 namespace { | 79 namespace { |
79 | 80 |
80 class CreateFileHelper FINAL : public AsyncFileSystemCallbacks { | 81 class CreateFileHelper FINAL : public AsyncFileSystemCallbacks { |
81 public: | 82 public: |
82 class CreateFileResult : public RefCounted<CreateFileResult> { | 83 class CreateFileResult : public RefCountedWillBeGarbageCollected<CreateFileR esult> { |
83 public: | 84 public: |
84 static PassRefPtr<CreateFileResult> create() | 85 static PassRefPtrWillBeRawPtr<CreateFileResult> create() |
85 { | 86 { |
86 return adoptRef(new CreateFileResult()); | 87 return adoptRefWillBeNoop(new CreateFileResult()); |
87 } | 88 } |
88 | 89 |
89 bool m_failed; | 90 bool m_failed; |
90 int m_code; | 91 int m_code; |
91 RefPtrWillBePersistent<File> m_file; | 92 RefPtrWillBeMember<File> m_file; |
93 | |
94 void trace(Visitor* visitor) | |
95 { | |
96 visitor->trace(m_file); | |
97 } | |
92 | 98 |
93 private: | 99 private: |
94 CreateFileResult() | 100 CreateFileResult() |
95 : m_failed(false) | 101 : m_failed(false) |
96 , m_code(0) | 102 , m_code(0) |
97 { | 103 { |
98 } | 104 } |
99 | 105 |
100 ~CreateFileResult() | 106 ~CreateFileResult() |
101 { | 107 { |
102 } | 108 } |
103 friend class WTF::RefCounted<CreateFileResult>; | 109 friend class RefCountedWillBeGarbageCollected<CreateFileResult>; |
haraken
2014/03/07 08:24:35
Not related to this CL, this class is mis-designed
| |
104 }; | 110 }; |
105 | 111 |
106 static PassOwnPtr<AsyncFileSystemCallbacks> create(PassRefPtr<CreateFileResu lt> result, const String& name, const KURL& url, FileSystemType type) | 112 static PassOwnPtr<AsyncFileSystemCallbacks> create(PassRefPtrWillBeRawPtr<Cr eateFileResult> result, const String& name, const KURL& url, FileSystemType type ) |
107 { | 113 { |
108 return adoptPtr(static_cast<AsyncFileSystemCallbacks*>(new CreateFileHel per(result, name, url, type))); | 114 return adoptPtr(static_cast<AsyncFileSystemCallbacks*>(new CreateFileHel per(result, name, url, type))); |
109 } | 115 } |
110 | 116 |
111 virtual void didFail(int code) OVERRIDE | 117 virtual void didFail(int code) OVERRIDE |
112 { | 118 { |
113 m_result->m_failed = true; | 119 m_result->m_failed = true; |
114 m_result->m_code = code; | 120 m_result->m_code = code; |
115 } | 121 } |
116 | 122 |
(...skipping 23 matching lines...) Loading... | |
140 m_result->m_file = File::createForFileSystemFile(m_url, metadata).ge t(); | 146 m_result->m_file = File::createForFileSystemFile(m_url, metadata).ge t(); |
141 } | 147 } |
142 } | 148 } |
143 | 149 |
144 virtual bool shouldBlockUntilCompletion() const OVERRIDE | 150 virtual bool shouldBlockUntilCompletion() const OVERRIDE |
145 { | 151 { |
146 return true; | 152 return true; |
147 } | 153 } |
148 | 154 |
149 private: | 155 private: |
150 CreateFileHelper(PassRefPtr<CreateFileResult> result, const String& name, co nst KURL& url, FileSystemType type) | 156 CreateFileHelper(PassRefPtrWillBeRawPtr<CreateFileResult> result, const Stri ng& name, const KURL& url, FileSystemType type) |
151 : m_result(result) | 157 : m_result(result) |
152 , m_name(name) | 158 , m_name(name) |
153 , m_url(url) | 159 , m_url(url) |
154 , m_type(type) | 160 , m_type(type) |
155 { | 161 { |
156 } | 162 } |
157 | 163 |
158 RefPtr<CreateFileResult> m_result; | 164 RefPtrWillBePersistent<CreateFileResult> m_result; |
159 String m_name; | 165 String m_name; |
160 KURL m_url; | 166 KURL m_url; |
161 FileSystemType m_type; | 167 FileSystemType m_type; |
162 }; | 168 }; |
163 | 169 |
164 } // namespace | 170 } // namespace |
165 | 171 |
166 PassRefPtrWillBeRawPtr<File> DOMFileSystemSync::createFile(const FileEntrySync* fileEntry, ExceptionState& exceptionState) | 172 PassRefPtrWillBeRawPtr<File> DOMFileSystemSync::createFile(const FileEntrySync* fileEntry, ExceptionState& exceptionState) |
167 { | 173 { |
168 KURL fileSystemURL = createFileSystemURL(fileEntry); | 174 KURL fileSystemURL = createFileSystemURL(fileEntry); |
169 RefPtr<CreateFileHelper::CreateFileResult> result(CreateFileHelper::CreateFi leResult::create()); | 175 RefPtrWillBeRawPtr<CreateFileHelper::CreateFileResult> result(CreateFileHelp er::CreateFileResult::create()); |
170 fileSystem()->createSnapshotFileAndReadMetadata(fileSystemURL, CreateFileHel per::create(result, fileEntry->name(), fileSystemURL, type())); | 176 fileSystem()->createSnapshotFileAndReadMetadata(fileSystemURL, CreateFileHel per::create(result, fileEntry->name(), fileSystemURL, type())); |
171 if (result->m_failed) { | 177 if (result->m_failed) { |
172 exceptionState.throwDOMException(result->m_code, "Could not create '" + fileEntry->name() + "'."); | 178 exceptionState.throwDOMException(result->m_code, "Could not create '" + fileEntry->name() + "'."); |
173 return nullptr; | 179 return nullptr; |
174 } | 180 } |
175 return result->m_file.get(); | 181 return result->m_file.get(); |
176 } | 182 } |
177 | 183 |
178 namespace { | 184 namespace { |
179 | 185 |
(...skipping 31 matching lines...) Loading... | |
211 explicit LocalErrorCallback(FileError::ErrorCode& errorCode) | 217 explicit LocalErrorCallback(FileError::ErrorCode& errorCode) |
212 : m_errorCode(errorCode) | 218 : m_errorCode(errorCode) |
213 { | 219 { |
214 } | 220 } |
215 | 221 |
216 FileError::ErrorCode& m_errorCode; | 222 FileError::ErrorCode& m_errorCode; |
217 }; | 223 }; |
218 | 224 |
219 } | 225 } |
220 | 226 |
221 PassRefPtr<FileWriterSync> DOMFileSystemSync::createWriter(const FileEntrySync* fileEntry, ExceptionState& exceptionState) | 227 PassRefPtrWillBeRawPtr<FileWriterSync> DOMFileSystemSync::createWriter(const Fil eEntrySync* fileEntry, ExceptionState& exceptionState) |
222 { | 228 { |
223 ASSERT(fileEntry); | 229 ASSERT(fileEntry); |
224 | 230 |
225 RefPtr<FileWriterSync> fileWriter = FileWriterSync::create(); | 231 RefPtrWillBeRawPtr<FileWriterSync> fileWriter = FileWriterSync::create(); |
226 OwnPtr<ReceiveFileWriterCallback> successCallback = ReceiveFileWriterCallbac k::create(); | 232 OwnPtr<ReceiveFileWriterCallback> successCallback = ReceiveFileWriterCallbac k::create(); |
227 FileError::ErrorCode errorCode = FileError::OK; | 233 FileError::ErrorCode errorCode = FileError::OK; |
228 OwnPtr<LocalErrorCallback> errorCallback = LocalErrorCallback::create(errorC ode); | 234 OwnPtr<LocalErrorCallback> errorCallback = LocalErrorCallback::create(errorC ode); |
229 | 235 |
230 OwnPtr<AsyncFileSystemCallbacks> callbacks = FileWriterBaseCallbacks::create (fileWriter, successCallback.release(), errorCallback.release()); | 236 OwnPtr<AsyncFileSystemCallbacks> callbacks = FileWriterBaseCallbacks::create (fileWriter, successCallback.release(), errorCallback.release()); |
231 callbacks->setShouldBlockUntilCompletion(true); | 237 callbacks->setShouldBlockUntilCompletion(true); |
232 | 238 |
233 fileSystem()->createFileWriter(createFileSystemURL(fileEntry), fileWriter.ge t(), callbacks.release()); | 239 fileSystem()->createFileWriter(createFileSystemURL(fileEntry), fileWriter.ge t(), callbacks.release()); |
234 if (errorCode != FileError::OK) { | 240 if (errorCode != FileError::OK) { |
235 FileError::throwDOMException(exceptionState, errorCode); | 241 FileError::throwDOMException(exceptionState, errorCode); |
236 return nullptr; | 242 return nullptr; |
237 } | 243 } |
238 return fileWriter.release(); | 244 return fileWriter.release(); |
239 } | 245 } |
240 | 246 |
241 } | 247 } |
OLD | NEW |