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 FCntDownloadManager.h
18 * @brief This is the header file for the %DownloadManager class.
20 * This header file contains the declarations of the %DownloadManager class.
22 #ifndef _FCNT_DOWNLOAD_MANAGER_H_
23 #define _FCNT_DOWNLOAD_MANAGER_H_
25 #include <FBaseResult.h>
26 #include <FBaseString.h>
27 #include <FCntTypes.h>
30 namespace Tizen { namespace Content
33 class DownloadRequest;
34 class IDownloadListener;
37 * @class DownloadManager
38 * @brief This class provides methods to handle HTTP downloads.
42 * @final This class is not intended for extension.
44 * The %DownloadManager class provides methods to handle HTTP downloads. A download request consists of a URL and a destination path; of which the URL is mandatory for downloading content. If the destination path is not specified, the content is downloaded to a default download storage that can be obtained with the System::Environment::GetDefaultDownloadPath() method.
45 * This class conducts the download in the background and calls the Start() method that takes care of HTTP connections. @n
46 * The download operation can be:
47 * - Paused by calling the Pause() method
48 * - Resumed by calling the Resume() method
49 * - Cancelled by calling the Cancel() method
50 * Depending on how the download operation is terminated the following methods are called:
51 * - IDownloadListener::OnDownloadCanceled() when the download is cancelled
52 * - IDownloadListener::OnDownloadCompleted() when the download is completed without any errors
53 * - IDownloadListener::OnDownloadFailed() when the download has been stopped because of an error
55 * The following example demonstrates how to use the %DownloadManager class.
60 * #include <FContent.h>
62 * using namespace Tizen::Base;
63 * using namespace Tizen::Content;
64 * using namespace Tizen::App;
67 * : public Tizen::Content::IDownloadListener
70 * result Download(const String& url);
71 * virtual void OnDownloadCanceled(RequestId reqId) {}
72 * virtual void OnDownloadCompleted(RequestId reqId, const Tizen::Base::String& path);
73 * virtual void OnDownloadFailed(RequestId reqId, result r, const Tizen::Base::String& errorCode);
74 * virtual void OnDownloadPaused(RequestId reqId) {}
75 * virtual void OnDownloadInProgress(RequestId reqId, unsigned long long receivedSize, unsigned long long totalSize) {}
80 * MyAppClass::Download(const String& url)
82 * result r = E_SUCCESS;
83 * RequestId reqId = 0;
85 * DownloadRequest request(url);
86 * DownloadManager* pManager = DownloadManager::GetInstance();
88 * pManager->SetDownloadListener(this);
89 * pManager->Start(request, reqId);
95 * MyAppClass::void OnDownloadCompleted(RequestId reqId, const Tizen::Base::String& path)
97 * AppLog("Download is completed.");
101 * MyAppClass::OnDownloadFailed(RequestId reqId, result r, const Tizen::Base::String& errorCode)
103 * AppLog("Download failed.");
109 class _OSP_EXPORT_ DownloadManager
110 : public Tizen::Base::Object
114 * Gets the download manager instance of an application.
118 * @return A pointer to the %DownloadManager instance, @n
119 * else @c null if it fails
120 * @exception E_SUCCESS The method is successful.
121 * @exception E_SYSTEM The method cannot proceed due to a severe system error.
122 * @remarks The specific error code can be accessed using the GetLastResult() method.
124 static DownloadManager* GetInstance(void);
127 * Starts the download operation. @n
128 * If this operation succeeds, the IDownloadListener::OnDownloadInProgress() method is called. @n
132 * @privilege %http://tizen.org/privilege/download
134 * @return An error code
135 * @param[in] request The download request
136 * @param[out] reqId The request ID
137 * @exception E_SUCCESS The method is successful.
138 * @exception E_INVALID_ARG The information of the download request is invalid.
139 * @exception E_ILLEGAL_ACCESS Access to the path of the download request is denied due to insufficient permission.
140 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
141 * @exception E_USER_NOT_CONSENTED The user blocks an application from calling this method.
142 * @exception E_SYSTEM The method cannot proceed due to a severe system error.
144 result Start(const DownloadRequest& request, RequestId& reqId);
147 * Pauses the download operation of the specified request ID. @n
148 * If this operation succeeds, the IDownloadListener::OnDownloadPaused() method is called.
152 * @return An error code
153 * @param[in] reqId The request ID returned by Start()
154 * @exception E_SUCCESS The method is successful.
155 * @exception E_INVALID_ARG There is no download request for the specified @c reqId.
156 * @exception E_INVALID_OPERATION The current download state prohibits the execution of this operation. @n
157 * The download state of the request ID is not downloading.
158 * @exception E_SYSTEM The method cannot proceed due to a severe system error.
160 result Pause(RequestId reqId);
163 * Resumes the download operation of the specified request ID. @n
164 * If this operation succeeds, the IDownloadListener::OnDownloadInProgress() method is called.
168 * @return An error code
169 * @param[in] reqId The request ID returned by Start()
170 * @exception E_SUCCESS The method is successful.
171 * @exception E_INVALID_ARG There is no download request for the specified @c reqId.
172 * @exception E_INVALID_OPERATION The current download state prohibits the execution of this operation. @n
173 * The download state for the specified request ID is either not paused or has failed.
174 * @exception E_SYSTEM The method cannot proceed due to a severe system error.
176 result Resume(RequestId reqId);
179 * Cancels the download operation of the specified request ID.
183 * @return An error code
184 * @param[in] reqId The request ID returned by Start()
185 * @exception E_SUCCESS The method is successful.
186 * @exception E_INVALID_ARG There is no download request for the specified @c reqId.
187 * @exception E_SYSTEM The method cannot proceed due to a severe system error.
189 result Cancel(RequestId reqId);
192 * Gets the download request information of the specified request ID.
196 * @return The download request
197 * @param[in] reqId The request ID returned by Start()
198 * @exception E_SUCCESS The method is successful.
199 * @exception E_INVALID_ARG There is no download request for the specified @c reqId.
201 * - The specific error code can be accessed using the GetLastResult() method.
202 * - The download request information is available for at least the next 24 hours after IDownloadListener::OnDownloadCompleted() has been called.
204 DownloadRequest* GetDownloadRequestN(RequestId reqId) const;
207 * Gets the download state of the given request ID. @n
208 * If there is no download request for the request ID, @c DOWNLOAD_STATE_NONE is returned.
212 * @return The download state
213 * @param[in] reqId The request ID returned by Start()
214 * @remarks The download state information is available for at least the next 24 hours after IDownloadListener::OnDownloadCompleted() has been called.
216 DownloadState GetState(RequestId reqId) const;
219 * Gets the MIME type of a download request.
223 * @return An error code
224 * @param[in] reqId The request ID returned by Start()
225 * @param[out] mimeType The MIME type
226 * @exception E_SUCCESS The method is successful.
227 * @exception E_INVALID_ARG There is no download request for the specified @c reqId.
228 * @exception E_INVALID_OPERATION The current download state prohibits the execution of this operation. @n
229 * The download operation has not yet started.
230 * @exception E_SYSTEM The method cannot proceed due to a severe system error.
231 * @remarks The MIME type information is available for at least the next 24 hours after IDownloadListener::OnDownloadCompleted() has been called.
233 result GetMimeType(RequestId reqId, Tizen::Base::String& mimeType) const;
236 * Sets a download listener.
240 * @param[in] pListener The download listener @n
241 * If this is @c null, it unsets the download listener.
243 void SetDownloadListener(IDownloadListener* pListener);
247 * This default constructor is intentionally declared as private to implement the Singleton semantic.
249 DownloadManager(void);
252 * This destructor is intentionally declared as private to implement the Singleton semantic.
254 virtual ~DownloadManager(void);
257 * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
259 DownloadManager(const DownloadManager& downloadManager);
262 * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
264 DownloadManager& operator =(const DownloadManager& downloadManager);
266 friend class _DownloadManagerImpl;
267 class _DownloadManagerImpl * __pDownloadManagerImpl;
269 }; // DownloadManager
271 } } // Tizen::Content
273 #endif //_FCNT_DOWNLOAD_MANAGER_H_