Remove warning message and Update doxygen
[framework/osp/web.git] / src / controls / FWebCtrlWebStorageManager.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file                FWebCtrlWebStorageManager.cpp
20  * @brief               The file contains the definition of FWebCtrlWebStorageManager class.
21  *
22  * The file contains the definition of FWebCtrlWebStorageManager class.
23  */
24 #include <unique_ptr.h>
25 #include <FBaseColIList.h>
26 #include <FBaseSysLog.h>
27 #include <FWebCtrlWebStorageManager.h>
28 #include <FSec_AccessController.h>
29 #include "FWebCtrl_WebStorageManagerImpl.h"
30
31
32 using namespace Tizen::Base;
33 using namespace Tizen::Base::Collection;
34 using namespace Tizen::Security;
35
36
37 namespace Tizen { namespace Web { namespace Controls
38 {
39
40
41 WebStorageManager* WebStorageManager::__pInstance = null;
42
43
44 WebStorageManager::WebStorageManager(void)
45         : __pWebStorageManagerImpl(null)
46 {
47         std::unique_ptr<_WebStorageManagerImpl> pWebStorageManagerImpl(new (std::nothrow) _WebStorageManagerImpl());
48         SysTryReturnVoidResult(NID_WEB_CTRL, pWebStorageManagerImpl.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
49
50         __pWebStorageManagerImpl = pWebStorageManagerImpl.release();
51 }
52
53
54 WebStorageManager::~WebStorageManager(void)
55 {
56         delete __pWebStorageManagerImpl;
57 }
58
59
60 void
61 WebStorageManager::InitWebStorageManager(void)
62 {
63         std::unique_ptr<WebStorageManager> pInstance(new (std::nothrow) WebStorageManager());
64         SysTryReturnVoidResult(NID_WEB_CTRL, pInstance.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
65
66         __pInstance = pInstance.release();
67         std::atexit(DestroyWebStorageManager);
68 }
69
70
71 void
72 WebStorageManager::DestroyWebStorageManager(void)
73 {
74         delete __pInstance;
75         __pInstance = null;
76 }
77
78
79 WebStorageManager*
80 WebStorageManager::GetInstance(void)
81 {
82         static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
83         if (__pInstance== null)
84         {
85                 ClearLastResult();
86                 pthread_once(&onceBlock, InitWebStorageManager);
87                 result r = GetLastResult();
88                 if (IsFailed(r))
89                 {
90                         onceBlock = PTHREAD_ONCE_INIT;
91                 }
92         }
93
94         return __pInstance;
95 }
96
97
98 IList*
99 WebStorageManager::GetOriginListN(WebStorageType storageType) const
100 {
101         SysAssertf(__pWebStorageManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
102
103         ClearLastResult();
104         result r = E_SUCCESS;
105
106         r = _AccessController::CheckUserPrivilege(_PRV_WEB_PRIVACY);
107         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, E_PRIVILEGE_DENIED, "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
108
109         IList* pList = __pWebStorageManagerImpl->GetOriginListN(storageType);
110         SysTryReturn(NID_WEB_CTRL, GetLastResult() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
111
112         return pList;
113 }
114
115
116 result
117 WebStorageManager::SetQuotaForOrigin(WebStorageType storageType, const String& origin, long quota)
118 {
119         SysAssertf(__pWebStorageManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
120
121         result r = E_SUCCESS;
122
123         r = _AccessController::CheckUserPrivilege(_PRV_WEB_PRIVACY);
124         SysTryReturnResult(NID_WEB_CTRL, r == E_SUCCESS, E_PRIVILEGE_DENIED, "[%s] The application does not have the privilege to call this method.",  GetErrorMessage(E_PRIVILEGE_DENIED));
125
126         r = __pWebStorageManagerImpl->SetQuotaForOrigin(storageType, origin, quota);
127         SysTryReturnResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
128
129         return E_SUCCESS;
130 }
131
132
133 long
134 WebStorageManager::GetQuotaForOrigin(WebStorageType storageType, const String& origin)
135 {
136         SysAssertf(__pWebStorageManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
137
138         ClearLastResult();
139         result r = E_SUCCESS;
140         long quota = 0;
141
142         r = _AccessController::CheckUserPrivilege(_PRV_WEB_PRIVACY);
143         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, 0, E_PRIVILEGE_DENIED, "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
144
145         quota = __pWebStorageManagerImpl->GetQuotaForOrigin(storageType, origin);
146         SysTryReturn(NID_WEB_CTRL, GetLastResult() == E_SUCCESS, 0, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
147
148         return quota;
149 }
150
151
152 long
153 WebStorageManager::GetUsageForOrigin(WebStorageType storageType, const String& origin) const
154 {
155         SysAssertf(__pWebStorageManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
156
157         ClearLastResult();
158         result r = E_SUCCESS;
159         long usage = 0;
160
161         r = _AccessController::CheckUserPrivilege(_PRV_WEB_PRIVACY);
162         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, 0, E_PRIVILEGE_DENIED, "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
163
164         usage = __pWebStorageManagerImpl->GetQuotaForOrigin(storageType, origin);
165         SysTryReturn(NID_WEB_CTRL, GetLastResult() == E_SUCCESS, 0, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
166
167         return usage;
168 }
169
170
171 result
172 WebStorageManager::Remove(WebStorageType storageType, const String& origin)
173 {
174         SysAssertf(__pWebStorageManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
175
176         result r = E_SUCCESS;
177
178         r = _AccessController::CheckUserPrivilege(_PRV_WEB_PRIVACY);
179         SysTryReturnResult(NID_WEB_CTRL, r == E_SUCCESS, E_PRIVILEGE_DENIED, "[%s] The application does not have the privilege to call this method.",  GetErrorMessage(E_PRIVILEGE_DENIED));
180
181         r = __pWebStorageManagerImpl->Remove(storageType, origin);
182         SysTryReturnResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
183
184         return E_SUCCESS;
185 }
186
187
188 result
189 WebStorageManager::RemoveAll(WebStorageType storageType)
190 {
191         SysAssertf(__pWebStorageManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
192
193         result r = E_SUCCESS;
194
195         r = _AccessController::CheckUserPrivilege(_PRV_WEB_PRIVACY);
196         SysTryReturnResult(NID_WEB_CTRL, r == E_SUCCESS, E_PRIVILEGE_DENIED, "[%s] The application does not have the privilege to call this method.",  GetErrorMessage(E_PRIVILEGE_DENIED));
197
198         r = __pWebStorageManagerImpl->RemoveAll(storageType);
199         SysTryReturnResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
200
201         return E_SUCCESS;
202 }
203
204
205 }}} // Tizen::Web::Controls