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

Side by Side 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: First round of review fixes Created 6 years, 4 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license
3 // that can be found in the LICENSE file.
4
5 #ifndef COMPONENTS_COPRESENCE_RPC_HTTP_POST_H_
6 #define COMPONENTS_COPRESENCE_RPC_HTTP_POST_H_
7
8 #include <string>
9
10 #include "base/callback.h"
11 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "net/url_request/url_fetcher_delegate.h"
15
16 namespace google {
17 namespace protobuf {
18 class MessageLite;
19 }
20 }
21
22 namespace net {
23 class URLRequestContextGetter;
24 }
25
26 namespace copresence {
27
28 // This class handles all Apiary calls to the Copresence server.
29 // It configures the HTTP request appropriately and reports any errors.
30 // Clients should not attempt to delete this class, as it needs to
31 // persist until the HTTP request completes (or times out).
32 //
33 // TODO(ckehoe): Add retry logic.
34 // 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
35 class HttpPost : public net::URLFetcherDelegate,
36 public base::SupportsWeakPtr<HttpPost> {
37 public:
38 // Callback to receive the HTTP status code and body of the response (if any).
39 typedef base::Callback<void(int, const std::string&)> ResponseCallback;
40
41 // An id for testing url fetching.
42 static const int kUrlFetcherId = 1;
43
44 // Send a request to the Copresence server. After calling the callback, this
45 // object will delete itself. |url_context_getter| is owned by the caller,
46 // and must be valid until the request is actually sent (on the IO thread).
47 HttpPost(net::URLRequestContextGetter* url_context_getter,
48 const std::string& server_host,
49 const std::string& rpc_name,
50 const google::protobuf::MessageLite& request_proto,
51 const ResponseCallback& response_callback);
52
53 private:
54 // This class deletes itself when the request completes (or times out).
55 virtual ~HttpPost();
56
57 // Overridden from net::URLFetcherDelegate.
58 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
59
60 ResponseCallback response_callback_;
61 scoped_ptr<net::URLFetcher> url_fetcher_;
62
63 DISALLOW_COPY_AND_ASSIGN(HttpPost);
64 };
65
66 } // namespace copresence
67
68 #endif // COMPONENTS_COPRESENCE_RPC_HTTP_POST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698