1 /* 2 * Copyright (C) 2010 Google Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: 7 * 8 * * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * * Redistributions in binary form must reproduce the above 11 * copyright notice, this list of conditions and the following disclaimer 12 * in the documentation and/or other materials provided with the 13 * distribution. 14 * * Neither the name of Google Inc. nor the names of its 15 * contributors may be used to endorse or promote products derived from 16 * this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 #ifndef WebFileSystemCallbacks_h 32 #define WebFileSystemCallbacks_h 33 34 #include "WebCommon.h" 35 #include "WebFileError.h" 36 #include "WebFileSystemEntry.h" 37 #include "WebFileSystemType.h" 38 #include "WebPrivatePtr.h" 39 #include "WebVector.h" 40 41 namespace WTF { template <typename T> class PassOwnPtr; } 42 43 namespace blink { 44 45 class AsyncFileSystemCallbacks; 46 class WebFileWriter; 47 class WebString; 48 class WebURL; 49 class WebFileSystemCallbacksPrivate; 50 struct WebFileInfo; 51 52 class WebFileSystemCallbacks { 53 public: 54 ~WebFileSystemCallbacks() { reset(); } 55 WebFileSystemCallbacks() { } 56 WebFileSystemCallbacks(const WebFileSystemCallbacks& c) { assign(c); } 57 WebFileSystemCallbacks& operator=(const WebFileSystemCallbacks& c) 58 { 59 assign(c); 60 return *this; 61 } 62 63 BLINK_PLATFORM_EXPORT void reset(); 64 BLINK_PLATFORM_EXPORT void assign(const WebFileSystemCallbacks&); 65 66 #if INSIDE_BLINK 67 BLINK_PLATFORM_EXPORT WebFileSystemCallbacks(const WTF::PassOwnPtr<AsyncFileSystemCallbacks>&); 68 #endif 69 70 // Callback for WebFileSystem's various operations that don't require 71 // return values. 72 BLINK_PLATFORM_EXPORT void didSucceed(); 73 74 // Callback for WebFileSystem::readMetadata. Called with the file metadata 75 // for the requested path. 76 BLINK_PLATFORM_EXPORT void didReadMetadata(const WebFileInfo&); 77 78 // Callback for WebFileSystem::createSnapshot. The metadata also includes the 79 // platform file path. 80 BLINK_PLATFORM_EXPORT void didCreateSnapshotFile(const WebFileInfo&); 81 82 // Callback for WebFileSystem::readDirectory. Called with a vector of 83 // file entries in the requested directory. This callback might be called 84 // multiple times if the directory has many entries. |hasMore| must be 85 // true when there are more entries. 86 BLINK_PLATFORM_EXPORT void didReadDirectory(const WebVector<WebFileSystemEntry>&, bool hasMore); 87 88 // Callback for WebFileSystem::openFileSystem. Called with a name and 89 // root URL for the FileSystem when the request is accepted. 90 BLINK_PLATFORM_EXPORT void didOpenFileSystem(const WebString& name, const WebURL& rootURL); 91 92 // Callback for WebFileSystem::resolveURL. Called with a name, root URL and 93 // file path for the FileSystem when the request is accepted. |isDirectory| 94 // must be true when an entry to be resolved is a directory. 95 BLINK_PLATFORM_EXPORT void didResolveURL(const WebString& name, const WebURL& rootURL, WebFileSystemType, const WebString& filePath, bool isDirectory); 96 97 // Callback for WebFileSystem::createFileWriter. Called with an instance 98 // of WebFileWriter and the target file length. The writer's ownership 99 // is transferred to the callback. 100 BLINK_PLATFORM_EXPORT void didCreateFileWriter(WebFileWriter*, long long length); 101 102 // Called with an error code when a requested operation hasn't been 103 // completed. 104 BLINK_PLATFORM_EXPORT void didFail(WebFileError); 105 106 // Returns true if the caller expects to be blocked until the request 107 // is fullfilled. 108 BLINK_PLATFORM_EXPORT bool shouldBlockUntilCompletion() const; 109 110 private: 111 WebPrivatePtr<WebFileSystemCallbacksPrivate> m_private; 112 }; 113 114 } // namespace blink 115 116 #endif 117