aboutsummaryrefslogtreecommitdiffstats
path: root/brillo/http/http_transport.h
diff options
context:
space:
mode:
authorAlex Vakulenko <avakulenko@google.com>2015-10-12 15:21:28 -0700
committerAlex Vakulenko <avakulenko@google.com>2015-10-13 16:10:03 -0700
commit9ed0cab99f18acb3570a35e9408f24355f6b8324 (patch)
tree60e3b4c2822b812b3218489a9a6d835df1e8ca6e /brillo/http/http_transport.h
parenteabfe23a51c91a103042793ac2d5c28170994e1f (diff)
downloadplatform_external_libbrillo-9ed0cab99f18acb3570a35e9408f24355f6b8324.tar.gz
platform_external_libbrillo-9ed0cab99f18acb3570a35e9408f24355f6b8324.tar.bz2
platform_external_libbrillo-9ed0cab99f18acb3570a35e9408f24355f6b8324.zip
Move chromeos symbols into brillo namespace
And move the include files into "brillo" directory instead of "chromeos" BUG: 24872993 TEST=built aosp and brillo and unit tests pass on dragonoboard Change-Id: Ieb979d1ebd3152921d36cd15acbd6247f02aae69
Diffstat (limited to 'brillo/http/http_transport.h')
-rw-r--r--brillo/http/http_transport.h95
1 files changed, 95 insertions, 0 deletions
diff --git a/brillo/http/http_transport.h b/brillo/http/http_transport.h
new file mode 100644
index 0000000..5b56b5c
--- /dev/null
+++ b/brillo/http/http_transport.h
@@ -0,0 +1,95 @@
+// Copyright 2014 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef LIBCHROMEOS_BRILLO_HTTP_HTTP_TRANSPORT_H_
+#define LIBCHROMEOS_BRILLO_HTTP_HTTP_TRANSPORT_H_
+
+#include <memory>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include <base/callback_forward.h>
+#include <base/location.h>
+#include <base/macros.h>
+#include <base/time/time.h>
+#include <brillo/brillo_export.h>
+#include <brillo/errors/error.h>
+
+namespace brillo {
+namespace http {
+
+BRILLO_EXPORT extern const char kErrorDomain[];
+
+class Request;
+class Response;
+class Connection;
+
+using RequestID = int;
+
+using HeaderList = std::vector<std::pair<std::string, std::string>>;
+using SuccessCallback =
+ base::Callback<void(RequestID, std::unique_ptr<Response>)>;
+using ErrorCallback = base::Callback<void(RequestID, const brillo::Error*)>;
+
+///////////////////////////////////////////////////////////////////////////////
+// Transport is a base class for specific implementation of HTTP communication.
+// This class (and its underlying implementation) is used by http::Request and
+// http::Response classes to provide HTTP functionality to the clients.
+///////////////////////////////////////////////////////////////////////////////
+class BRILLO_EXPORT Transport : public std::enable_shared_from_this<Transport> {
+ public:
+ Transport() = default;
+ virtual ~Transport() = default;
+
+ // Creates a connection object and initializes it with the specified data.
+ // |transport| is a shared pointer to this transport object instance,
+ // used to maintain the object alive as long as the connection exists.
+ // The |url| here is the full URL specified in the request. It is passed
+ // to the underlying transport (e.g. CURL) to establish the connection.
+ virtual std::shared_ptr<Connection> CreateConnection(
+ const std::string& url,
+ const std::string& method,
+ const HeaderList& headers,
+ const std::string& user_agent,
+ const std::string& referer,
+ brillo::ErrorPtr* error) = 0;
+
+ // Runs |callback| on the task runner (message loop) associated with the
+ // transport. For transports that do not contain references to real message
+ // loops (e.g. a fake transport), calls the callback immediately.
+ virtual void RunCallbackAsync(const tracked_objects::Location& from_here,
+ const base::Closure& callback) = 0;
+
+ // Initiates an asynchronous transfer on the given |connection|.
+ // The actual implementation of an async I/O is transport-specific.
+ // Returns a request ID which can be used to cancel the request.
+ virtual RequestID StartAsyncTransfer(
+ Connection* connection,
+ const SuccessCallback& success_callback,
+ const ErrorCallback& error_callback) = 0;
+
+ // Cancels a pending asynchronous request. This will cancel a pending request
+ // scheduled by the transport while the I/O operations are still in progress.
+ // As soon as all I/O completes for the request/response, or when an error
+ // occurs, the success/error callbacks are invoked and the request is
+ // considered complete and can no longer be canceled.
+ // Returns false if pending request with |request_id| is not found (e.g. it
+ // has already completed/its callbacks are dispatched).
+ virtual bool CancelRequest(RequestID request_id) = 0;
+
+ // Set the default timeout of requests made.
+ virtual void SetDefaultTimeout(base::TimeDelta timeout) = 0;
+
+ // Creates a default http::Transport (currently, using http::curl::Transport).
+ static std::shared_ptr<Transport> CreateDefault();
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(Transport);
+};
+
+} // namespace http
+} // namespace brillo
+
+#endif // LIBCHROMEOS_BRILLO_HTTP_HTTP_TRANSPORT_H_