2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
17 * @file FCntContentTransfer.cpp
18 * @brief This is the implementation file for the %ContentTransfer class.
20 * This file contains implementation of the %ContentTransfer class.
23 #include <FBaseSysLog.h>
24 #include <FCntContentTransfer.h>
25 #include <FBaseColIList.h>
26 #include <FBaseUtilUri.h>
27 #include <FCnt_ContentTransferImpl.h>
28 #include <FSec_AccessController.h>
30 using namespace Tizen::Base;
31 using namespace Tizen::Security;
33 namespace Tizen { namespace Content
35 ContentTransfer::ContentTransfer(void)
42 ContentTransfer::~ContentTransfer(void)
52 ContentTransfer::Construct(IContentTransferListener& listener)
57 SysAssertf(__pImpl == null,
58 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
60 _ContentTransferImpl* pContentTransferImpl = new (std::nothrow) _ContentTransferImpl();
61 SysTryReturn(NID_CNT, pContentTransferImpl != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Construct failed.");
63 r = pContentTransferImpl->Construct(listener);
64 SysTryCatch(NID_CNT, r == E_SUCCESS, , r, "[%S] Propagating.", GetErrorMessage(r));
66 __pImpl = pContentTransferImpl;
71 delete pContentTransferImpl;
72 pContentTransferImpl = null;
78 ContentTransfer::Cancel(RequestId reqId)
83 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
85 r = __pImpl->Cancel(reqId);
86 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] Cancel failed.", GetErrorMessage(r));
92 ContentTransfer::SetDefaultTimeout(int sec)
96 SysLog(NID_CNT, "__pImpl is null.");
99 __pImpl->SetDefaultTimeout(sec);
103 ContentTransfer::GetDefaultTimeout(void) const
107 SysLog(NID_CNT, "__pImpl is null.");
110 return __pImpl->GetDefaultTimeout();
114 ContentTransfer::Remove(RequestId reqId)
117 result r = E_SUCCESS;
119 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
121 r = __pImpl->Remove(reqId);
122 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] Remove failed.", GetErrorMessage(r));
128 ContentTransfer::RemoveAll(void)
131 result r = E_SUCCESS;
133 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
135 r = __pImpl->RemoveAll();
136 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] RemoveAll failed.", GetErrorMessage(r));
142 ContentTransfer::CancelAll(void)
145 result r = E_SUCCESS;
147 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
149 r = __pImpl->CancelAll();
150 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] CancelAll failed.", GetErrorMessage(r));
156 ContentTransfer::GetContentTransferInfoListN(void) const
160 SysLog(NID_CNT, "__pImpl is null.");
163 return __pImpl->GetContentTransferInfoListN();
167 ContentTransfer::GetContentTransferInfoListInProgressN(void) const
171 SysLog(NID_CNT, "__pImpl is null.");
174 return __pImpl->GetContentTransferInfoListInProgressN();
178 ContentTransfer::SetProgressIntervalByPercent(int percent)
182 SysLog(NID_CNT, "__pImpl is null.");
185 __pImpl->SetProgressIntervalByPercent(percent);
189 ContentTransfer::Download(const Utility::Uri& uri, int fileSize, const String& destFilePath, bool replace,
190 RequestId& reqId, IContentTransferListener* pListener, int sec)
193 result r = E_SUCCESS;
195 // Checks the privilege
196 r = _AccessController::CheckUserPrivilege(_PRV_DOWNLOAD);
197 r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
198 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "The application is not permitted to call this method.");
200 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
202 r = __pImpl->Download(uri, fileSize, destFilePath, replace, reqId, pListener, sec);
203 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] Download failed.", GetErrorMessage(r));
209 ContentTransfer::Download(const Utility::Uri& uri, const String& filePath,
210 RequestId& reqId, bool replace, int timeout, int progressInterval)
213 result r = E_SUCCESS;
215 // Checks the privilege
216 r = _AccessController::CheckUserPrivilege(_PRV_DOWNLOAD);
217 r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
218 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "The application is not permitted to call this method.");
220 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
222 r = __pImpl->Download(uri, filePath, reqId, replace, timeout, progressInterval);
223 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] Download failed.", GetErrorMessage(r));
229 ContentTransfer::DownloadToBuffer(const Utility::Uri& uri, int fileSize, RequestId& reqId,IContentTransferListener* pListener, int sec)
232 result r = E_SUCCESS;
234 r = _AccessController::CheckUserPrivilege(_PRV_DOWNLOAD);
235 r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
236 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "The application is not permitted to call this method.");
238 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
240 r = __pImpl->DownloadToBuffer(uri, fileSize, reqId, pListener, sec);
241 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] DownloadToBuffer failed.", GetErrorMessage(r));
247 ContentTransfer::DownloadToBuffer(const Utility::Uri& uri, RequestId& reqId, int timeout, int progressInterval)
250 result r = E_SUCCESS;
252 r = _AccessController::CheckUserPrivilege(_PRV_DOWNLOAD);
253 r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
254 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "The application is not permitted to call this method.");
256 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
258 r = __pImpl->DownloadToBuffer(uri, reqId, timeout, progressInterval);
259 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] DownloadToBuffer failed.", GetErrorMessage(r));