Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 "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 class HttpPost : public net::URLFetcherDelegate, | |
| 35 public base::SupportsWeakPtr<HttpPost> { | |
|
willchan no longer on Chromium
2014/08/07 20:27:05
Can you explain why this inherits from SupportsWea
Charlie
2014/08/07 22:40:58
You're right, WeakPtr isn't needed. It actually is
| |
| 36 public: | |
| 37 // Callback to receive the HTTP status code and body of the response | |
| 38 // (if any). A pointer to this HttpPost object is also passed along, | |
| 39 // which will be deleted right after the callback completes. | |
| 40 typedef base::Callback<void(int, const std::string&, HttpPost*)> | |
| 41 ResponseCallback; | |
| 42 | |
| 43 // An id for testing url fetching. | |
| 44 static const int kUrlFetcherId = 1; | |
| 45 | |
| 46 // Send a request to the Copresence server. After calling the callback, this | |
| 47 // object will delete itself. |url_context_getter| is owned by the caller, | |
| 48 // and the context it provides must be available until the request completes. | |
| 49 // If this context is being destructed, call Cancel(). | |
| 50 HttpPost(net::URLRequestContextGetter* url_context_getter, | |
| 51 const std::string& server_host, | |
| 52 const std::string& rpc_name, | |
| 53 const google::protobuf::MessageLite& request_proto, | |
| 54 const ResponseCallback& response_callback); | |
| 55 | |
| 56 // Cancels the HTTP request and deletes this object. Call this | |
| 57 // if the URLRequestContext passed into the constructor is going away. | |
| 58 void Cancel(); | |
| 59 | |
| 60 private: | |
| 61 // This class deletes itself when the request completes (or times out). | |
| 62 // To delete it earlier, call Cancel(). | |
| 63 virtual ~HttpPost(); | |
| 64 | |
| 65 // Overridden from net::URLFetcherDelegate. | |
| 66 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | |
| 67 | |
| 68 ResponseCallback response_callback_; | |
| 69 scoped_ptr<net::URLFetcher> url_fetcher_; | |
| 70 | |
| 71 DISALLOW_COPY_AND_ASSIGN(HttpPost); | |
| 72 }; | |
| 73 | |
| 74 } // namespace copresence | |
| 75 | |
| 76 #endif // COMPONENTS_COPRESENCE_RPC_HTTP_POST_H_ | |
| OLD | NEW |