Upstream version 9.38.198.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 : public RefCounted<WebStorageQuotaCallbacksPrivate> {
18 public:
19     static PassRefPtr<WebStorageQuotaCallbacksPrivate> create(const PassOwnPtr<StorageQuotaCallbacks>& callbacks)
20     {
21         return adoptRef(new WebStorageQuotaCallbacksPrivate(callbacks));
22     }
23
24     StorageQuotaCallbacks* callbacks() { return m_callbacks.get(); }
25
26 private:
27     WebStorageQuotaCallbacksPrivate(const PassOwnPtr<StorageQuotaCallbacks>& callbacks) : m_callbacks(callbacks) { }
28     OwnPtr<StorageQuotaCallbacks> m_callbacks;
29 };
30
31 WebStorageQuotaCallbacks::WebStorageQuotaCallbacks(const PassOwnPtr<StorageQuotaCallbacks>& callbacks)
32 {
33     m_private = WebStorageQuotaCallbacksPrivate::create(callbacks);
34 }
35
36 void WebStorageQuotaCallbacks::reset()
37 {
38     m_private.reset();
39 }
40
41 void WebStorageQuotaCallbacks::assign(const WebStorageQuotaCallbacks& other)
42 {
43     m_private = other.m_private;
44 }
45
46 void WebStorageQuotaCallbacks::didQueryStorageUsageAndQuota(unsigned long long usageInBytes, unsigned long long quotaInBytes)
47 {
48     ASSERT(!m_private.isNull());
49     m_private->callbacks()->didQueryStorageUsageAndQuota(usageInBytes, quotaInBytes);
50     m_private.reset();
51 }
52
53 void WebStorageQuotaCallbacks::didGrantStorageQuota(unsigned long long usageInBytes, unsigned long long grantedQuotaInBytes)
54 {
55     ASSERT(!m_private.isNull());
56     m_private->callbacks()->didGrantStorageQuota(usageInBytes, grantedQuotaInBytes);
57     m_private.reset();
58 }
59
60 void WebStorageQuotaCallbacks::didFail(WebStorageQuotaError error)
61 {
62     ASSERT(!m_private.isNull());
63     m_private->callbacks()->didFail(error);
64     m_private.reset();
65 }
66
67 } // namespace blink