Chromium Code Reviews| Index: components/copresence/rpc/http_post.h |
| diff --git a/components/copresence/rpc/http_post.h b/components/copresence/rpc/http_post.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3ec6036006ceea121722390161266717ae378dde |
| --- /dev/null |
| +++ b/components/copresence/rpc/http_post.h |
| @@ -0,0 +1,68 @@ |
| +// Copyright 2014 The Chromium 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 COMPONENTS_COPRESENCE_RPC_HTTP_POST_H_ |
| +#define COMPONENTS_COPRESENCE_RPC_HTTP_POST_H_ |
| + |
| +#include <string> |
| + |
| +#include "base/callback.h" |
| +#include "base/macros.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "net/url_request/url_fetcher_delegate.h" |
| + |
| +namespace google { |
| +namespace protobuf { |
| +class MessageLite; |
| +} |
| +} |
| + |
| +namespace net { |
| +class URLRequestContextGetter; |
| +} |
| + |
| +namespace copresence { |
| + |
| +// This class handles all Apiary calls to the Copresence server. |
| +// It configures the HTTP request appropriately and reports any errors. |
| +// Clients should not attempt to delete this class, as it needs to |
| +// persist until the HTTP request completes (or times out). |
| +// |
| +// TODO(ckehoe): Add retry logic. |
| +// TODO(ckehoe): Template this class to parse the proto received. |
|
Daniel Erat
2014/08/06 21:35:18
it'd probably be better to avoid templates if poss
Charlie
2014/08/06 22:36:23
Can you clarify the cost of moving the implementat
Daniel Erat
2014/08/06 22:45:08
- bigger binaries since the implementation is bein
Charlie
2014/08/06 23:30:25
Makes sense. You mean the implementation is duplic
|
| +class HttpPost : public net::URLFetcherDelegate, |
| + public base::SupportsWeakPtr<HttpPost> { |
| + public: |
| + // Callback to receive the HTTP status code and body of the response (if any). |
| + typedef base::Callback<void(int, const std::string&)> ResponseCallback; |
| + |
| + // An id for testing url fetching. |
| + static const int kUrlFetcherId = 1; |
| + |
| + // Send a request to the Copresence server. After calling the callback, this |
| + // object will delete itself. |url_context_getter| is owned by the caller, |
| + // and must be valid until the request is actually sent (on the IO thread). |
| + HttpPost(net::URLRequestContextGetter* url_context_getter, |
| + const std::string& server_host, |
| + const std::string& rpc_name, |
| + const google::protobuf::MessageLite& request_proto, |
| + const ResponseCallback& response_callback); |
| + |
| + private: |
| + // This class deletes itself when the request completes (or times out). |
| + virtual ~HttpPost(); |
| + |
| + // Overridden from net::URLFetcherDelegate. |
| + virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| + |
| + ResponseCallback response_callback_; |
| + scoped_ptr<net::URLFetcher> url_fetcher_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(HttpPost); |
| +}; |
| + |
| +} // namespace copresence |
| + |
| +#endif // COMPONENTS_COPRESENCE_RPC_HTTP_POST_H_ |