Vectorize website settings icons in omnibox
[chromium-blink-merge.git] / components / copresence / rpc / http_post.h
blob197f7146661318559e15918722b0dea2cd523084
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 using ResponseCallback = base::Callback<void(int, const std::string&)>;
38 // Create a request to the Copresence server.
39 // |url_context_getter| is owned by the caller,
40 // and the context it provides must be available until the request completes.
41 HttpPost(net::URLRequestContextGetter* url_context_getter,
42 const std::string& server_host,
43 // TODO(ckehoe): Condense some of these into a struct.
44 const std::string& rpc_name,
45 std::string api_key, // If blank, we overwrite with a default.
46 const std::string& auth_token,
47 const std::string& tracing_token,
48 const google::protobuf::MessageLite& request_proto);
50 // HTTP requests are cancelled on delete.
51 ~HttpPost() override;
53 // Send an HttpPost request.
54 void Start(const ResponseCallback& response_callback);
56 private:
57 static const int kUrlFetcherId = 1;
58 static const char kApiKeyField[];
59 static const char kTracingField[];
61 friend class HttpPostTest;
63 // Overridden from net::URLFetcherDelegate.
64 void OnURLFetchComplete(const net::URLFetcher* source) override;
66 ResponseCallback response_callback_;
68 scoped_ptr<net::URLFetcher> url_fetcher_;
70 DISALLOW_COPY_AND_ASSIGN(HttpPost);
73 } // namespace copresence
75 #endif // COMPONENTS_COPRESENCE_RPC_HTTP_POST_H_