| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 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 CHROME_BROWSER_SYNC_INTERNAL_API_HTTP_POST_PROVIDER_INTERFACE_H_ | |
| 6 #define CHROME_BROWSER_SYNC_INTERNAL_API_HTTP_POST_PROVIDER_INTERFACE_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <string> | |
| 10 | |
| 11 namespace sync_api { | |
| 12 | |
| 13 // An interface the embedding application (e.g. Chromium) implements to provide | |
| 14 // required HTTP POST functionality to the syncer backend. This interface is | |
| 15 // designed for one-time use. You create one, use it, and create another if you | |
| 16 // want to make a subsequent POST. | |
| 17 class HttpPostProviderInterface { | |
| 18 public: | |
| 19 virtual ~HttpPostProviderInterface() {} | |
| 20 | |
| 21 // Use specified user agent string when POSTing. If not called a default UA | |
| 22 // may be used. | |
| 23 virtual void SetUserAgent(const char* user_agent) = 0; | |
| 24 | |
| 25 // Add additional headers to the request. | |
| 26 virtual void SetExtraRequestHeaders(const char* headers) = 0; | |
| 27 | |
| 28 // Set the URL to POST to. | |
| 29 virtual void SetURL(const char* url, int port) = 0; | |
| 30 | |
| 31 // Set the type, length and content of the POST payload. | |
| 32 // |content_type| is a null-terminated MIME type specifier. | |
| 33 // |content| is a data buffer; Do not interpret as a null-terminated string. | |
| 34 // |content_length| is the total number of chars in |content|. It is used to | |
| 35 // assign/copy |content| data. | |
| 36 virtual void SetPostPayload(const char* content_type, | |
| 37 int content_length, | |
| 38 const char* content) = 0; | |
| 39 | |
| 40 // Returns true if the URL request succeeded. If the request failed, | |
| 41 // error() may be non-zero and hence contain more information. | |
| 42 virtual bool MakeSynchronousPost(int* error_code, int* response_code) = 0; | |
| 43 | |
| 44 // Get the length of the content returned in the HTTP response. | |
| 45 // This does not count the trailing null-terminating character returned | |
| 46 // by GetResponseContent, so it is analogous to calling string.length. | |
| 47 virtual int GetResponseContentLength() const = 0; | |
| 48 | |
| 49 // Get the content returned in the HTTP response. | |
| 50 // This is a null terminated string of characters. | |
| 51 // Value should be copied. | |
| 52 virtual const char* GetResponseContent() const = 0; | |
| 53 | |
| 54 // Get the value of a header returned in the HTTP response. | |
| 55 // If the header is not present, returns the empty string. | |
| 56 virtual const std::string GetResponseHeaderValue( | |
| 57 const std::string& name) const = 0; | |
| 58 | |
| 59 // Abandon any pending POST and unblock caller in MakeSynchronousPost. | |
| 60 // This must be safe to call from any thread. | |
| 61 virtual void Abort() = 0; | |
| 62 }; | |
| 63 | |
| 64 } // namespace sync_api | |
| 65 | |
| 66 #endif // CHROME_BROWSER_SYNC_INTERNAL_API_HTTP_POST_PROVIDER_INTERFACE_H_ | |
| OLD | NEW |