Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / platform / exported / WebStorageQuotaCallbacks.cpp
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "public/platform/WebStorageQuotaCallbacks.h"
7
8 #include "platform/StorageQuotaCallbacks.h"
9 #include "wtf/Forward.h"
10 #include "wtf/OwnPtr.h"
11 #include "wtf/PassOwnPtr.h"
12 #include "wtf/PassRefPtr.h"
13 #include "wtf/RefCounted.h"
14
15 namespace blink {
16
17 class WebStorageQuotaCallbacksPrivate FINAL : public RefCountedWillBeGarbageCollected<WebStorageQuotaCallbacksPrivate> {
18 public:
19     static PassRefPtrWillBeRawPtr<WebStorageQuotaCallbacksPrivate> create(const PassOwnPtrWillBeRawPtr<StorageQuotaCallbacks>& callbacks)
20     {
21         return adoptRefWillBeNoop(new WebStorageQuotaCallbacksPrivate(callbacks));
22     }
23
24     void trace(Visitor*);
25
26     StorageQuotaCallbacks* callbacks() { return m_callbacks.get(); }
27
28 private:
29     WebStorageQuotaCallbacksPrivate(const PassOwnPtrWillBeRawPtr<StorageQuotaCallbacks>& callbacks) : m_callbacks(callbacks) { }
30     OwnPtrWillBeMember<StorageQuotaCallbacks> m_callbacks;
31 };
32
33 void WebStorageQuotaCallbacksPrivate::trace(Visitor* visitor)
34 {
35     visitor->trace(m_callbacks);
36 }
37
38 WebStorageQuotaCallbacks::WebStorageQuotaCallbacks(const PassOwnPtrWillBeRawPtr<StorageQuotaCallbacks>& callbacks)
39 {
40     m_private = WebStorageQuotaCallbacksPrivate::create(callbacks);
41 }
42
43 void WebStorageQuotaCallbacks::reset()
44 {
45     m_private.reset();
46 }
47
48 void WebStorageQuotaCallbacks::assign(const WebStorageQuotaCallbacks& other)
49 {
50     m_private = other.m_private;
51 }
52
53 void WebStorageQuotaCallbacks::didQueryStorageUsageAndQuota(unsigned long long usageInBytes, unsigned long long quotaInBytes)
54 {
55     ASSERT(!m_private.isNull());
56     m_private->callbacks()->didQueryStorageUsageAndQuota(usageInBytes, quotaInBytes);
57     m_private.reset();
58 }
59
60 void WebStorageQuotaCallbacks::didGrantStorageQuota(unsigned long long usageInBytes, unsigned long long grantedQuotaInBytes)
61 {
62     ASSERT(!m_private.isNull());
63     m_private->callbacks()->didGrantStorageQuota(usageInBytes, grantedQuotaInBytes);
64     m_private.reset();
65 }
66
67 void WebStorageQuotaCallbacks::didFail(WebStorageQuotaError error)
68 {
69     ASSERT(!m_private.isNull());
70     m_private->callbacks()->didFail(error);
71     m_private.reset();
72 }
73
74 } // namespace blink