| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/sync/engine/net/server_connection_manager.h" | 5 #include "chrome/browser/sync/engine/net/server_connection_manager.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 | 8 |
| 9 #include <ostream> | 9 #include <ostream> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 } | 128 } |
| 129 // Notify if we've gone on or offline. | 129 // Notify if we've gone on or offline. |
| 130 if (server_reachable_ != conn_mgr_->server_reachable_) | 130 if (server_reachable_ != conn_mgr_->server_reachable_) |
| 131 conn_mgr_->NotifyStatusChanged(); | 131 conn_mgr_->NotifyStatusChanged(); |
| 132 } | 132 } |
| 133 | 133 |
| 134 ServerConnectionManager::ServerConnectionManager( | 134 ServerConnectionManager::ServerConnectionManager( |
| 135 const string& server, | 135 const string& server, |
| 136 int port, | 136 int port, |
| 137 bool use_ssl, | 137 bool use_ssl, |
| 138 const string& user_agent, | 138 const string& user_agent) |
| 139 const string& client_id) | |
| 140 : sync_server_(server), | 139 : sync_server_(server), |
| 141 sync_server_port_(port), | 140 sync_server_port_(port), |
| 142 client_id_(client_id), | |
| 143 user_agent_(user_agent), | 141 user_agent_(user_agent), |
| 144 use_ssl_(use_ssl), | 142 use_ssl_(use_ssl), |
| 145 proto_sync_path_(kSyncServerSyncPath), | 143 proto_sync_path_(kSyncServerSyncPath), |
| 146 get_time_path_(kSyncServerGetTimePath), | 144 get_time_path_(kSyncServerGetTimePath), |
| 147 error_count_(0), | 145 error_count_(0), |
| 148 channel_(new Channel(shutdown_event)), | 146 channel_(new Channel(shutdown_event)), |
| 149 server_status_(HttpResponse::NONE), | 147 server_status_(HttpResponse::NONE), |
| 150 server_reachable_(false), | 148 server_reachable_(false), |
| 151 reset_count_(0), | 149 reset_count_(0), |
| 152 terminate_all_io_(false) { | 150 terminate_all_io_(false) { |
| 153 } | 151 } |
| 154 | 152 |
| 155 ServerConnectionManager::~ServerConnectionManager() { | 153 ServerConnectionManager::~ServerConnectionManager() { |
| 156 delete channel_; | 154 delete channel_; |
| 157 } | 155 } |
| 158 | 156 |
| 159 void ServerConnectionManager::NotifyStatusChanged() { | 157 void ServerConnectionManager::NotifyStatusChanged() { |
| 160 ServerConnectionEvent event = { ServerConnectionEvent::STATUS_CHANGED, | 158 ServerConnectionEvent event = { ServerConnectionEvent::STATUS_CHANGED, |
| 161 server_status_, | 159 server_status_, |
| 162 server_reachable_ }; | 160 server_reachable_ }; |
| 163 channel_->NotifyListeners(event); | 161 channel_->NotifyListeners(event); |
| 164 } | 162 } |
| 165 | 163 |
| 166 // Uses currently set auth token. Set by AuthWatcher. | |
| 167 bool ServerConnectionManager::PostBufferWithCachedAuth( | 164 bool ServerConnectionManager::PostBufferWithCachedAuth( |
| 168 const PostBufferParams* params, ScopedServerStatusWatcher* watcher) { | 165 const PostBufferParams* params, ScopedServerStatusWatcher* watcher) { |
| 169 string path = | 166 string path = |
| 170 MakeSyncServerPath(proto_sync_path(), MakeSyncQueryString(client_id_)); | 167 MakeSyncServerPath(proto_sync_path(), MakeSyncQueryString(client_id_)); |
| 171 return PostBufferToPath(params, path, auth_token(), watcher); | 168 return PostBufferToPath(params, path, auth_token(), watcher); |
| 172 } | 169 } |
| 173 | 170 |
| 174 bool ServerConnectionManager::PostBufferWithAuth(const PostBufferParams* params, | |
| 175 const string& auth_token, ScopedServerStatusWatcher* watcher) { | |
| 176 string path = MakeSyncServerPath(proto_sync_path(), | |
| 177 MakeSyncQueryString(client_id_)); | |
| 178 | |
| 179 return PostBufferToPath(params, path, auth_token, watcher); | |
| 180 } | |
| 181 | |
| 182 bool ServerConnectionManager::PostBufferToPath(const PostBufferParams* params, | 171 bool ServerConnectionManager::PostBufferToPath(const PostBufferParams* params, |
| 183 const string& path, const string& auth_token, | 172 const string& path, const string& auth_token, |
| 184 ScopedServerStatusWatcher* watcher) { | 173 ScopedServerStatusWatcher* watcher) { |
| 185 DCHECK(watcher != NULL); | 174 DCHECK(watcher != NULL); |
| 186 scoped_ptr<Post> post(MakePost()); | 175 scoped_ptr<Post> post(MakePost()); |
| 187 post->set_timing_info(params->timing_info); | 176 post->set_timing_info(params->timing_info); |
| 188 bool ok = post->Init(path.c_str(), auth_token, params->buffer_in, | 177 bool ok = post->Init(path.c_str(), auth_token, params->buffer_in, |
| 189 params->response); | 178 params->response); |
| 190 | 179 |
| 191 if (!ok || RC_REQUEST_OK != params->response->response_code) { | 180 if (!ok || RC_REQUEST_OK != params->response->response_code) { |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 | 347 |
| 359 } // namespace browser_sync | 348 } // namespace browser_sync |
| 360 | 349 |
| 361 std::ostream& operator << (std::ostream& s, | 350 std::ostream& operator << (std::ostream& s, |
| 362 const struct browser_sync::HttpResponse& hr) { | 351 const struct browser_sync::HttpResponse& hr) { |
| 363 s << " Response Code (bogus on error): " << hr.response_code; | 352 s << " Response Code (bogus on error): " << hr.response_code; |
| 364 s << " Content-Length (bogus on error): " << hr.content_length; | 353 s << " Content-Length (bogus on error): " << hr.content_length; |
| 365 s << " Server Status: " << hr.server_status; | 354 s << " Server Status: " << hr.server_status; |
| 366 return s; | 355 return s; |
| 367 } | 356 } |
| OLD | NEW |