OLD | NEW |
| (Empty) |
1 // Copyright 2009-2010 Google Inc. | |
2 // | |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 // you may not use this file except in compliance with the License. | |
5 // You may obtain a copy of the License at | |
6 // | |
7 // http://www.apache.org/licenses/LICENSE-2.0 | |
8 // | |
9 // Unless required by applicable law or agreed to in writing, software | |
10 // distributed under the License is distributed on an "AS IS" BASIS, | |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 // See the License for the specific language governing permissions and | |
13 // limitations under the License. | |
14 // ======================================================================== | |
15 | |
16 #ifndef OMAHA_COMMON_WEB_SERVICES_CLIENT_H_ | |
17 #define OMAHA_COMMON_WEB_SERVICES_CLIENT_H_ | |
18 | |
19 #include <windows.h> | |
20 #include <atlstr.h> | |
21 #include <utility> | |
22 #include <vector> | |
23 #include "base/basictypes.h" | |
24 #include "base/scoped_ptr.h" | |
25 #include "omaha/net/proxy_auth.h" | |
26 | |
27 namespace omaha { | |
28 | |
29 namespace xml { | |
30 | |
31 class UpdateRequest; | |
32 class UpdateResponse; | |
33 | |
34 } // namespace xml | |
35 | |
36 struct Lockable; | |
37 class NetworkRequest; | |
38 | |
39 typedef std::vector<std::pair<CString, CString> > HeadersVector; | |
40 | |
41 class WebServicesClientInterface { | |
42 public: | |
43 virtual ~WebServicesClientInterface() {} | |
44 | |
45 virtual HRESULT Send(const xml::UpdateRequest* update_request, | |
46 xml::UpdateResponse* update_response) = 0; | |
47 | |
48 virtual HRESULT SendString(const CString* request_buffer, | |
49 xml::UpdateResponse* response_buffer) = 0; | |
50 | |
51 virtual void Cancel() = 0; | |
52 | |
53 virtual void set_proxy_auth_config(const ProxyAuthConfig& config) = 0; | |
54 | |
55 // Returns true if the http transaction completed with 200 OK. | |
56 virtual bool is_http_success() const = 0; | |
57 | |
58 // Returns the last http request status code. | |
59 virtual int http_status_code() const = 0; | |
60 | |
61 // Returns http request trace (for logging). | |
62 virtual CString http_trace() const = 0; | |
63 }; | |
64 | |
65 // Defines a class to send and receive protocol requests. | |
66 class WebServicesClient : public WebServicesClientInterface { | |
67 public: | |
68 explicit WebServicesClient(bool is_machine); | |
69 virtual ~WebServicesClient(); | |
70 | |
71 HRESULT Initialize(const CString& url, | |
72 const HeadersVector& headers, | |
73 bool use_cup); | |
74 | |
75 virtual HRESULT Send(const xml::UpdateRequest* update_request, | |
76 xml::UpdateResponse* update_response); | |
77 | |
78 virtual HRESULT SendString(const CString* request_buffer, | |
79 xml::UpdateResponse* update_response); | |
80 | |
81 virtual void Cancel(); | |
82 | |
83 virtual void set_proxy_auth_config(const ProxyAuthConfig& proxy_auth_config); | |
84 | |
85 virtual bool is_http_success() const; | |
86 | |
87 virtual int http_status_code() const; | |
88 | |
89 virtual CString http_trace() const; | |
90 | |
91 private: | |
92 HRESULT SendStringPreserveProtocol(bool need_preserve_https, | |
93 const CString* request_buffer, | |
94 xml::UpdateResponse* update_response); | |
95 | |
96 const Lockable& lock() const; | |
97 | |
98 CString url() const; | |
99 | |
100 NetworkRequest* network_request(); | |
101 | |
102 mutable Lockable* volatile lock_; // Owned by this instance. | |
103 | |
104 const bool is_machine_; | |
105 CString url_; | |
106 | |
107 scoped_ptr<NetworkRequest> network_request_; | |
108 | |
109 friend class WebServicesClientTest; | |
110 DISALLOW_EVIL_CONSTRUCTORS(WebServicesClient); | |
111 }; | |
112 | |
113 } // namespace omaha | |
114 | |
115 #endif // OMAHA_COMMON_WEB_SERVICES_CLIENT_H_ | |
OLD | NEW |