Home | History | Annotate | Download | only in sync
      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
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_
      6 #define CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_
      7 
      8 #include <string>
      9 
     10 #include "base/callback.h"
     11 #include "base/compiler_specific.h"
     12 #include "base/memory/weak_ptr.h"
     13 #include "chrome/browser/signin/profile_oauth2_token_service.h"
     14 #include "chrome/browser/sync/glue/data_type_manager_impl.h"
     15 #include "chrome/browser/sync/glue/sync_backend_host_impl.h"
     16 #include "chrome/browser/sync/profile_sync_service.h"
     17 #include "chrome/browser/sync/sync_prefs.h"
     18 #include "sync/test/engine/test_id_factory.h"
     19 #include "testing/gmock/include/gmock/gmock.h"
     20 
     21 class Profile;
     22 class ProfileOAuth2TokenService;
     23 class ProfileSyncComponentsFactory;
     24 class ProfileSyncComponentsFactoryMock;
     25 
     26 ACTION(ReturnNewDataTypeManager) {
     27   return new browser_sync::DataTypeManagerImpl(arg0,
     28                                                arg1,
     29                                                arg2,
     30                                                arg3,
     31                                                arg4,
     32                                                arg5);
     33 }
     34 
     35 namespace browser_sync {
     36 
     37 class SyncBackendHostForProfileSyncTest : public SyncBackendHostImpl {
     38  public:
     39   SyncBackendHostForProfileSyncTest(
     40       Profile* profile,
     41       const base::WeakPtr<SyncPrefs>& sync_prefs,
     42       base::Closure& callback);
     43   virtual ~SyncBackendHostForProfileSyncTest();
     44 
     45   virtual void RequestConfigureSyncer(
     46       syncer::ConfigureReason reason,
     47       syncer::ModelTypeSet to_download,
     48       syncer::ModelTypeSet to_purge,
     49       syncer::ModelTypeSet to_journal,
     50       syncer::ModelTypeSet to_unapply,
     51       syncer::ModelTypeSet to_ignore,
     52       const syncer::ModelSafeRoutingInfo& routing_info,
     53       const base::Callback<void(syncer::ModelTypeSet,
     54                                 syncer::ModelTypeSet)>& ready_task,
     55       const base::Closure& retry_callback) OVERRIDE;
     56 
     57  protected:
     58   virtual void InitCore(scoped_ptr<DoInitializeOptions> options) OVERRIDE;
     59 
     60  private:
     61   // Invoked at the start of HandleSyncManagerInitializationOnFrontendLoop.
     62   // Allows extra initialization work to be performed before the backend comes
     63   // up.
     64   base::Closure& callback_;
     65 };
     66 
     67 }  // namespace browser_sync
     68 
     69 class TestProfileSyncService : public ProfileSyncService {
     70  public:
     71   // TODO(tim): Add ability to inject TokenService alongside SigninManager.
     72   // TODO(rogerta): what does above comment mean?
     73   TestProfileSyncService(
     74       ProfileSyncComponentsFactory* factory,
     75       Profile* profile,
     76       SigninManagerBase* signin,
     77       ProfileOAuth2TokenService* oauth2_token_service,
     78       ProfileSyncService::StartBehavior behavior);
     79 
     80   virtual ~TestProfileSyncService();
     81 
     82   virtual void OnConfigureDone(
     83       const browser_sync::DataTypeManager::ConfigureResult& result) OVERRIDE;
     84 
     85   // We implement our own version to avoid some DCHECKs.
     86   virtual syncer::UserShare* GetUserShare() const OVERRIDE;
     87 
     88   static BrowserContextKeyedService* BuildAutoStartAsyncInit(
     89       content::BrowserContext* profile);
     90 
     91   ProfileSyncComponentsFactoryMock* components_factory_mock();
     92 
     93   // |callback| can be used to populate nodes before the OnBackendInitialized
     94   // callback fires.
     95   void set_backend_init_callback(const base::Closure& callback) {
     96     callback_ = callback;
     97   }
     98 
     99   syncer::TestIdFactory* id_factory();
    100 
    101  protected:
    102   virtual void CreateBackend() OVERRIDE;
    103 
    104   // Return NULL handle to use in backend initialization to avoid receiving
    105   // js messages on UI loop when it's being destroyed, which are not deleted
    106   // and cause memory leak in test.
    107   virtual syncer::WeakHandle<syncer::JsEventHandler> GetJsEventHandler()
    108       OVERRIDE;
    109 
    110  private:
    111   syncer::TestIdFactory id_factory_;
    112 
    113   base::Closure callback_;
    114 };
    115 
    116 #endif  // CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_
    117