| 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 CHROME_BROWSER_SYNC_GLUE_SHARED_CHANGE_PROCESSOR_H_ | 5 #ifndef CHROME_BROWSER_SYNC_GLUE_SHARED_CHANGE_PROCESSOR_H_ |
| 6 #define CHROME_BROWSER_SYNC_GLUE_SHARED_CHANGE_PROCESSOR_H_ | 6 #define CHROME_BROWSER_SYNC_GLUE_SHARED_CHANGE_PROCESSOR_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/message_loop_proxy.h" | 12 #include "base/message_loop_proxy.h" |
| 13 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
| 14 #include "chrome/browser/sync/glue/data_type_error_handler.h" | 14 #include "chrome/browser/sync/glue/data_type_error_handler.h" |
| 15 #include "sync/api/sync_change_processor.h" | 15 #include "sync/api/sync_change_processor.h" |
| 16 #include "sync/api/sync_error.h" | 16 #include "sync/api/sync_error.h" |
| 17 #include "sync/api/sync_error_factory.h" | 17 #include "sync/api/sync_error_factory.h" |
| 18 #include "sync/internal_api/public/engine/model_safe_worker.h" | 18 #include "sync/internal_api/public/engine/model_safe_worker.h" |
| 19 | 19 |
| 20 class ProfileSyncComponentsFactory; | 20 class ProfileSyncComponentsFactory; |
| 21 class ProfileSyncService; | 21 class ProfileSyncService; |
| 22 |
| 23 namespace csync { |
| 22 class SyncData; | 24 class SyncData; |
| 23 class SyncableService; | 25 class SyncableService; |
| 24 | 26 |
| 25 typedef std::vector<SyncData> SyncDataList; | 27 typedef std::vector<csync::SyncData> SyncDataList; |
| 28 } // namespace |
| 26 | 29 |
| 27 namespace browser_sync { | 30 namespace browser_sync { |
| 28 | 31 |
| 29 class GenericChangeProcessor; | 32 class GenericChangeProcessor; |
| 30 class DataTypeErrorHandler; | 33 class DataTypeErrorHandler; |
| 31 | 34 |
| 32 // A ref-counted wrapper around a GenericChangeProcessor for use with datatypes | 35 // A ref-counted wrapper around a GenericChangeProcessor for use with datatypes |
| 33 // that don't live on the UI thread. | 36 // that don't live on the UI thread. |
| 34 // | 37 // |
| 35 // We need to make it refcounted as the ownership transfer from the | 38 // We need to make it refcounted as the ownership transfer from the |
| (...skipping 11 matching lines...) Expand all Loading... |
| 47 // | 50 // |
| 48 // We use virtual methods so that we can use mock's in testing. | 51 // We use virtual methods so that we can use mock's in testing. |
| 49 class SharedChangeProcessor | 52 class SharedChangeProcessor |
| 50 : public base::RefCountedThreadSafe<SharedChangeProcessor> { | 53 : public base::RefCountedThreadSafe<SharedChangeProcessor> { |
| 51 public: | 54 public: |
| 52 // Create an uninitialized SharedChangeProcessor (to be later connected). | 55 // Create an uninitialized SharedChangeProcessor (to be later connected). |
| 53 SharedChangeProcessor(); | 56 SharedChangeProcessor(); |
| 54 | 57 |
| 55 // Connect to the Syncer and prepare to handle changes for |type|. Will | 58 // Connect to the Syncer and prepare to handle changes for |type|. Will |
| 56 // create and store a new GenericChangeProcessor and return a weak pointer to | 59 // create and store a new GenericChangeProcessor and return a weak pointer to |
| 57 // the SyncableService associated with |type|. | 60 // the csync::SyncableService associated with |type|. |
| 58 // Note: If this SharedChangeProcessor has been disconnected, or the | 61 // Note: If this SharedChangeProcessor has been disconnected, or the |
| 59 // SyncableService was not alive, will return a null weak pointer. | 62 // csync::SyncableService was not alive, will return a null weak pointer. |
| 60 virtual base::WeakPtr<SyncableService> Connect( | 63 virtual base::WeakPtr<csync::SyncableService> Connect( |
| 61 ProfileSyncComponentsFactory* sync_factory, | 64 ProfileSyncComponentsFactory* sync_factory, |
| 62 ProfileSyncService* sync_service, | 65 ProfileSyncService* sync_service, |
| 63 DataTypeErrorHandler* error_handler, | 66 DataTypeErrorHandler* error_handler, |
| 64 syncable::ModelType type); | 67 syncable::ModelType type); |
| 65 | 68 |
| 66 // Disconnects from the generic change processor. May be called from any | 69 // Disconnects from the generic change processor. May be called from any |
| 67 // thread. After this, all attempts to interact with the change processor by | 70 // thread. After this, all attempts to interact with the change processor by |
| 68 // |local_service_| are dropped and return errors. The syncer will be safe to | 71 // |local_service_| are dropped and return errors. The syncer will be safe to |
| 69 // shut down from the point of view of this datatype. | 72 // shut down from the point of view of this datatype. |
| 70 // Note: Once disconnected, you cannot reconnect without creating a new | 73 // Note: Once disconnected, you cannot reconnect without creating a new |
| 71 // SharedChangeProcessor. | 74 // SharedChangeProcessor. |
| 72 // Returns: true if we were previously succesfully connected, false if we were | 75 // Returns: true if we were previously succesfully connected, false if we were |
| 73 // already disconnected. | 76 // already disconnected. |
| 74 virtual bool Disconnect(); | 77 virtual bool Disconnect(); |
| 75 | 78 |
| 76 // GenericChangeProcessor stubs (with disconnect support). | 79 // GenericChangeProcessor stubs (with disconnect support). |
| 77 // Should only be called on the same thread the datatype resides. | 80 // Should only be called on the same thread the datatype resides. |
| 78 virtual SyncError GetSyncData(SyncDataList* current_sync_data); | 81 virtual csync::SyncError GetSyncData(csync::SyncDataList* current_sync_data); |
| 79 virtual SyncError ProcessSyncChanges( | 82 virtual csync::SyncError ProcessSyncChanges( |
| 80 const tracked_objects::Location& from_here, | 83 const tracked_objects::Location& from_here, |
| 81 const SyncChangeList& change_list); | 84 const csync::SyncChangeList& change_list); |
| 82 virtual bool SyncModelHasUserCreatedNodes(bool* has_nodes); | 85 virtual bool SyncModelHasUserCreatedNodes(bool* has_nodes); |
| 83 virtual bool CryptoReadyIfNecessary(); | 86 virtual bool CryptoReadyIfNecessary(); |
| 84 | 87 |
| 85 // Register |generic_change_processor_| as the change processor for the | 88 // Register |generic_change_processor_| as the change processor for the |
| 86 // current type on |model_safe_group|. | 89 // current type on |model_safe_group|. |
| 87 // Does nothing if |disconnected_| is true. | 90 // Does nothing if |disconnected_| is true. |
| 88 virtual void ActivateDataType(csync::ModelSafeGroup model_safe_group); | 91 virtual void ActivateDataType(csync::ModelSafeGroup model_safe_group); |
| 89 | 92 |
| 90 virtual SyncError CreateAndUploadError( | 93 virtual csync::SyncError CreateAndUploadError( |
| 91 const tracked_objects::Location& location, | 94 const tracked_objects::Location& location, |
| 92 const std::string& message); | 95 const std::string& message); |
| 93 | 96 |
| 94 protected: | 97 protected: |
| 95 friend class base::RefCountedThreadSafe<SharedChangeProcessor>; | 98 friend class base::RefCountedThreadSafe<SharedChangeProcessor>; |
| 96 virtual ~SharedChangeProcessor(); | 99 virtual ~SharedChangeProcessor(); |
| 97 | 100 |
| 98 private: | 101 private: |
| 99 // Monitor lock for this object. All methods that interact with the change | 102 // Monitor lock for this object. All methods that interact with the change |
| 100 // processor must aquire this lock and check whether we're disconnected or | 103 // processor must aquire this lock and check whether we're disconnected or |
| (...skipping 17 matching lines...) Expand all Loading... |
| 118 GenericChangeProcessor* generic_change_processor_; | 121 GenericChangeProcessor* generic_change_processor_; |
| 119 | 122 |
| 120 DataTypeErrorHandler* error_handler_; | 123 DataTypeErrorHandler* error_handler_; |
| 121 | 124 |
| 122 DISALLOW_COPY_AND_ASSIGN(SharedChangeProcessor); | 125 DISALLOW_COPY_AND_ASSIGN(SharedChangeProcessor); |
| 123 }; | 126 }; |
| 124 | 127 |
| 125 } // namespace browser_sync | 128 } // namespace browser_sync |
| 126 | 129 |
| 127 #endif // CHROME_BROWSER_SYNC_GLUE_SHARED_CHANGE_PROCESSOR_H_ | 130 #endif // CHROME_BROWSER_SYNC_GLUE_SHARED_CHANGE_PROCESSOR_H_ |
| OLD | NEW |