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

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: More WeakPtr 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 that can be
3 // 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 "net/url_request/url_fetcher_delegate.h"
14
15 namespace google {
16 namespace protobuf {
17 class MessageLite;
18 }
19 }
20
21 namespace net {
22 class URLRequestContextGetter;
23 }
24
25 namespace copresence {
26
27 // This class handles all Apiary calls to the Copresence server.
28 // It configures the HTTP request appropriately and reports any errors.
29 // Clients should not attempt to delete this class, as it needs to
30 // persist until the HTTP request completes (or times out).
31 //
32 // TODO(ckehoe): Add retry logic.
33 class HttpPost : public net::URLFetcherDelegate {
34 public:
35 // Callback to receive the HTTP status code and body of the response
36 // (if any). A pointer to this HttpPost object is also passed along,
37 // which will be deleted right after the callback completes.
38 typedef base::Callback<void(int, const std::string&, HttpPost*)>
39 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 the context it provides must be available until the request completes.
47 // If this context is being destructed, call Cancel().
48 HttpPost(net::URLRequestContextGetter* url_context_getter,
49 const std::string& server_host,
50 const std::string& rpc_name,
51 const google::protobuf::MessageLite& request_proto,
52 const ResponseCallback& response_callback);
53
54 // Cancels the HTTP request and deletes this object. Call this
55 // if the URLRequestContext passed into the constructor is going away.
56 void Cancel();
57
58 private:
59 // This class deletes itself when the request completes (or times out).
60 // To delete it earlier, call Cancel().
61 virtual ~HttpPost();
62
63 // Overridden from net::URLFetcherDelegate.
64 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
65
66 ResponseCallback response_callback_;
67 scoped_ptr<net::URLFetcher> url_fetcher_;
68
69 DISALLOW_COPY_AND_ASSIGN(HttpPost);
70 };
71
72 } // namespace copresence
73
74 #endif // COMPONENTS_COPRESENCE_RPC_HTTP_POST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698