Roll src/third_party/WebKit bf18a82:a9cee16 (svn 185297:185304)
[chromium-blink-merge.git] / components / copresence / rpc / http_post.h
blob777be15dadc75fe52551c043939fbb38d802fe98
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.
5 #ifndef COMPONENTS_COPRESENCE_RPC_HTTP_POST_H_
6 #define COMPONENTS_COPRESENCE_RPC_HTTP_POST_H_
8 #include <string>
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"
15 namespace google {
16 namespace protobuf {
17 class MessageLite;
21 namespace net {
22 class URLRequestContextGetter;
25 namespace copresence {
27 // This class handles all Apiary calls to the Copresence server.
28 // It configures the HTTP request appropriately and reports any errors.
29 // If deleted, the HTTP request is cancelled.
31 // TODO(ckehoe): Add retry logic.
32 class HttpPost : public net::URLFetcherDelegate {
33 public:
34 // Callback to receive the HTTP status code and body of the response
35 // (if any). A pointer to this HttpPost object is also passed along.
36 typedef base::Callback<void(int, const std::string&)>
37 ResponseCallback;
39 // Create a request to the Copresence server.
40 // |url_context_getter| is owned by the caller,
41 // and the context it provides must be available until the request completes.
42 HttpPost(net::URLRequestContextGetter* url_context_getter,
43 const std::string& server_host,
44 // TODO(ckehoe): Condense some of these into a struct.
45 const std::string& rpc_name,
46 std::string api_key, // If blank, we overwrite with a default.
47 const std::string& auth_token,
48 const std::string& tracing_token,
49 const google::protobuf::MessageLite& request_proto);
51 // HTTP requests are cancelled on delete.
52 ~HttpPost() override;
54 // Send an HttpPost request.
55 void Start(const ResponseCallback& response_callback);
57 private:
58 static const int kUrlFetcherId = 1;
59 static const char kApiKeyField[];
60 static const char kTracingField[];
62 friend class HttpPostTest;
64 // Overridden from net::URLFetcherDelegate.
65 void OnURLFetchComplete(const net::URLFetcher* source) override;
67 ResponseCallback response_callback_;
69 scoped_ptr<net::URLFetcher> url_fetcher_;
71 DISALLOW_COPY_AND_ASSIGN(HttpPost);
74 } // namespace copresence
76 #endif // COMPONENTS_COPRESENCE_RPC_HTTP_POST_H_