1 /* 2 * Copyright (C) 2008 Apple 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 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 #include "config.h" 27 #include "LocalStorageTask.h" 28 29 #if ENABLE(DOM_STORAGE) 30 31 #include "LocalStorageThread.h" 32 #include "StorageAreaSync.h" 33 #include "StorageTracker.h" 34 35 namespace WebCore { 36 37 LocalStorageTask::LocalStorageTask(Type type, StorageAreaSync* area) 38 : m_type(type) 39 , m_area(area) 40 , m_thread(0) 41 { 42 ASSERT(m_area); 43 ASSERT(m_type == AreaImport || m_type == AreaSync || m_type == DeleteEmptyDatabase); 44 } 45 46 LocalStorageTask::LocalStorageTask(Type type, LocalStorageThread* thread) 47 : m_type(type) 48 , m_area(0) 49 , m_thread(thread) 50 { 51 ASSERT(m_thread); 52 ASSERT(m_type == TerminateThread); 53 } 54 55 LocalStorageTask::LocalStorageTask(Type type) 56 : m_type(type) 57 { 58 ASSERT(m_type == ImportOrigins || m_type == DeleteAllOrigins); 59 } 60 61 LocalStorageTask::LocalStorageTask(Type type, const String& originIdentifier) 62 : m_type(type) 63 , m_originIdentifier(originIdentifier) 64 { 65 ASSERT(m_type == DeleteOrigin); 66 } 67 68 LocalStorageTask::LocalStorageTask(Type type, const String& originIdentifier, const String& databaseFilename) 69 : m_type(type) 70 , m_originIdentifier(originIdentifier) 71 , m_databaseFilename(databaseFilename) 72 { 73 ASSERT(m_type == SetOriginDetails); 74 } 75 76 LocalStorageTask::~LocalStorageTask() 77 { 78 } 79 80 void LocalStorageTask::performTask() 81 { 82 switch (m_type) { 83 case AreaImport: 84 m_area->performImport(); 85 break; 86 case AreaSync: 87 m_area->performSync(); 88 break; 89 case SetOriginDetails: 90 StorageTracker::tracker().syncSetOriginDetails(m_originIdentifier, m_databaseFilename); 91 break; 92 case ImportOrigins: 93 StorageTracker::tracker().syncImportOriginIdentifiers(); 94 break; 95 case DeleteAllOrigins: 96 StorageTracker::tracker().syncDeleteAllOrigins(); 97 break; 98 case DeleteOrigin: 99 StorageTracker::tracker().syncDeleteOrigin(m_originIdentifier); 100 break; 101 case DeleteEmptyDatabase: 102 m_area->deleteEmptyDatabase(); 103 break; 104 case TerminateThread: 105 m_thread->performTerminate(); 106 break; 107 } 108 } 109 110 } 111 112 #endif // ENABLE(DOM_STORAGE) 113