Fix : Search APIs don't return exception despite the content in DB doesn't match...
[platform/framework/native/content.git] / src / FCntDownloadManager.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
15 //
16
17 /**
18  * @file        FCntDownloadManager.cpp
19  * @brief       This is the implementation file for the DownloadManager class.
20  *
21  */
22
23 #include <FBaseSysLog.h>
24 #include <FSec_AccessController.h>
25 #include <FCntDownloadManager.h>
26 #include <FCntDownloadRequest.h>
27 #include <FCntIDownloadListener.h>
28
29 #include "FCnt_DownloadManagerImpl.h"
30
31 using namespace Tizen::Base;
32 using namespace Tizen::Base::Collection;
33 using namespace Tizen::Security;
34
35 namespace Tizen { namespace Content
36 {
37
38 DownloadManager::DownloadManager(void)
39         : __pDownloadManagerImpl(null)
40 {
41 }
42
43 DownloadManager::~DownloadManager(void)
44 {
45         delete __pDownloadManagerImpl;
46 }
47
48 DownloadManager*
49 DownloadManager::GetInstance(void)
50 {
51         static DownloadManager* pManager = null;
52
53         if (pManager == null)
54         {
55                 pManager = new (std::nothrow) DownloadManager;
56                 SysTryReturn(NID_CNT, pManager != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
57
58                 _DownloadManagerImpl* pImpl = _DownloadManagerImpl::GetInstance();
59                 SysTryCatch(NID_CNT, pImpl != null, , E_SYSTEM, "[E_SYSTEM] Failed to initialize download manager.");
60
61                 pManager->__pDownloadManagerImpl = pImpl;
62         }
63
64         return pManager;
65
66 CATCH:
67         delete pManager;
68         pManager = null;
69
70         return null;
71 }
72
73 result
74 DownloadManager::Start(const DownloadRequest& request, RequestId& reqId)
75 {
76         SysAssertf(__pDownloadManagerImpl != null, "Not yet constructed. Construct() should be called before use.\n");
77
78         result r = _AccessController::CheckUserPrivilege(_PRV_DOWNLOAD);
79         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
80         SysTryReturnResult(NID_CNT, r == E_SUCCESS, r,
81                         "The application is not permitted to call this method.");
82
83         return __pDownloadManagerImpl->Start(request, reqId);
84 }
85
86
87 result
88 DownloadManager::Pause(RequestId reqId)
89 {
90         SysAssertf(__pDownloadManagerImpl != null, "Not yet constructed. Construct() should be called before use.\n");
91
92         return __pDownloadManagerImpl->Pause(reqId);
93 }
94
95 result
96 DownloadManager::Resume(RequestId reqId)
97 {
98         SysAssertf(__pDownloadManagerImpl != null, "Not yet constructed. Construct() should be called before use.\n");
99
100         return __pDownloadManagerImpl->Resume(reqId);
101 }
102
103 result
104 DownloadManager::Cancel(RequestId reqId)
105 {
106         SysAssertf(__pDownloadManagerImpl != null, "Not yet constructed. Construct() should be called before use.\n");
107
108         return __pDownloadManagerImpl->Cancel(reqId);
109 }
110
111
112 DownloadRequest*
113 DownloadManager::GetDownloadRequestN(RequestId reqId) const
114 {
115         SysAssertf(__pDownloadManagerImpl != null, "Not yet constructed. Construct() should be called before use.\n");
116
117         return __pDownloadManagerImpl->GetDownloadRequestN(reqId);
118 }
119
120 DownloadState
121 DownloadManager::GetState(RequestId reqId) const
122 {
123         SysAssertf(__pDownloadManagerImpl != null, "Not yet constructed. Construct() should be called before use.\n");
124
125         return (DownloadState)__pDownloadManagerImpl->GetState(reqId);
126 }
127
128 result
129 DownloadManager::GetMimeType(RequestId reqId, String& mimeType) const
130 {
131         SysAssertf(__pDownloadManagerImpl != null, "Not yet constructed. Construct() should be called before use.\n");
132
133         return __pDownloadManagerImpl->GetMimeType(reqId, mimeType);
134 }
135
136 /*
137 result
138 DownloadManager::SetAllowedNetwork(unsigned long flags)
139 {
140         SysAssertf(__pDownloadManagerImpl != null, "Not yet constructed. Construct() should be called before use.\n");
141
142         return __pDownloadManagerImpl->SetAllowedNetwork(flags);
143 }
144
145 result
146 DownloadManager::GetProgress(RequestId reqId, int& progress) const
147 {
148         SysAssertf(__pDownloadManagerImpl != null, "Not yet constructed. Construct() should be called before use.\n");
149
150         return __pDownloadManagerImpl->GetProgress(reqId, progress);
151 }
152 */
153
154 void
155 DownloadManager::SetDownloadListener(IDownloadListener* pListener)
156 {
157         __pDownloadManagerImpl->SetDownloadListener(pListener);
158 }
159
160 } } // Tizen::Content