1/*
2 * Copyright (C) 2009 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#include "config.h"
32#include "WebDatabase.h"
33
34#include "public/platform/WebString.h"
35#include "wtf/PassRefPtr.h"
36#include "wtf/RefPtr.h"
37#include "WebDatabaseObserver.h"
38#include "modules/webdatabase/DatabaseBackendBase.h"
39#include "modules/webdatabase/DatabaseManager.h"
40#include "modules/webdatabase/QuotaTracker.h"
41#include "weborigin/SecurityOrigin.h"
42
43using namespace WebCore;
44
45namespace WebKit {
46
47static WebDatabaseObserver* databaseObserver = 0;
48
49WebString WebDatabase::name() const
50{
51    ASSERT(m_database);
52    return m_database->stringIdentifier();
53}
54
55WebString WebDatabase::displayName() const
56{
57    ASSERT(m_database);
58    return m_database->displayName();
59}
60
61unsigned long WebDatabase::estimatedSize() const
62{
63    ASSERT(m_database);
64    return m_database->estimatedSize();
65}
66
67WebSecurityOrigin WebDatabase::securityOrigin() const
68{
69    ASSERT(m_database);
70    return WebSecurityOrigin(m_database->securityOrigin());
71}
72
73bool WebDatabase::isSyncDatabase() const
74{
75    ASSERT(m_database);
76    return m_database->isSyncDatabase();
77}
78
79void WebDatabase::setObserver(WebDatabaseObserver* observer)
80{
81    databaseObserver = observer;
82}
83
84WebDatabaseObserver* WebDatabase::observer()
85{
86    return databaseObserver;
87}
88
89void WebDatabase::updateDatabaseSize(const WebString& originIdentifier, const WebString& name, long long size)
90{
91    QuotaTracker::instance().updateDatabaseSize(originIdentifier, name, size);
92}
93
94void WebDatabase::updateSpaceAvailable(const WebString& originIdentifier, long long spaceAvailable)
95{
96    QuotaTracker::instance().updateSpaceAvailableToOrigin(originIdentifier, spaceAvailable);
97}
98
99void WebDatabase::resetSpaceAvailable(const WebString& originIdentifier)
100{
101    QuotaTracker::instance().resetSpaceAvailableToOrigin(originIdentifier);
102}
103
104void WebDatabase::closeDatabaseImmediately(const WebString& originIdentifier, const WebString& databaseName)
105{
106    DatabaseManager::manager().closeDatabasesImmediately(originIdentifier, databaseName);
107}
108
109WebDatabase::WebDatabase(const DatabaseBackendBase* database)
110    : m_database(database)
111{
112}
113
114} // namespace WebKit
115