2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file FCnt_ContentDownloadListener.cpp
19 * @brief This is the implementation file for the %_ContentDownloadListener class.
21 * This file contains implementation of the %_ContentDownloadListener class.
24 #include <unique_ptr.h>
25 #include <FBaseSysLog.h>
26 #include <FIoDirectory.h>
27 #include <FSysEnvironment.h>
28 #include <FCntImageContentInfo.h>
29 #include <FCntVideoContentInfo.h>
30 #include <FCntAudioContentInfo.h>
31 #include <FCntOtherContentInfo.h>
32 #include <FApp_AppInfo.h>
33 #include <FCnt_ContentManagerImpl.h>
34 #include <FCnt_ContentManagerUtilImpl.h>
35 #include <FIo_FileImpl.h>
36 #include "FCnt_ContentDownloadListener.h"
38 using namespace Tizen;
39 using namespace Tizen::App;
40 using namespace Tizen::Base;
41 using namespace Tizen::Base::Runtime;
42 using namespace Tizen::Io;
43 using namespace Tizen::System;
44 using namespace Tizen::Net;
45 using namespace Tizen::Net::Http;
47 namespace Tizen { namespace Content
50 static const int INVALID_PROGRESS_INTERVAL = -1;
51 static const int CONTENT_TRANSFER_COUNTER = 20;
53 _ContentDownloadListener::_ContentDownloadListener(void)
56 _ContentDownloadListener::~_ContentDownloadListener(void)
61 _ContentDownloadListener::OnTransactionReadyToRead(HttpSession& httpSession,
62 HttpTransaction& httpTransaction, int availableBodyLen)
64 SysLog(NID_CNT, "OnTransactionReadyToRead event fired.");
67 std::unique_ptr<File> pFile;
68 std::unique_ptr<ByteBuffer> pBody;
69 HttpResponse* pHttpResponse = null;
71 _ContentDownloadUserData* pUserData = dynamic_cast<_ContentDownloadUserData*>(httpTransaction.GetUserObject());
72 SysTryReturnVoidResult(NID_CNT, pUserData != null, r = E_SYSTEM,
73 "[E_SYSTEM] ContentDownloadUserData instance must not be null.");
75 SysLog(NID_CNT, "##### Request ID : %d #####", pUserData->GetRequestId());
76 SysLog(NID_CNT, "##### Download path : %ls #####", pUserData->GetDestPath().GetPointer());
77 SysLog(NID_CNT, "##### Download URL : %ls #####", pUserData->GetUrl().GetPointer());
78 SysLog(NID_CNT, "##### Slot number : %d #####", pUserData->GetSlot());
79 SysLog(NID_CNT, "##### Total size : %lld #####", pUserData->GetTotalSize());
80 SysLog(NID_CNT, "##### Prev data size : %lld #####", pUserData->GetPrevData());
82 pHttpResponse = httpTransaction.GetResponse();
84 SysTryReturnVoidResult(NID_CNT, pHttpResponse != null, r, "[%s] Failed to get the HTTP transaction response.", GetErrorMessage(r));
86 if (pHttpResponse->GetHttpStatusCode() != HTTP_STATUS_OK)
88 SysLogException(NID_CNT, E_INVALID_STATE, "[E_INVALID_STATE] HTTP status code is not HTTP_STATUS_OK.");
92 pBody = std::unique_ptr<ByteBuffer>(pHttpResponse->ReadBodyN());
93 SysTryReturnVoidResult(NID_CNT, pBody != null, r = E_OUT_OF_MEMORY,
94 "[E_OUT_OF_MEMORY] Failed to perform ReadBodyN operation to ByteBuffer.");
96 pFile = std::unique_ptr<File>(new (std::nothrow) File);
97 SysTryReturnVoidResult(NID_CNT, pFile != null, r = E_OUT_OF_MEMORY,
98 "[E_OUT_OF_MEMORY] Failed to construct File.");
100 r = pFile->Construct(pUserData->GetDestPath(), L"a+");
101 SysTryReturnVoidResult(NID_CNT, !IsFailed(r), r, "[%s] Failed to construct File.", GetErrorMessage(r));
103 r = pFile->Write(*(pBody.get()));
104 SysTryReturnVoidResult(NID_CNT, !IsFailed(r), r, "[%s] Failed to perform write operation to File.", GetErrorMessage(r));
108 _ContentDownloadListener::OnTransactionAborted(HttpSession& httpSession, HttpTransaction& httpTransaction, result res)
110 SysLog(NID_CNT, "OnTransactionAborted event fired.");
112 HttpResponse* pHttpResponse = null;
113 String errorMsg(L"");
115 result r = E_SUCCESS;
117 SysLog(NID_CNT, "Input result parameter of OnTransactionAborted is [%s]", GetErrorMessage(res));
119 _ContentDownloadUserData* pUserData = dynamic_cast<_ContentDownloadUserData*>(httpTransaction.GetUserObject());
120 SysTryReturnVoidResult(NID_CNT, pUserData != null, r = E_SYSTEM,
121 "[E_SYSTEM] ContentDownloadUserData instance must not be null.");
123 pHttpResponse = httpTransaction.GetResponse();
127 SysLog(NID_CNT, "[%s] Failed to get the HTTP transaction response.", GetErrorMessage(r));
131 statusCode = pHttpResponse->GetHttpStatusCode();
132 SysTryReturnVoidResult(NID_CNT, statusCode == HTTP_STATUS_OK, r = E_INVALID_STATE,
133 "[E_INVALID_STATE] HTTP status code is not HTTP_STATUS_OK.");
135 errorMsg = pHttpResponse->GetStatusText();
137 SysTryReturnVoidResult(NID_CNT, !IsFailed(r), r = E_INVALID_STATE,
138 "[E_INVALID_STATE] The server is unavailable.");
141 // delete downloaded file because of error
142 if (_FileImpl::IsFileExist(pUserData->GetDestPath()))
144 r = _FileImpl::Remove(pUserData->GetDestPath());
145 SysTryReturnVoidResult(NID_CNT, !IsFailed(r), r,
146 "[%s] Failed to remove the downloaded file on OnTransactionAborted.", GetErrorMessage(r));
149 DownloadCanceled(pUserData, statusCode, errorMsg, E_SERVER);
153 _ContentDownloadListener::OnTransactionCompleted(HttpSession& httpSession, HttpTransaction& httpTransaction)
155 SysLog(NID_CNT, "OnTransactionCompleted event fired.");
158 result r = E_SUCCESS;
159 HttpResponse* pHttpResponse = null;
160 String errorMsg(L"");
162 String destPath(L"");
164 _ContentDownloadUserData* pUserData = dynamic_cast<_ContentDownloadUserData*>(httpTransaction.GetUserObject());
165 SysTryReturnVoidResult(NID_CNT, pUserData != null, r = E_SYSTEM,
166 "[E_SYSTEM] ContentDownloadUserData instance must not be null.");
168 pHttpResponse = httpTransaction.GetResponse();
169 SysTryCatch(NID_CNT, pHttpResponse != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Failed to get the HTTP transaction response.");
171 pUserData->SetDownloadCount(0);
173 statusCode = pHttpResponse->GetHttpStatusCode();
174 SysTryCatch(NID_CNT, statusCode == HTTP_STATUS_OK, r = E_SERVER, E_SERVER, "[E_SERVER] HTTP status code is not HTTP_STATUS_OK.");
176 errorMsg = pHttpResponse->GetStatusText();
178 SysTryCatch(NID_CNT, !IsFailed(r), r = E_SERVER, E_SERVER, "[E_SERVER] The server is unavailable.");
180 if (!_AppInfo::IsOspCompat())
182 destPath = pUserData->GetDestPath();
186 if (destPath.StartsWith(Environment::GetMediaPath(), 0) || destPath.StartsWith(Environment::GetExternalStoragePath(), 0))
188 r = RegisterMediaFile(httpSession, httpTransaction, pUserData);
189 SysTryCatch(NID_CNT, !IsFailed(r), r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Failed to perform RegisterMediaFile operation.");
191 DownloadCompleted(httpSession, httpTransaction, pUserData, statusCode, errorMsg, r);
195 DownloadCompleted(httpSession, httpTransaction, pUserData, statusCode, errorMsg, r);
200 if (_FileImpl::IsMediaPath(pUserData->GetDestPath()))
202 r = RegisterMediaFile(httpSession, httpTransaction, pUserData);
203 SysTryCatch(NID_CNT, !IsFailed(r), r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Failed to perform RegisterMediaFile operation.");
205 DownloadCompleted(httpSession, httpTransaction, pUserData, statusCode, errorMsg, r);
209 DownloadCompleted(httpSession, httpTransaction, pUserData, statusCode, errorMsg, r);
216 statusCode = pHttpResponse->GetHttpStatusCode();
217 errorMsg = pHttpResponse->GetStatusText();
219 if (_FileImpl::IsFileExist(pUserData->GetDestPath()))
221 result res = _FileImpl::Remove(pUserData->GetDestPath());
222 SysTryLog(NID_CNT, !IsFailed(res), "[%s] Failed to remove the downloaded file on OnTransactionCompleted.", GetErrorMessage(res));
225 DownloadCompleted(httpSession, httpTransaction, pUserData, statusCode, errorMsg, r);
229 _ContentDownloadListener::OnHttpDownloadInProgress(HttpSession& httpSession, HttpTransaction& httpTransaction,
230 long long currentLength, long long totalLength)
232 SysLog(NID_CNT, "OnHttpDownloadInProgress event fired.");
235 result r = E_SUCCESS;
237 double currentData = 0.0;
238 double totalData = 0.0;
240 _ContentDownloadUserData* pUserData = dynamic_cast<_ContentDownloadUserData*>(httpTransaction.GetUserObject());
241 SysTryReturnVoidResult(NID_CNT, pUserData != null, r = E_SYSTEM,
242 "[E_SYSTEM] ContentDownloadUserData instance must not be null.");
244 count = pUserData->GetDownloadCount();
245 currentData = currentLength;
246 totalData = totalLength;
248 if (totalLength == 0)
251 pUserData->SetDownloadCount(count);
253 if (pUserData->GetDownloadCount() == CONTENT_TRANSFER_COUNTER)
255 TransferProgress(httpSession, httpTransaction, currentLength, totalLength, pUserData);
256 pUserData->SetDownloadCount(0);
262 Double data1(totalData);
263 Double data2(currentData);
264 DoubleComparer comparer;
266 r = comparer.Compare(data1, data2, cmp);
267 SysTryReturnVoidResult(NID_CNT, !IsFailed(r), r,
268 "[%s] Failed to compare total size with current size for a content.", GetErrorMessage(r));
270 if ((pUserData->GetPercent() == INVALID_PROGRESS_INTERVAL)
271 || ((cmp == 0) && (pUserData->GetPrevData() != currentLength))
272 || (((currentData - pUserData->GetPrevData()) / totalData * 100) >= pUserData->GetPercent()))
274 pUserData->SetPrevData(currentLength);
275 pUserData->SetTotalSize(totalLength);
276 TransferProgress(httpSession, httpTransaction, currentLength, totalLength, pUserData);
282 _ContentDownloadListener::OnTransactionCertVerificationRequiredN(HttpSession& httpSession,
283 HttpTransaction& httpTransaction, String* pCert)
285 SysLog(NID_CNT, "OnTransactionCertVerificationRequiredN event fired.");
289 _ContentDownloadListener::OnTransactionHeaderCompleted(HttpSession& httpSession, HttpTransaction& httpTransaction,
290 int headerLen, bool bAuthRequired)
292 SysLog(NID_CNT, "OnTransactionHeaderCompleted event fired.");
296 _ContentDownloadListener::OnTransactionReadyToWrite(HttpSession& httpSession, HttpTransaction& httpTransaction,
297 int recommendedChunkSize)
299 SysLog(NID_CNT, "OnTransactionReadyToWrite event fired.");
303 _ContentDownloadListener::OnHttpUploadInProgress(HttpSession& httpSession, HttpTransaction& httpTransaction,
304 long long currentLength, long long totalLength)
306 SysLog(NID_CNT, "OnHttpUploadInProgress event fired.");
310 _ContentDownloadListener::DownloadCompleted(HttpSession& httpSession, HttpTransaction& httpTransaction,
311 _ContentDownloadUserData* pUserData, int errorCode, String errorMsg, result res)
313 SysLog(NID_CNT, "DownloadCompleted operation start after OnTransactionCompleted event fire.");
316 result r = E_SUCCESS;
317 std::unique_ptr<_ContentTransferEventArg> pContentTransferEventArg;
319 RequestId resultRequestId = INVALID_REQUEST_ID;
320 long long fileSize = 0;
321 std::unique_ptr<ByteBuffer> pBuffer;
323 FileAttributes attribute;
324 String destPath(L"");
326 pContentTransferEventArg = std::unique_ptr<_ContentTransferEventArg>(new (std::nothrow) _ContentTransferEventArg());
327 SysTryCatch(NID_CNT, pContentTransferEventArg != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
328 "[E_OUT_OF_MEMORY] Failed to construct ContentTrasnferEventArg.");
330 SysTryCatch(NID_CNT, pUserData != null, r = E_INVALID_STATE, E_INVALID_STATE,
331 "[E_INVALID_STATE] ContentDownloadUserData instance must not be null.");
333 resultRequestId = pUserData->GetRequestId();
334 destPath = pUserData->GetDestPath();
335 contentId = pUserData->GetContentId();
337 pUserData->SetRequestId(INVALID_REQUEST_ID);
339 if (!(pUserData->GetDownloadBufferFlag()))
341 if (pUserData->GetContentId() != UuId::GetInvalidUuId())
343 pUserData->SetContentId(UuId::GetInvalidUuId());
347 contentId = UuId::GetInvalidUuId();
350 pContentTransferEventArg->SetResult(res);
351 pContentTransferEventArg->SetErrorMsg(Integer::ToString(errorCode), errorMsg);
352 pContentTransferEventArg->SetEventType(Content::CONTENT_TRANSFER_EVENT_DOWNLOAD_COMPLETED);
353 pContentTransferEventArg->SetContentId(contentId);
355 // TODO : needs request ID mapping
356 pContentTransferEventArg->SetRequestId(resultRequestId);
358 SysTryCatch(NID_CNT, pUserData->GetContentTransferEvent() != null, r = E_INVALID_STATE, E_INVALID_STATE,
359 "[E_INVALID_STATE] ContentTransferEvent in UserData must not be null.");
361 r = pUserData->GetContentTransferEvent()->Fire(*(pContentTransferEventArg.release()));
362 SysTryCatch(NID_CNT, !IsFailed(r), , r, "[%s] Failed to perform fire operation on ContentTransferEvent.", GetErrorMessage(r));
364 pUserData->SetSlotFlag(false);
366 if (pUserData->GetContentTransferInfo() != null)
368 pUserData->GetContentTransferInfo()->SetDownloadStatus(Content::CONTENT_TRANSFER_STATUS_DOWNLOAD_COMPLETED);
373 pContentTransferEventArg->SetEventType(Content::CONTENT_TRANSFER_EVENT_DOWNLOAD_TO_BUFFER_COMPLETED);
374 pContentTransferEventArg->SetRequestId(resultRequestId);
375 pUserData->SetDownloadBufferFlag(false);
377 r = file.Construct(destPath, L"r");
378 SysTryCatch(NID_CNT, !IsFailed(r), , r, "[E_OUT_OF_MEMORY] Failed to construct File.");
380 r = _FileImpl::GetAttributes(destPath, attribute);
381 SysTryCatch(NID_CNT, !IsFailed(r), , r, "[%s] Failed to perform GetAttributes operation.", GetErrorMessage(r));
383 fileSize = attribute.GetFileSize();
384 SysTryCatch(NID_CNT, fileSize != 0, , r, "[%s] Failed to perform GetFileSize.", GetErrorMessage(r));
386 pBuffer = std::unique_ptr<ByteBuffer>(new (std::nothrow) ByteBuffer());
387 SysTryCatch(NID_CNT, pBuffer != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
388 "[E_OUT_OF_MEMROY] Failed to construct ByteBuffer.");
390 r = pBuffer->Construct(static_cast<int>(fileSize));
391 SysTryCatch(NID_CNT, !IsFailed(r), , r, "[E_OUT_OF_MEMORY] Failed to construct ByteBuffer.");
393 r = file.Read(*(pBuffer.get()));
394 SysTryCatch(NID_CNT, !IsFailed(r), , r, "[%s] Failed to perform Read operation from File to ByteBuffer.", GetErrorMessage(r));
396 r = pBuffer->SetPosition(fileSize);
397 SysTryCatch(NID_CNT, !IsFailed(r), , r, "[%s] Failed to perform SetPosition operation.", GetErrorMessage(r));
399 r = file.Remove(destPath);
400 SysTryCatch(NID_CNT, !IsFailed(r), , r, "[%s] Failed to perform Remove operation for download file.", GetErrorMessage(r));
403 pContentTransferEventArg->SetBuffer(pBuffer.release());
404 pContentTransferEventArg->SetResult(res);
405 pContentTransferEventArg->SetErrorMsg(Integer::ToString(errorCode), errorMsg);
407 SysTryCatch(NID_CNT, pUserData->GetContentTransferEvent() != null, r = E_INVALID_STATE, E_INVALID_STATE,
408 "[E_INVALID_STATE] ContentTransferEvent in UserData must not be null.");
410 r = pUserData->GetContentTransferEvent()->Fire(*(pContentTransferEventArg.release()));
411 SysTryCatch(NID_CNT, !IsFailed(r), , r,
412 "[%s] Failed to perform fire operation on ContentTransferEvent.", GetErrorMessage(r));
414 pUserData->SetSlotFlag(false);
416 if (pUserData->GetContentTransferInfo() != null)
418 pUserData->GetContentTransferInfo()->SetDownloadStatus(Content::CONTENT_TRANSFER_STATUS_DOWNLOAD_COMPLETED);
425 _ContentManagerImpl contentManager;
427 r = contentManager.Construct();
428 SysTryLog(NID_CNT, !IsFailed(r), "[%s] Failed to construct ContentManager.", GetErrorMessage(r));
430 r = contentManager.DeleteContent(contentId);
431 SysTryLog(NID_CNT, !IsFailed(r), "[%s] Failed to perform DeleteContent operation.", GetErrorMessage(r));
433 if (pContentTransferEventArg)
435 pContentTransferEventArg->SetResult(r);
436 pContentTransferEventArg->SetErrorMsg(Integer::ToString(errorCode), errorMsg);
438 r = pUserData->GetContentTransferEvent()->Fire(*(pContentTransferEventArg.release()));
439 SysTryLog(NID_CNT, !IsFailed(r), "[%s] Failed to perform fire operation on ContentTransferEvent.", GetErrorMessage(r));
441 pUserData->SetSlotFlag(false);
444 if (_FileImpl::IsFileExist(destPath))
446 r = file.Remove(destPath);
447 SysTryLog(NID_CNT, !IsFailed(r), "[%s] Failed to perform Remove operation for download file.", GetErrorMessage(r));
450 if (pUserData->GetContentTransferInfo() != null)
452 pUserData->GetContentTransferInfo()->SetDownloadStatus(Content::CONTENT_TRANSFER_STATUS_DOWNLOAD_COMPLETED);
459 _ContentDownloadListener::RegisterMediaFile(HttpSession& httpSession, HttpTransaction& httpTransaction,
460 _ContentDownloadUserData* pUserData)
463 result r = E_SUCCESS;
465 _ContentManagerImpl contentManager;
466 ContentType contentType = CONTENT_TYPE_UNKNOWN;
467 ImageContentInfo imageContentInfo;
468 AudioContentInfo audioContentInfo;
469 VideoContentInfo videoContentInfo;
470 OtherContentInfo otherContentInfo;
471 String contentPath(L"");
473 SysTryReturnResult(NID_CNT, pUserData != null, r = E_INVALID_STATE,
474 "ContentDownloadUserData instance must not be null.");
476 contentPath = pUserData->GetDestPath();
478 contentType = Content::_ContentManagerUtilImpl::CheckContentType(pUserData->GetDestPath());
480 SysTryReturnResult(NID_CNT, r == E_SUCCESS || r == E_UNSUPPORTED_FORMAT, r,
481 "Failed to perform CheckContentType for [%ls].", (pUserData->GetDestPath()).GetPointer());
483 r = contentManager.Construct();
484 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to construct ContentManager.");
486 if (contentType == CONTENT_TYPE_IMAGE)
488 SysLog(NID_CNT, "Register the image type to database.");
489 r = imageContentInfo.Construct(&contentPath);
490 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to construct ImageContentInfo.");
492 contentId = contentManager.CreateContent(imageContentInfo);
493 SysTryReturnResult(NID_CNT, contentId != UuId::GetInvalidUuId(), GetLastResult(),
494 "Failed to perform CreateContent operation for image type.");
496 else if (contentType == CONTENT_TYPE_AUDIO)
498 SysLog(NID_CNT, "Register the audio type to database.");
499 r = audioContentInfo.Construct(&contentPath);
500 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to construct AudioContentInfo.");
502 contentId = contentManager.CreateContent(audioContentInfo);
503 SysTryReturnResult(NID_CNT, contentId != UuId::GetInvalidUuId(), GetLastResult(),
504 "Failed to perform CreateContent operation for audio type.");
506 else if (contentType == CONTENT_TYPE_VIDEO)
508 SysLog(NID_CNT, "Register the video type to database.");
509 r = videoContentInfo.Construct(&contentPath);
510 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to construct VideoContentInfo.");
512 contentId = contentManager.CreateContent(videoContentInfo);
513 SysTryReturnResult(NID_CNT, contentId != UuId::GetInvalidUuId(), GetLastResult(),
514 "Failed to perform CreateContent operation for video type.");
516 else if (contentType == CONTENT_TYPE_OTHER || contentType == CONTENT_TYPE_UNKNOWN)
518 SysLog(NID_CNT, "Register the other type to database.");
519 r = otherContentInfo.Construct(&contentPath);
520 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to construct OtherContentInfo.");
522 contentId = contentManager.CreateContent(otherContentInfo);
523 SysTryReturnResult(NID_CNT, contentId != UuId::GetInvalidUuId(), GetLastResult(),
524 "Failed to construct CreateContent operation for other type.");
529 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "contentType is CONTENT_TYPE_UNKNOWN.");
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.");