1a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch/* 2a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * Copyright (C) 2010 Google Inc. All rights reserved. 3a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * 4a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * Redistribution and use in source and binary forms, with or without 5a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * modification, are permitted provided that the following conditions are 6a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * met: 7a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * 8a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * * Redistributions of source code must retain the above copyright 9a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * notice, this list of conditions and the following disclaimer. 10a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * * Redistributions in binary form must reproduce the above 11a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * copyright notice, this list of conditions and the following disclaimer 12a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * in the documentation and/or other materials provided with the 13a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * distribution. 14a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * * Neither the name of Google Inc. nor the names of its 15a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * contributors may be used to endorse or promote products derived from 16a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * this software without specific prior written permission. 17a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * 18a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch */ 30a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch 31a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch#include "config.h" 32a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch#include "DirectoryEntrySync.h" 33a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch 34a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch#if ENABLE(FILE_SYSTEM) 35a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch 36a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch#include "DirectoryReaderSync.h" 37a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch#include "EntrySync.h" 38a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch#include "FileEntrySync.h" 39e14391e94c850b8bd03680c23b38978db68687a8John Reck#include "FileException.h" 40a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch#include "SyncCallbackHelper.h" 41a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch 42a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochnamespace WebCore { 43a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch 44e14391e94c850b8bd03680c23b38978db68687a8John ReckDirectoryEntrySync::DirectoryEntrySync(PassRefPtr<DOMFileSystemBase> fileSystem, const String& fullPath) 45a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch : EntrySync(fileSystem, fullPath) 46a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch{ 47a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch} 48a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch 49a94275402997c11dd2e778633dacf4b7e630a35dBen MurdochPassRefPtr<DirectoryReaderSync> DirectoryEntrySync::createReader(ExceptionCode&) 50a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch{ 51a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch return DirectoryReaderSync::create(m_fileSystem, m_fullPath); 52a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch} 53a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch 542daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben MurdochPassRefPtr<FileEntrySync> DirectoryEntrySync::getFile(const String& path, PassRefPtr<WebKitFlags> flags, ExceptionCode& ec) 55a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch{ 56a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch ec = 0; 57a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch EntrySyncCallbackHelper helper(m_fileSystem->asyncFileSystem()); 58a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch if (!m_fileSystem->getFile(this, path, flags, helper.successCallback(), helper.errorCallback())) { 59e14391e94c850b8bd03680c23b38978db68687a8John Reck ec = FileException::INVALID_MODIFICATION_ERR; 60a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch return 0; 61a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch } 62a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch return static_pointer_cast<FileEntrySync>(helper.getResult(ec)); 63a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch} 64a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch 652daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben MurdochPassRefPtr<DirectoryEntrySync> DirectoryEntrySync::getDirectory(const String& path, PassRefPtr<WebKitFlags> flags, ExceptionCode& ec) 66a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch{ 67a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch ec = 0; 68a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch EntrySyncCallbackHelper helper(m_fileSystem->asyncFileSystem()); 69a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch if (!m_fileSystem->getDirectory(this, path, flags, helper.successCallback(), helper.errorCallback())) { 70e14391e94c850b8bd03680c23b38978db68687a8John Reck ec = FileException::INVALID_MODIFICATION_ERR; 71a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch return 0; 72a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch } 73a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch return static_pointer_cast<DirectoryEntrySync>(helper.getResult(ec)); 74a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch} 75a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch 76a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochvoid DirectoryEntrySync::removeRecursively(ExceptionCode& ec) 77a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch{ 78a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch ec = 0; 79a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch VoidSyncCallbackHelper helper(m_fileSystem->asyncFileSystem()); 80a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch if (!m_fileSystem->removeRecursively(this, helper.successCallback(), helper.errorCallback())) { 81e14391e94c850b8bd03680c23b38978db68687a8John Reck ec = FileException::INVALID_MODIFICATION_ERR; 82a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch return; 83a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch } 84a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch helper.getResult(ec); 85a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch} 86a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch 87a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch} 88a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch 89a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch#endif // ENABLE(FILE_SYSTEM) 90