Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: include/AdblockPlus/IWebRequest.h

Issue 29428650: Issue 5180 - introduce asynchronous web request (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Patch Set: Created May 3, 2017, 2:21 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/AdblockPlus/DefaultWebRequest.h ('k') | include/AdblockPlus/JsEngine.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/AdblockPlus/IWebRequest.h
diff --git a/include/AdblockPlus/WebRequest.h b/include/AdblockPlus/IWebRequest.h
similarity index 75%
copy from include/AdblockPlus/WebRequest.h
copy to include/AdblockPlus/IWebRequest.h
index 9eae7e4e7d36f6ea96559fac9315acaee5a5ffc9..110d25fdebdbdf2530f568ef547a25595da0c5ac 100644
--- a/include/AdblockPlus/WebRequest.h
+++ b/include/AdblockPlus/IWebRequest.h
@@ -15,20 +15,21 @@
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef ADBLOCK_PLUS_WEB_REQUEST_H
-#define ADBLOCK_PLUS_WEB_REQUEST_H
+#ifndef ADBLOCK_PLUS_IWEB_REQUEST_H
+#define ADBLOCK_PLUS_IWEB_REQUEST_H
+#include <cstdint>
+#include <functional>
#include <memory>
-#include <stdint.h>
-#include <string>
#include <vector>
+#include <string>
namespace AdblockPlus
{
/**
* List of HTTP headers.
*/
- typedef std::vector<std::pair<std::string, std::string> > HeaderList;
+ typedef std::vector<std::pair<std::string, std::string>> HeaderList;
/**
* HTTP response.
@@ -66,15 +67,14 @@ namespace AdblockPlus
};
/**
- * Web request interface.
+ * Web request interface used to implement XMLHttpRequest.
*/
- class WebRequest
+ struct IWebRequest
{
- public:
/**
* Possible [Mozilla status codes](https://developer.mozilla.org/en/docs/Table_Of_Errors#Network_Errors).
*/
- enum
+ enum MozillaStatusCode
{
NS_OK = 0,
NS_ERROR_FAILURE = 0x80004005,
@@ -94,21 +94,26 @@ namespace AdblockPlus
NS_ERROR_NOT_INITIALIZED = 0xc1f30001
};
- virtual inline ~WebRequest() {};
+ /**
+ * Callback type invoked when the server response is ready.
+ * The parameter is the server response.
+ */
+ typedef std::function<void(const ServerResponse&)> GetCallback;
+ virtual ~IWebRequest() {};
/**
* Performs a GET request.
* @param url Request URL.
* @param requestHeaders Request headers.
- * @return HTTP response.
+ * @param getCallback to invoke when the server response is ready.
*/
- virtual ServerResponse GET(const std::string& url, const HeaderList& requestHeaders) const = 0;
+ virtual void GET(const std::string& url, const HeaderList& requestHeaders, const GetCallback& getCallback) = 0;
};
/**
- * Shared smart pointer to a `WebRequest` instance.
+ * Unique smart pointer to an instance of `IWebRequest` implementation.
*/
- typedef std::shared_ptr<WebRequest> WebRequestSharedPtr;
+ typedef std::unique_ptr<IWebRequest> WebRequestPtr;
}
#endif
« no previous file with comments | « include/AdblockPlus/DefaultWebRequest.h ('k') | include/AdblockPlus/JsEngine.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld