Home | History | Annotate | Download | only in net
      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_ENGINE_NET_SYNCAPI_SERVER_CONNECTION_MANAGER_H_
      6 #define CHROME_BROWSER_SYNC_ENGINE_NET_SYNCAPI_SERVER_CONNECTION_MANAGER_H_
      7 #pragma once
      8 
      9 #include <string>
     10 
     11 #include "base/memory/scoped_ptr.h"
     12 #include "chrome/browser/sync/engine/net/server_connection_manager.h"
     13 
     14 namespace sync_api {
     15 
     16 class HttpPostProviderFactory;
     17 
     18 // This provides HTTP Post functionality through the interface provided
     19 // to the sync API by the application hosting the syncer backend.
     20 class SyncAPIBridgedPost
     21     : public browser_sync::ServerConnectionManager::Post {
     22  public:
     23   SyncAPIBridgedPost(browser_sync::ServerConnectionManager* scm,
     24                      HttpPostProviderFactory* factory);
     25 
     26   virtual ~SyncAPIBridgedPost();
     27 
     28   virtual bool Init(const char* path,
     29                     const std::string& auth_token,
     30                     const std::string& payload,
     31                     browser_sync::HttpResponse* response);
     32 
     33  private:
     34   // Pointer to the factory we use for creating HttpPostProviders. We do not
     35   // own |factory_|.
     36   HttpPostProviderFactory* factory_;
     37 
     38   DISALLOW_COPY_AND_ASSIGN(SyncAPIBridgedPost);
     39 };
     40 
     41 // A ServerConnectionManager subclass used by the syncapi layer. We use a
     42 // subclass so that we can override MakePost() to generate a POST object using
     43 // an instance of the HttpPostProviderFactory class.
     44 class SyncAPIServerConnectionManager
     45     : public browser_sync::ServerConnectionManager {
     46  public:
     47   // Takes ownership of factory.
     48   SyncAPIServerConnectionManager(const std::string& server,
     49                                  int port,
     50                                  bool use_ssl,
     51                                  const std::string& client_version,
     52                                  HttpPostProviderFactory* factory);
     53   virtual ~SyncAPIServerConnectionManager();
     54 
     55  protected:
     56   virtual Post* MakePost();
     57 
     58  private:
     59   // A factory creating concrete HttpPostProviders for use whenever we need to
     60   // issue a POST to sync servers.
     61   scoped_ptr<HttpPostProviderFactory> post_provider_factory_;
     62 
     63   DISALLOW_COPY_AND_ASSIGN(SyncAPIServerConnectionManager);
     64 };
     65 
     66 }  // namespace sync_api
     67 
     68 #endif  // CHROME_BROWSER_SYNC_ENGINE_NET_SYNCAPI_SERVER_CONNECTION_MANAGER_H_
     69