| 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 #ifndef SYNC_INTERNAL_API_SYNCAPI_SERVER_CONNECTION_MANAGER_H_ | 5 #ifndef SYNC_INTERNAL_API_SYNCAPI_SERVER_CONNECTION_MANAGER_H_ |
| 6 #define SYNC_INTERNAL_API_SYNCAPI_SERVER_CONNECTION_MANAGER_H_ | 6 #define SYNC_INTERNAL_API_SYNCAPI_SERVER_CONNECTION_MANAGER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "sync/engine/net/server_connection_manager.h" | 13 #include "sync/engine/net/server_connection_manager.h" |
| 14 | 14 |
| 15 namespace syncer { | 15 namespace syncer { |
| 16 | 16 |
| 17 class HttpPostProviderFactory; | 17 class HttpPostProviderFactory; |
| 18 class HttpPostProviderInterface; | 18 class HttpPostProviderInterface; |
| 19 | 19 |
| 20 // This provides HTTP Post functionality through the interface provided | 20 // This provides HTTP Post functionality through the interface provided |
| 21 // to the sync API by the application hosting the syncer backend. | 21 // to the sync API by the application hosting the syncer backend. |
| 22 class SyncAPIBridgedConnection | 22 class SyncAPIBridgedConnection : public ServerConnectionManager::Connection { |
| 23 : public syncer::ServerConnectionManager::Connection { | |
| 24 public: | 23 public: |
| 25 SyncAPIBridgedConnection(syncer::ServerConnectionManager* scm, | 24 SyncAPIBridgedConnection(ServerConnectionManager* scm, |
| 26 HttpPostProviderFactory* factory); | 25 HttpPostProviderFactory* factory); |
| 27 | 26 |
| 28 virtual ~SyncAPIBridgedConnection(); | 27 virtual ~SyncAPIBridgedConnection(); |
| 29 | 28 |
| 30 virtual bool Init(const char* path, | 29 virtual bool Init(const char* path, |
| 31 const std::string& auth_token, | 30 const std::string& auth_token, |
| 32 const std::string& payload, | 31 const std::string& payload, |
| 33 syncer::HttpResponse* response) OVERRIDE; | 32 HttpResponse* response) OVERRIDE; |
| 34 | 33 |
| 35 virtual void Abort() OVERRIDE; | 34 virtual void Abort() OVERRIDE; |
| 36 | 35 |
| 37 private: | 36 private: |
| 38 // Pointer to the factory we use for creating HttpPostProviders. We do not | 37 // Pointer to the factory we use for creating HttpPostProviders. We do not |
| 39 // own |factory_|. | 38 // own |factory_|. |
| 40 HttpPostProviderFactory* factory_; | 39 HttpPostProviderFactory* factory_; |
| 41 | 40 |
| 42 HttpPostProviderInterface* post_provider_; | 41 HttpPostProviderInterface* post_provider_; |
| 43 | 42 |
| 44 DISALLOW_COPY_AND_ASSIGN(SyncAPIBridgedConnection); | 43 DISALLOW_COPY_AND_ASSIGN(SyncAPIBridgedConnection); |
| 45 }; | 44 }; |
| 46 | 45 |
| 47 // A ServerConnectionManager subclass used by the syncapi layer. We use a | 46 // A ServerConnectionManager subclass used by the syncapi layer. We use a |
| 48 // subclass so that we can override MakePost() to generate a POST object using | 47 // subclass so that we can override MakePost() to generate a POST object using |
| 49 // an instance of the HttpPostProviderFactory class. | 48 // an instance of the HttpPostProviderFactory class. |
| 50 class SyncAPIServerConnectionManager | 49 class SyncAPIServerConnectionManager : public ServerConnectionManager { |
| 51 : public syncer::ServerConnectionManager { | |
| 52 public: | 50 public: |
| 53 // Takes ownership of factory. | 51 // Takes ownership of factory. |
| 54 SyncAPIServerConnectionManager(const std::string& server, | 52 SyncAPIServerConnectionManager(const std::string& server, |
| 55 int port, | 53 int port, |
| 56 bool use_ssl, | 54 bool use_ssl, |
| 57 HttpPostProviderFactory* factory); | 55 HttpPostProviderFactory* factory); |
| 58 virtual ~SyncAPIServerConnectionManager(); | 56 virtual ~SyncAPIServerConnectionManager(); |
| 59 | 57 |
| 60 // ServerConnectionManager overrides. | 58 // ServerConnectionManager overrides. |
| 61 virtual Connection* MakeConnection() OVERRIDE; | 59 virtual Connection* MakeConnection() OVERRIDE; |
| 62 | 60 |
| 63 private: | 61 private: |
| 64 FRIEND_TEST_ALL_PREFIXES(SyncAPIServerConnectionManagerTest, EarlyAbortPost); | 62 FRIEND_TEST_ALL_PREFIXES(SyncAPIServerConnectionManagerTest, EarlyAbortPost); |
| 65 FRIEND_TEST_ALL_PREFIXES(SyncAPIServerConnectionManagerTest, AbortPost); | 63 FRIEND_TEST_ALL_PREFIXES(SyncAPIServerConnectionManagerTest, AbortPost); |
| 66 | 64 |
| 67 // A factory creating concrete HttpPostProviders for use whenever we need to | 65 // A factory creating concrete HttpPostProviders for use whenever we need to |
| 68 // issue a POST to sync servers. | 66 // issue a POST to sync servers. |
| 69 scoped_ptr<HttpPostProviderFactory> post_provider_factory_; | 67 scoped_ptr<HttpPostProviderFactory> post_provider_factory_; |
| 70 | 68 |
| 71 DISALLOW_COPY_AND_ASSIGN(SyncAPIServerConnectionManager); | 69 DISALLOW_COPY_AND_ASSIGN(SyncAPIServerConnectionManager); |
| 72 }; | 70 }; |
| 73 | 71 |
| 74 } // namespace syncer | 72 } // namespace syncer |
| 75 | 73 |
| 76 #endif // SYNC_INTERNAL_API_SYNCAPI_SERVER_CONNECTION_MANAGER_H_ | 74 #endif // SYNC_INTERNAL_API_SYNCAPI_SERVER_CONNECTION_MANAGER_H_ |
| OLD | NEW |