Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(220)

Unified Diff: components/copresence/rpc/http_post.h

Issue 433283002: Adding the Copresence RpcHandler and HttpPost helper. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@directive-handler
Patch Set: Rebasing off the correct CL Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..05f8e3be58839176b21bd259a3457cb6bcbee696
--- /dev/null
+++ b/components/copresence/rpc/http_post.h
@@ -0,0 +1,66 @@
+// 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.
Daniel Erat 2014/08/06 00:44:47 use c++-style comments (//)
Charlie 2014/08/06 19:32:18 Done. Is this in the style guide? I suppose Chromi
+ * 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.
+ */
+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;
+
+ HttpPost(net::URLRequestContextGetter* url_context_getter,
Daniel Erat 2014/08/06 00:44:47 document whether the ownership of this argument is
Charlie 2014/08/06 19:32:18 Done.
+ const std::string& rpc_name,
+ const scoped_ptr<google::protobuf::MessageLite> request_proto,
Daniel Erat 2014/08/06 00:44:47 const reference instead of const scoped_ptr?
Charlie 2014/08/06 19:32:18 Done.
+ 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_

Powered by Google App Engine
This is Rietveld 408576698