| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "components/sync/core_impl/syncapi_server_connection_manager.h" | 5 #include "components/sync/engine_impl/net/sync_server_connection_manager.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "components/sync/core/http_post_provider_factory.h" | 9 #include "components/sync/engine/net/http_post_provider_factory.h" |
| 10 #include "components/sync/core/http_post_provider_interface.h" | 10 #include "components/sync/engine/net/http_post_provider_interface.h" |
| 11 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
| 12 #include "net/http/http_status_code.h" | 12 #include "net/http/http_status_code.h" |
| 13 | 13 |
| 14 namespace syncer { | 14 namespace syncer { |
| 15 | 15 |
| 16 SyncAPIBridgedConnection::SyncAPIBridgedConnection( | 16 SyncBridgedConnection::SyncBridgedConnection(ServerConnectionManager* scm, |
| 17 ServerConnectionManager* scm, | 17 HttpPostProviderFactory* factory) |
| 18 HttpPostProviderFactory* factory) | |
| 19 : Connection(scm), factory_(factory) { | 18 : Connection(scm), factory_(factory) { |
| 20 post_provider_ = factory_->Create(); | 19 post_provider_ = factory_->Create(); |
| 21 } | 20 } |
| 22 | 21 |
| 23 SyncAPIBridgedConnection::~SyncAPIBridgedConnection() { | 22 SyncBridgedConnection::~SyncBridgedConnection() { |
| 24 DCHECK(post_provider_); | 23 DCHECK(post_provider_); |
| 25 factory_->Destroy(post_provider_); | 24 factory_->Destroy(post_provider_); |
| 26 post_provider_ = NULL; | 25 post_provider_ = NULL; |
| 27 } | 26 } |
| 28 | 27 |
| 29 bool SyncAPIBridgedConnection::Init(const char* path, | 28 bool SyncBridgedConnection::Init(const char* path, |
| 30 const std::string& auth_token, | 29 const std::string& auth_token, |
| 31 const std::string& payload, | 30 const std::string& payload, |
| 32 HttpResponse* response) { | 31 HttpResponse* response) { |
| 33 std::string sync_server; | 32 std::string sync_server; |
| 34 int sync_server_port = 0; | 33 int sync_server_port = 0; |
| 35 bool use_ssl = false; | 34 bool use_ssl = false; |
| 36 GetServerParams(&sync_server, &sync_server_port, &use_ssl); | 35 GetServerParams(&sync_server, &sync_server_port, &use_ssl); |
| 37 std::string connection_url = MakeConnectionURL(sync_server, path, use_ssl); | 36 std::string connection_url = MakeConnectionURL(sync_server, path, use_ssl); |
| 38 | 37 |
| 39 HttpPostProviderInterface* http = post_provider_; | 38 HttpPostProviderInterface* http = post_provider_; |
| 40 http->SetURL(connection_url.c_str(), sync_server_port); | 39 http->SetURL(connection_url.c_str(), sync_server_port); |
| 41 | 40 |
| 42 if (!auth_token.empty()) { | 41 if (!auth_token.empty()) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 70 else if (response->response_code == net::HTTP_UNAUTHORIZED) | 69 else if (response->response_code == net::HTTP_UNAUTHORIZED) |
| 71 response->server_status = HttpResponse::SYNC_AUTH_ERROR; | 70 response->server_status = HttpResponse::SYNC_AUTH_ERROR; |
| 72 else | 71 else |
| 73 response->server_status = HttpResponse::SYNC_SERVER_ERROR; | 72 response->server_status = HttpResponse::SYNC_SERVER_ERROR; |
| 74 | 73 |
| 75 // Write the content into our buffer. | 74 // Write the content into our buffer. |
| 76 buffer_.assign(http->GetResponseContent(), http->GetResponseContentLength()); | 75 buffer_.assign(http->GetResponseContent(), http->GetResponseContentLength()); |
| 77 return true; | 76 return true; |
| 78 } | 77 } |
| 79 | 78 |
| 80 void SyncAPIBridgedConnection::Abort() { | 79 void SyncBridgedConnection::Abort() { |
| 81 DCHECK(post_provider_); | 80 DCHECK(post_provider_); |
| 82 post_provider_->Abort(); | 81 post_provider_->Abort(); |
| 83 } | 82 } |
| 84 | 83 |
| 85 SyncAPIServerConnectionManager::SyncAPIServerConnectionManager( | 84 SyncServerConnectionManager::SyncServerConnectionManager( |
| 86 const std::string& server, | 85 const std::string& server, |
| 87 int port, | 86 int port, |
| 88 bool use_ssl, | 87 bool use_ssl, |
| 89 HttpPostProviderFactory* factory, | 88 HttpPostProviderFactory* factory, |
| 90 CancelationSignal* cancelation_signal) | 89 CancelationSignal* cancelation_signal) |
| 91 : ServerConnectionManager(server, port, use_ssl, cancelation_signal), | 90 : ServerConnectionManager(server, port, use_ssl, cancelation_signal), |
| 92 post_provider_factory_(factory) { | 91 post_provider_factory_(factory) { |
| 93 DCHECK(post_provider_factory_.get()); | 92 DCHECK(post_provider_factory_.get()); |
| 94 } | 93 } |
| 95 | 94 |
| 96 SyncAPIServerConnectionManager::~SyncAPIServerConnectionManager() {} | 95 SyncServerConnectionManager::~SyncServerConnectionManager() {} |
| 97 | 96 |
| 98 ServerConnectionManager::Connection* | 97 ServerConnectionManager::Connection* |
| 99 SyncAPIServerConnectionManager::MakeConnection() { | 98 SyncServerConnectionManager::MakeConnection() { |
| 100 return new SyncAPIBridgedConnection(this, post_provider_factory_.get()); | 99 return new SyncBridgedConnection(this, post_provider_factory_.get()); |
| 101 } | 100 } |
| 102 | 101 |
| 103 } // namespace syncer | 102 } // namespace syncer |
| OLD | NEW |