[content] Change secure log
[platform/framework/native/content.git] / src / FCntContentTransfer.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  * @file                FCntContentTransfer.cpp
19  * @brief               This is the implementation file for the %ContentTransfer class.
20  *
21  * This file contains implementation of the %ContentTransfer class.
22  */
23
24 #include <FBaseSysLog.h>
25 #include <FCntContentTransfer.h>
26 #include <FBaseColIList.h>
27 #include <FBaseUtilUri.h>
28 #include <FCnt_ContentTransferImpl.h>
29 #include <FSec_AccessController.h>
30
31 using namespace Tizen::Base;
32 using namespace Tizen::Security;
33
34 namespace Tizen { namespace Content
35 {
36 ContentTransfer::ContentTransfer(void)
37         : Object()
38         , __pImpl(null)
39 {
40
41 }
42
43 ContentTransfer::~ContentTransfer(void)
44 {
45         if (__pImpl != null)
46         {
47                 delete __pImpl;
48                 __pImpl = null;
49         }
50 }
51
52 result
53 ContentTransfer::Construct(IContentTransferListener& listener)
54 {
55         ClearLastResult();
56         result r = E_SUCCESS;
57
58         SysAssertf(__pImpl == null,
59                         "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
60
61         _ContentTransferImpl* pContentTransferImpl = new (std::nothrow) _ContentTransferImpl();
62         SysTryReturn(NID_CNT, pContentTransferImpl != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Construct failed.");
63
64         r = pContentTransferImpl->Construct(listener);
65         SysTryCatch(NID_CNT, r == E_SUCCESS, , r, "[%S] Propagating.", GetErrorMessage(r));
66
67         __pImpl = pContentTransferImpl;
68
69         return E_SUCCESS;
70
71 CATCH:
72         delete pContentTransferImpl;
73         pContentTransferImpl = null;
74
75         return r;
76 }
77
78 result
79 ContentTransfer::Cancel(RequestId reqId)
80 {
81         ClearLastResult();
82         result r = E_SUCCESS;
83
84         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
85
86         r = __pImpl->Cancel(reqId);
87         SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] Cancel failed.", GetErrorMessage(r));
88
89         return r;
90 }
91
92 void
93 ContentTransfer::SetDefaultTimeout(int sec)
94 {
95         if (__pImpl == null)
96         {
97                 SysLog(NID_CNT, "__pImpl is null.");
98                 return;
99         }
100         __pImpl->SetDefaultTimeout(sec);
101 }
102
103 int
104 ContentTransfer::GetDefaultTimeout(void) const
105 {
106         if (__pImpl == null)
107         {
108                 SysLog(NID_CNT, "__pImpl is null.");
109                 return 0;
110         }
111         return __pImpl->GetDefaultTimeout();
112 }
113
114 result
115 ContentTransfer::Remove(RequestId reqId)
116 {
117         ClearLastResult();
118         result r = E_SUCCESS;
119
120         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
121
122         r = __pImpl->Remove(reqId);
123         SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] Remove failed.", GetErrorMessage(r));
124
125         return r;
126 }
127
128 result
129 ContentTransfer::RemoveAll(void)
130 {
131         ClearLastResult();
132         result r = E_SUCCESS;
133
134         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
135
136         r = __pImpl->RemoveAll();
137         SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] RemoveAll failed.", GetErrorMessage(r));
138
139         return r;
140 }
141
142 result
143 ContentTransfer::CancelAll(void)
144 {
145         ClearLastResult();
146         result r = E_SUCCESS;
147
148         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
149
150         r = __pImpl->CancelAll();
151         SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] CancelAll failed.", GetErrorMessage(r));
152
153         return r;
154 }
155
156 Collection::IList*
157 ContentTransfer::GetContentTransferInfoListN(void) const
158 {
159         if (__pImpl == null)
160         {
161                 SysLog(NID_CNT, "__pImpl is null.");
162                 return null;
163         }
164         return __pImpl->GetContentTransferInfoListN();
165 }
166
167 Collection::IList*
168 ContentTransfer::GetContentTransferInfoListInProgressN(void) const
169 {
170         if (__pImpl == null)
171         {
172                 SysLog(NID_CNT, "__pImpl is null.");
173                 return null;
174         }
175         return __pImpl->GetContentTransferInfoListInProgressN();
176 }
177
178 void
179 ContentTransfer::SetProgressIntervalByPercent(int percent)
180 {
181         if (__pImpl == null)
182         {
183                 SysLog(NID_CNT, "__pImpl is null.");
184                 return;
185         }
186         __pImpl->SetProgressIntervalByPercent(percent);
187 }
188
189 result
190 ContentTransfer::Download(const Utility::Uri& uri, int fileSize, const String& destFilePath, bool replace,
191                 RequestId& reqId, IContentTransferListener* pListener, int sec)
192 {
193         ClearLastResult();
194         result r = E_SUCCESS;
195
196         // Checks the privilege
197         r = _AccessController::CheckUserPrivilege(_PRV_DOWNLOAD);
198         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
199         SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "The application is not permitted to call this method.");
200
201         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
202
203         r = __pImpl->Download(uri, fileSize, destFilePath, replace, reqId, pListener, sec);
204         SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] Download failed.", GetErrorMessage(r));
205
206         return r;
207 }
208
209 result
210 ContentTransfer::Download(const Utility::Uri& uri, const String& filePath,
211                                                   RequestId& reqId, bool replace, int timeout, int progressInterval)
212 {
213         ClearLastResult();
214         result r = E_SUCCESS;
215
216         // Checks the privilege
217         r = _AccessController::CheckUserPrivilege(_PRV_DOWNLOAD);
218         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
219         SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "The application is not permitted to call this method.");
220
221         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
222
223         r = __pImpl->Download(uri, filePath, reqId, replace, timeout, progressInterval);
224         SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] Download failed.", GetErrorMessage(r));
225
226         return r;
227 }
228
229 result
230 ContentTransfer::DownloadToBuffer(const Utility::Uri& uri, int fileSize, RequestId& reqId,IContentTransferListener* pListener, int sec)
231 {
232         ClearLastResult();
233         result r = E_SUCCESS;
234
235         r = _AccessController::CheckUserPrivilege(_PRV_DOWNLOAD);
236         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
237         SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "The application is not permitted to call this method.");
238
239         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
240
241         r = __pImpl->DownloadToBuffer(uri, fileSize, reqId, pListener, sec);
242         SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] DownloadToBuffer failed.", GetErrorMessage(r));
243
244         return r;
245 }
246
247 result
248 ContentTransfer::DownloadToBuffer(const Utility::Uri& uri, RequestId& reqId, int timeout, int progressInterval)
249 {
250         ClearLastResult();
251         result r = E_SUCCESS;
252
253         r = _AccessController::CheckUserPrivilege(_PRV_DOWNLOAD);
254         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
255         SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "The application is not permitted to call this method.");
256
257         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
258
259         r = __pImpl->DownloadToBuffer(uri, reqId, timeout, progressInterval);
260         SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] DownloadToBuffer failed.", GetErrorMessage(r));
261
262         return r;
263 }
264 }}