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 FCnt_ContentDownloadListener.cpp
18 * @brief This is the implementation file for the %_ContentDownloadListener class.
20 * This file contains implementation of the %_ContentDownloadListener class.
23 #include <unique_ptr.h>
24 #include <FBaseSysLog.h>
25 #include <FIoDirectory.h>
26 #include <FSysEnvironment.h>
27 #include <FCntImageContentInfo.h>
28 #include <FCntVideoContentInfo.h>
29 #include <FCntAudioContentInfo.h>
30 #include <FCntOtherContentInfo.h>
31 #include <FApp_AppInfo.h>
32 #include <FCnt_ContentManagerImpl.h>
33 #include <FCnt_ContentManagerUtilImpl.h>
34 #include <FIo_FileImpl.h>
35 #include "FCnt_ContentDownloadListener.h"
37 using namespace Tizen;
38 using namespace Tizen::App;
39 using namespace Tizen::Base;
40 using namespace Tizen::Base::Runtime;
41 using namespace Tizen::Io;
42 using namespace Tizen::System;
43 using namespace Tizen::Net;
44 using namespace Tizen::Net::Http;
46 namespace Tizen { namespace Content
49 static const int INVALID_PROGRESS_INTERVAL = -1;
50 static const int CONTENT_TRANSFER_COUNTER = 20;
52 _ContentDownloadListener::_ContentDownloadListener(void)
55 _ContentDownloadListener::~_ContentDownloadListener(void)
60 _ContentDownloadListener::OnTransactionReadyToRead(HttpSession& httpSession,
61 HttpTransaction& httpTransaction, int availableBodyLen)
63 SysLog(NID_CNT, "OnTransactionReadyToRead event fired.");
66 std::unique_ptr<File> pFile;
67 std::unique_ptr<ByteBuffer> pBody;
68 HttpResponse* pHttpResponse = null;
70 _ContentDownloadUserData* pUserData = dynamic_cast<_ContentDownloadUserData*>(httpTransaction.GetUserObject());
71 SysTryReturnVoidResult(NID_CNT, pUserData != null, r = E_SYSTEM,
72 "[E_SYSTEM] ContentDownloadUserData instance must not be null.");
74 SysLog(NID_CNT, "##### Request ID : %d #####", pUserData->GetRequestId());
75 SysLog(NID_CNT, "##### Download path : %ls #####", pUserData->GetDestPath().GetPointer());
76 SysLog(NID_CNT, "##### Download URL : %ls #####", pUserData->GetUrl().GetPointer());
77 SysLog(NID_CNT, "##### Slot number : %d #####", pUserData->GetSlot());
78 SysLog(NID_CNT, "##### Total size : %lld #####", pUserData->GetTotalSize());
79 SysLog(NID_CNT, "##### Prev data size : %lld #####", pUserData->GetPrevData());
81 pHttpResponse = httpTransaction.GetResponse();
83 SysTryReturnVoidResult(NID_CNT, pHttpResponse != null, r, "[%s] Failed to get the HTTP transaction response.", GetErrorMessage(r));
85 if (pHttpResponse->GetHttpStatusCode() != HTTP_STATUS_OK)
87 SysLogException(NID_CNT, E_INVALID_STATE, "[E_INVALID_STATE] HTTP status code is not HTTP_STATUS_OK.");
91 pBody = std::unique_ptr<ByteBuffer>(pHttpResponse->ReadBodyN());
92 SysTryReturnVoidResult(NID_CNT, pBody != null, r = E_OUT_OF_MEMORY,
93 "[E_OUT_OF_MEMORY] Failed to perform ReadBodyN operation to ByteBuffer.");
95 pFile = std::unique_ptr<File>(new (std::nothrow) File);
96 SysTryReturnVoidResult(NID_CNT, pFile != null, r = E_OUT_OF_MEMORY,
97 "[E_OUT_OF_MEMORY] Failed to construct File.");
99 r = pFile->Construct(pUserData->GetDestPath(), L"a+");
100 SysTryReturnVoidResult(NID_CNT, !IsFailed(r), r, "[%s] Failed to construct File.", GetErrorMessage(r));
102 r = pFile->Write(*(pBody.get()));
103 SysTryReturnVoidResult(NID_CNT, !IsFailed(r), r, "[%s] Failed to perform write operation to File.", GetErrorMessage(r));
107 _ContentDownloadListener::OnTransactionAborted(HttpSession& httpSession, HttpTransaction& httpTransaction, result res)
109 SysLog(NID_CNT, "OnTransactionAborted event fired.");
111 HttpResponse* pHttpResponse = null;
112 String errorMsg(L"");
114 result r = E_SUCCESS;
116 SysLog(NID_CNT, "Input result parameter of OnTransactionAborted is [%s]", GetErrorMessage(res));
118 _ContentDownloadUserData* pUserData = dynamic_cast<_ContentDownloadUserData*>(httpTransaction.GetUserObject());
119 SysTryReturnVoidResult(NID_CNT, pUserData != null, r = E_SYSTEM,
120 "[E_SYSTEM] ContentDownloadUserData instance must not be null.");
122 pHttpResponse = httpTransaction.GetResponse();
126 SysLog(NID_CNT, "[%s] Failed to get the HTTP transaction response.", GetErrorMessage(r));
130 statusCode = pHttpResponse->GetHttpStatusCode();
131 SysTryReturnVoidResult(NID_CNT, statusCode == HTTP_STATUS_OK, r = E_INVALID_STATE,
132 "[E_INVALID_STATE] HTTP status code is not HTTP_STATUS_OK.");
134 errorMsg = pHttpResponse->GetStatusText();
136 SysTryReturnVoidResult(NID_CNT, !IsFailed(r), r = E_INVALID_STATE,
137 "[E_INVALID_STATE] The server is unavailable.");
140 // delete downloaded file because of error
141 if (_FileImpl::IsFileExist(pUserData->GetDestPath()))
143 r = _FileImpl::Remove(pUserData->GetDestPath());
144 SysTryReturnVoidResult(NID_CNT, !IsFailed(r), r,
145 "[%s] Failed to remove the downloaded file on OnTransactionAborted.", GetErrorMessage(r));
148 DownloadCanceled(pUserData, statusCode, errorMsg, E_SERVER);
152 _ContentDownloadListener::OnTransactionCompleted(HttpSession& httpSession, HttpTransaction& httpTransaction)
154 SysLog(NID_CNT, "OnTransactionCompleted event fired.");
157 result r = E_SUCCESS;
158 HttpResponse* pHttpResponse = null;
159 String errorMsg(L"");
161 String destPath(L"");
163 _ContentDownloadUserData* pUserData = dynamic_cast<_ContentDownloadUserData*>(httpTransaction.GetUserObject());
164 SysTryReturnVoidResult(NID_CNT, pUserData != null, r = E_SYSTEM,
165 "[E_SYSTEM] ContentDownloadUserData instance must not be null.");
167 pHttpResponse = httpTransaction.GetResponse();
168 SysTryCatch(NID_CNT, pHttpResponse != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Failed to get the HTTP transaction response.");
170 pUserData->SetDownloadCount(0);
172 statusCode = pHttpResponse->GetHttpStatusCode();
173 SysTryCatch(NID_CNT, statusCode == HTTP_STATUS_OK, r = E_SERVER, E_SERVER, "[E_SERVER] HTTP status code is not HTTP_STATUS_OK.");
175 errorMsg = pHttpResponse->GetStatusText();
177 SysTryCatch(NID_CNT, !IsFailed(r), r = E_SERVER, E_SERVER, "[E_SERVER] The server is unavailable.");
179 if (!_AppInfo::IsOspCompat())
181 destPath = pUserData->GetDestPath();
185 if (destPath.StartsWith(Environment::GetMediaPath(), 0) || destPath.StartsWith(Environment::GetExternalStoragePath(), 0))
187 r = RegisterMediaFile(httpSession, httpTransaction, pUserData);
188 SysTryCatch(NID_CNT, !IsFailed(r), r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Failed to perform RegisterMediaFile operation.");
190 DownloadCompleted(httpSession, httpTransaction, pUserData, statusCode, errorMsg, r);
194 DownloadCompleted(httpSession, httpTransaction, pUserData, statusCode, errorMsg, r);
199 if (_FileImpl::IsMediaPath(pUserData->GetDestPath()))
201 r = RegisterMediaFile(httpSession, httpTransaction, pUserData);
202 SysTryCatch(NID_CNT, !IsFailed(r), r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Failed to perform RegisterMediaFile operation.");
204 DownloadCompleted(httpSession, httpTransaction, pUserData, statusCode, errorMsg, r);
208 DownloadCompleted(httpSession, httpTransaction, pUserData, statusCode, errorMsg, r);
215 statusCode = pHttpResponse->GetHttpStatusCode();
216 errorMsg = pHttpResponse->GetStatusText();
218 if (_FileImpl::IsFileExist(pUserData->GetDestPath()))
220 result res = _FileImpl::Remove(pUserData->GetDestPath());
221 SysTryLog(NID_CNT, !IsFailed(res), "[%s] Failed to remove the downloaded file on OnTransactionCompleted.", GetErrorMessage(res));
224 DownloadCompleted(httpSession, httpTransaction, pUserData, statusCode, errorMsg, r);
228 _ContentDownloadListener::OnHttpDownloadInProgress(HttpSession& httpSession, HttpTransaction& httpTransaction,
229 long long currentLength, long long totalLength)
231 SysLog(NID_CNT, "OnHttpDownloadInProgress event fired.");
234 result r = E_SUCCESS;
236 double currentData = 0.0;
237 double totalData = 0.0;
239 _ContentDownloadUserData* pUserData = dynamic_cast<_ContentDownloadUserData*>(httpTransaction.GetUserObject());
240 SysTryReturnVoidResult(NID_CNT, pUserData != null, r = E_SYSTEM,
241 "[E_SYSTEM] ContentDownloadUserData instance must not be null.");
243 count = pUserData->GetDownloadCount();
244 currentData = currentLength;
245 totalData = totalLength;
247 if (totalLength == 0)
250 pUserData->SetDownloadCount(count);
252 if (pUserData->GetDownloadCount() == CONTENT_TRANSFER_COUNTER)
254 TransferProgress(httpSession, httpTransaction, currentLength, totalLength, pUserData);
255 pUserData->SetDownloadCount(0);
261 Double data1(totalData);
262 Double data2(currentData);
263 DoubleComparer comparer;
265 r = comparer.Compare(data1, data2, cmp);
266 SysTryReturnVoidResult(NID_CNT, !IsFailed(r), r,
267 "[%s] Failed to compare total size with current size for a content.", GetErrorMessage(r));
269 if ((pUserData->GetPercent() == INVALID_PROGRESS_INTERVAL)
270 || ((cmp == 0) && (pUserData->GetPrevData() != currentLength))
271 || (((currentData - pUserData->GetPrevData()) / totalData * 100) >= pUserData->GetPercent()))
273 pUserData->SetPrevData(currentLength);
274 pUserData->SetTotalSize(totalLength);
275 TransferProgress(httpSession, httpTransaction, currentLength, totalLength, pUserData);
281 _ContentDownloadListener::OnTransactionCertVerificationRequiredN(HttpSession& httpSession,
282 HttpTransaction& httpTransaction, String* pCert)
284 SysLog(NID_CNT, "OnTransactionCertVerificationRequiredN event fired.");
288 _ContentDownloadListener::OnTransactionHeaderCompleted(HttpSession& httpSession, HttpTransaction& httpTransaction,
289 int headerLen, bool bAuthRequired)
291 SysLog(NID_CNT, "OnTransactionHeaderCompleted event fired.");
295 _ContentDownloadListener::OnTransactionReadyToWrite(HttpSession& httpSession, HttpTransaction& httpTransaction,
296 int recommendedChunkSize)
298 SysLog(NID_CNT, "OnTransactionReadyToWrite event fired.");
302 _ContentDownloadListener::OnHttpUploadInProgress(HttpSession& httpSession, HttpTransaction& httpTransaction,
303 long long currentLength, long long totalLength)
305 SysLog(NID_CNT, "OnHttpUploadInProgress event fired.");
309 _ContentDownloadListener::DownloadCompleted(HttpSession& httpSession, HttpTransaction& httpTransaction,
310 _ContentDownloadUserData* pUserData, int errorCode, String errorMsg, result res)
312 SysLog(NID_CNT, "DownloadCompleted operation start after OnTransactionCompleted event fire.");
315 result r = E_SUCCESS;
316 std::unique_ptr<_ContentTransferEventArg> pContentTransferEventArg;
318 RequestId resultRequestId = INVALID_REQUEST_ID;
319 long long fileSize = 0;
320 std::unique_ptr<ByteBuffer> pBuffer;
322 FileAttributes attribute;
323 String destPath(L"");
325 pContentTransferEventArg = std::unique_ptr<_ContentTransferEventArg>(new (std::nothrow) _ContentTransferEventArg());
326 SysTryCatch(NID_CNT, pContentTransferEventArg != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
327 "[E_OUT_OF_MEMORY] Failed to construct ContentTrasnferEventArg.");
329 SysTryCatch(NID_CNT, pUserData != null, r = E_INVALID_STATE, E_INVALID_STATE,
330 "[E_INVALID_STATE] ContentDownloadUserData instance must not be null.");
332 resultRequestId = pUserData->GetRequestId();
333 destPath = pUserData->GetDestPath();
334 contentId = pUserData->GetContentId();
336 pUserData->SetRequestId(INVALID_REQUEST_ID);
338 if (!(pUserData->GetDownloadBufferFlag()))
340 if (pUserData->GetContentId() != UuId::GetInvalidUuId())
342 pUserData->SetContentId(UuId::GetInvalidUuId());
346 contentId = UuId::GetInvalidUuId();
349 pContentTransferEventArg->SetResult(res);
350 pContentTransferEventArg->SetErrorMsg(Integer::ToString(errorCode), errorMsg);
351 pContentTransferEventArg->SetEventType(Content::CONTENT_TRANSFER_EVENT_DOWNLOAD_COMPLETED);
352 pContentTransferEventArg->SetContentId(contentId);
354 // TODO : needs request ID mapping
355 pContentTransferEventArg->SetRequestId(resultRequestId);
357 SysTryCatch(NID_CNT, pUserData->GetContentTransferEvent() != null, r = E_INVALID_STATE, E_INVALID_STATE,
358 "[E_INVALID_STATE] ContentTransferEvent in UserData must not be null.");
360 r = pUserData->GetContentTransferEvent()->Fire(*(pContentTransferEventArg.release()));
361 SysTryCatch(NID_CNT, !IsFailed(r), , r, "[%s] Failed to perform fire operation on ContentTransferEvent.", GetErrorMessage(r));
363 pUserData->SetSlotFlag(false);
365 if (pUserData->GetContentTransferInfo() != null)
367 pUserData->GetContentTransferInfo()->SetDownloadStatus(Content::CONTENT_TRANSFER_STATUS_DOWNLOAD_COMPLETED);
372 pContentTransferEventArg->SetEventType(Content::CONTENT_TRANSFER_EVENT_DOWNLOAD_TO_BUFFER_COMPLETED);
373 pContentTransferEventArg->SetRequestId(resultRequestId);
374 pUserData->SetDownloadBufferFlag(false);
376 r = file.Construct(destPath, L"r");
377 SysTryCatch(NID_CNT, !IsFailed(r), , r, "[E_OUT_OF_MEMORY] Failed to construct File.");
379 r = _FileImpl::GetAttributes(destPath, attribute);
380 SysTryCatch(NID_CNT, !IsFailed(r), , r, "[%s] Failed to perform GetAttributes operation.", GetErrorMessage(r));
382 fileSize = attribute.GetFileSize();
383 SysTryCatch(NID_CNT, fileSize != 0, , r, "[%s] Failed to perform GetFileSize.", GetErrorMessage(r));
385 pBuffer = std::unique_ptr<ByteBuffer>(new (std::nothrow) ByteBuffer());
386 SysTryCatch(NID_CNT, pBuffer != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
387 "[E_OUT_OF_MEMROY] Failed to construct ByteBuffer.");
389 r = pBuffer->Construct(static_cast<int>(fileSize));
390 SysTryCatch(NID_CNT, !IsFailed(r), , r, "[E_OUT_OF_MEMORY] Failed to construct ByteBuffer.");
392 r = file.Read(*(pBuffer.get()));
393 SysTryCatch(NID_CNT, !IsFailed(r), , r, "[%s] Failed to perform Read operation from File to ByteBuffer.", GetErrorMessage(r));
395 r = pBuffer->SetPosition(fileSize);
396 SysTryCatch(NID_CNT, !IsFailed(r), , r, "[%s] Failed to perform SetPosition operation.", GetErrorMessage(r));
398 r = file.Remove(destPath);
399 SysTryCatch(NID_CNT, !IsFailed(r), , r, "[%s] Failed to perform Remove operation for download file.", GetErrorMessage(r));
402 pContentTransferEventArg->SetBuffer(pBuffer.release());
403 pContentTransferEventArg->SetResult(res);
404 pContentTransferEventArg->SetErrorMsg(Integer::ToString(errorCode), errorMsg);
406 SysTryCatch(NID_CNT, pUserData->GetContentTransferEvent() != null, r = E_INVALID_STATE, E_INVALID_STATE,
407 "[E_INVALID_STATE] ContentTransferEvent in UserData must not be null.");
409 r = pUserData->GetContentTransferEvent()->Fire(*(pContentTransferEventArg.release()));
410 SysTryCatch(NID_CNT, !IsFailed(r), , r,
411 "[%s] Failed to perform fire operation on ContentTransferEvent.", GetErrorMessage(r));
413 pUserData->SetSlotFlag(false);
415 if (pUserData->GetContentTransferInfo() != null)
417 pUserData->GetContentTransferInfo()->SetDownloadStatus(Content::CONTENT_TRANSFER_STATUS_DOWNLOAD_COMPLETED);
424 _ContentManagerImpl contentManager;
426 r = contentManager.Construct();
427 SysTryLog(NID_CNT, !IsFailed(r), "[%s] Failed to construct ContentManager.", GetErrorMessage(r));
429 r = contentManager.DeleteContent(contentId);
430 SysTryLog(NID_CNT, !IsFailed(r), "[%s] Failed to perform DeleteContent operation.", GetErrorMessage(r));
432 if (pContentTransferEventArg)
434 pContentTransferEventArg->SetResult(r);
435 pContentTransferEventArg->SetErrorMsg(Integer::ToString(errorCode), errorMsg);
437 r = pUserData->GetContentTransferEvent()->Fire(*(pContentTransferEventArg.release()));
438 SysTryLog(NID_CNT, !IsFailed(r), "[%s] Failed to perform fire operation on ContentTransferEvent.", GetErrorMessage(r));
440 pUserData->SetSlotFlag(false);
443 if (_FileImpl::IsFileExist(destPath))
445 r = file.Remove(destPath);
446 SysTryLog(NID_CNT, !IsFailed(r), "[%s] Failed to perform Remove operation for download file.", GetErrorMessage(r));
449 if (pUserData->GetContentTransferInfo() != null)
451 pUserData->GetContentTransferInfo()->SetDownloadStatus(Content::CONTENT_TRANSFER_STATUS_DOWNLOAD_COMPLETED);
458 _ContentDownloadListener::RegisterMediaFile(HttpSession& httpSession, HttpTransaction& httpTransaction,
459 _ContentDownloadUserData* pUserData)
462 result r = E_SUCCESS;
464 _ContentManagerImpl contentManager;
465 ContentType contentType = CONTENT_TYPE_UNKNOWN;
466 ImageContentInfo imageContentInfo;
467 AudioContentInfo audioContentInfo;
468 VideoContentInfo videoContentInfo;
469 OtherContentInfo otherContentInfo;
470 String contentPath(L"");
472 SysTryReturnResult(NID_CNT, pUserData != null, r = E_INVALID_STATE,
473 "ContentDownloadUserData instance must not be null.");
475 contentPath = pUserData->GetDestPath();
477 contentType = Content::_ContentManagerUtilImpl::CheckContentType(pUserData->GetDestPath());
479 SysTryReturnResult(NID_CNT, r == E_SUCCESS || r == E_UNSUPPORTED_FORMAT, r,
480 "Failed to perform CheckContentType for [%ls].", (pUserData->GetDestPath()).GetPointer());
482 r = contentManager.Construct();
483 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to construct ContentManager.");
485 if (contentType == CONTENT_TYPE_IMAGE)
487 SysLog(NID_CNT, "Register the image type to database.");
488 r = imageContentInfo.Construct(&contentPath);
489 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to construct ImageContentInfo.");
491 contentId = contentManager.CreateContent(imageContentInfo);
492 SysTryReturnResult(NID_CNT, contentId != UuId::GetInvalidUuId(), GetLastResult(),
493 "Failed to perform CreateContent operation for image type.");
495 else if (contentType == CONTENT_TYPE_AUDIO)
497 SysLog(NID_CNT, "Register the audio type to database.");
498 r = audioContentInfo.Construct(&contentPath);
499 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to construct AudioContentInfo.");
501 contentId = contentManager.CreateContent(audioContentInfo);
502 SysTryReturnResult(NID_CNT, contentId != UuId::GetInvalidUuId(), GetLastResult(),
503 "Failed to perform CreateContent operation for audio type.");
505 else if (contentType == CONTENT_TYPE_VIDEO)
507 SysLog(NID_CNT, "Register the video type to database.");
508 r = videoContentInfo.Construct(&contentPath);
509 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to construct VideoContentInfo.");
511 contentId = contentManager.CreateContent(videoContentInfo);
512 SysTryReturnResult(NID_CNT, contentId != UuId::GetInvalidUuId(), GetLastResult(),
513 "Failed to perform CreateContent operation for video type.");
515 else if (contentType == CONTENT_TYPE_OTHER || contentType == CONTENT_TYPE_UNKNOWN)
517 SysLog(NID_CNT, "Register the other type to database.");
518 r = otherContentInfo.Construct(&contentPath);
519 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to construct OtherContentInfo.");
521 contentId = contentManager.CreateContent(otherContentInfo);
522 SysTryReturnResult(NID_CNT, contentId != UuId::GetInvalidUuId(), GetLastResult(),
523 "Failed to construct CreateContent operation for other type.");
527 SysLogException(NID_CNT, r = E_SYSTEM, "[%s]contentType is CONTENT_TYPE_UNKNOWN.", GetErrorMessage(E_SYSTEM));
532 pUserData->SetContentId(contentId);
538 _ContentDownloadListener::DownloadCanceled(_ContentDownloadUserData* pUserData, int statusCode, String errorMsg, result res)
540 SysLog(NID_CNT, "Cancel the download operation with status code(%d).", statusCode);
543 result r = E_SUCCESS;
544 std::unique_ptr<_ContentTransferEventArg> pTransferEventArg(new (std::nothrow) _ContentTransferEventArg);
545 SysTryReturnVoidResult(NID_CNT, pTransferEventArg != null, E_OUT_OF_MEMORY,
546 "[E_OUT_OF_MEMORY] pTransferEventArg construct failed.");
548 SysTryReturnVoidResult(NID_CNT, pUserData != null, r = E_INVALID_STATE,
549 "[E_INVALID_STATE] ContentDownloadUserData instance must not be null.");
551 pTransferEventArg->SetEventType(Content::CONTENT_TRANSFER_EVENT_CANCELED);
552 pTransferEventArg->SetRequestId(pUserData->GetRequestId());
553 pTransferEventArg->SetResult(res);
554 pTransferEventArg->SetErrorMsg(Integer::ToString(statusCode), errorMsg);
556 SysTryReturnVoidResult(NID_CNT, pUserData->GetContentTransferEvent() != null, r = E_INVALID_STATE,
557 "[E_INVALID_STATE] ContentTransferEvent in UserData must not be null.");
559 r = pUserData->GetContentTransferEvent()->Fire(*(pTransferEventArg.release()));
560 SysTryReturnVoidResult(NID_CNT, !IsFailed(r), r,
561 "[%s] Failed to perform fire operation on ContentTransferEvent.", GetErrorMessage(r));
563 if (pUserData->GetDownloadBufferFlag())
565 pUserData->SetDownloadBufferFlag(false);
568 pUserData->SetSlotFlag(false);
570 if (pUserData->GetContentTransferInfo() != null)
572 pUserData->GetContentTransferInfo()->SetDownloadStatus(Content::CONTENT_TRANSFER_STATUS_DOWNLOAD_COMPLETED);
576 SysLogException(NID_CNT, E_INVALID_STATE, "[E_INVALID_STATE] ContentTransferInfo is not exist in UserData.");
581 _ContentDownloadListener::TransferProgress(HttpSession& httpSession, HttpTransaction& httpTransaction,
582 long long currentLength, long long totalLength, _ContentDownloadUserData* pUserData)
585 result r = E_SUCCESS;
586 std::unique_ptr<_ContentTransferEventArg> pTransferEventArg(new (std::nothrow) _ContentTransferEventArg);
587 SysTryReturnVoidResult(NID_CNT, pTransferEventArg != null, r = E_OUT_OF_MEMORY,
588 "[E_OUT_OF_MEMORY] Failed to construct ContentTransferEventArg.");
590 SysTryReturnVoidResult(NID_CNT, pUserData != null, r = E_INVALID_STATE,
591 "[E_INVALID_STATE] ContentDownloadUserData must not be null.");
593 pTransferEventArg->SetEventType(Content::CONTENT_TRANSFER_EVENT_TRANSFER_IN_PROGRESS);
594 pTransferEventArg->SetRequestId(pUserData->GetRequestId());
595 pTransferEventArg->SetTotalTransferedSize(currentLength);
597 SysTryReturnVoidResult(NID_CNT, pUserData->GetContentTransferEvent() != null, r = E_INVALID_STATE,
598 "[E_INVALID_STATE] ContentTransferEvent in UserData must not be null.");
600 r = pUserData->GetContentTransferEvent()->Fire(*(pTransferEventArg.release()));
601 SysTryReturnVoidResult(NID_CNT, !IsFailed(r), r = E_INVALID_STATE,
602 "[E_INVALID_STATE] Failed to perform fire operation on ContentTransferEvent.");