15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/*
25c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 2010 Google Inc. All rights reserved.
35c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without
55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * modification, are permitted provided that the following conditions are
65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * met:
75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *     * Redistributions of source code must retain the above copyright
95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * notice, this list of conditions and the following disclaimer.
105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *     * Redistributions in binary form must reproduce the above
115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * copyright notice, this list of conditions and the following disclaimer
125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * in the documentation and/or other materials provided with the
135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * distribution.
145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *     * Neither the name of Google Inc. nor the names of its
155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * contributors may be used to endorse or promote products derived from
165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * this software without specific prior written permission.
175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) */
305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include "config.h"
3253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "modules/filesystem/EntrySync.h"
335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
34197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#include "bindings/core/v8/ExceptionMessages.h"
35197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#include "bindings/core/v8/ExceptionState.h"
36591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch#include "core/dom/ExceptionCode.h"
3753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "modules/filesystem/DOMFilePath.h"
3853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "modules/filesystem/DirectoryEntry.h"
3953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "modules/filesystem/DirectoryEntrySync.h"
4053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "modules/filesystem/FileEntrySync.h"
4153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "modules/filesystem/Metadata.h"
4253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "modules/filesystem/SyncCallbackHelper.h"
435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
44c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink {
455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
465d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)EntrySync* EntrySync::create(EntryBase* entry)
475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (entry->isFile())
4909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        return FileEntrySync::create(entry->m_fileSystem, entry->m_fullPath);
5009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    return DirectoryEntrySync::create(entry->m_fileSystem, entry->m_fullPath);
515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
535d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)Metadata* EntrySync::getMetadata(ExceptionState& exceptionState)
545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
557242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    MetadataSyncCallbackHelper* helper = MetadataSyncCallbackHelper::create();
56aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch    m_fileSystem->getMetadata(this, helper->successCallback(), helper->errorCallback(), DOMFileSystemBase::Synchronous);
57aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch    return helper->getResult(exceptionState);
585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
605d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)EntrySync* EntrySync::moveTo(DirectoryEntrySync* parent, const String& name, ExceptionState& exceptionState) const
615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
627242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    EntrySyncCallbackHelper* helper = EntrySyncCallbackHelper::create();
635d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    m_fileSystem->move(this, parent, name, helper->successCallback(), helper->errorCallback(), DOMFileSystemBase::Synchronous);
64aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch    return helper->getResult(exceptionState);
655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
675d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)EntrySync* EntrySync::copyTo(DirectoryEntrySync* parent, const String& name, ExceptionState& exceptionState) const
685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
697242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    EntrySyncCallbackHelper* helper = EntrySyncCallbackHelper::create();
705d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    m_fileSystem->copy(this, parent, name, helper->successCallback(), helper->errorCallback(), DOMFileSystemBase::Synchronous);
71aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch    return helper->getResult(exceptionState);
725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
7451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)void EntrySync::remove(ExceptionState& exceptionState) const
755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
767242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    VoidSyncCallbackHelper* helper = VoidSyncCallbackHelper::create();
77aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch    m_fileSystem->remove(this, helper->successCallback(), helper->errorCallback(), DOMFileSystemBase::Synchronous);
78aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch    helper->getResult(exceptionState);
795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
815d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)EntrySync* EntrySync::getParent() const
825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Sync verion of getParent doesn't throw exceptions.
845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    String parentPath = DOMFilePath::getDirectory(fullPath());
855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return DirectoryEntrySync::create(m_fileSystem, parentPath);
865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
885d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)EntrySync::EntrySync(DOMFileSystemBase* fileSystem, const String& fullPath)
895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    : EntryBase(fileSystem, fullPath)
905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
93d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)void EntrySync::trace(Visitor* visitor)
94d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles){
95d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    EntryBase::trace(visitor);
96d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)}
97d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
99