Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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_GENERIC_CHANGE_PROCESSOR_H_ | 5 #ifndef CHROME_BROWSER_SYNC_GLUE_GENERIC_CHANGE_PROCESSOR_H_ |
| 6 #define CHROME_BROWSER_SYNC_GLUE_GENERIC_CHANGE_PROCESSOR_H_ | 6 #define CHROME_BROWSER_SYNC_GLUE_GENERIC_CHANGE_PROCESSOR_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/memory/weak_ptr.h" | |
| 13 #include "base/threading/non_thread_safe.h" | |
| 12 #include "chrome/browser/sync/api/sync_change_processor.h" | 14 #include "chrome/browser/sync/api/sync_change_processor.h" |
| 13 #include "chrome/browser/sync/glue/change_processor.h" | 15 #include "chrome/browser/sync/glue/change_processor.h" |
| 14 | 16 |
| 15 class SyncData; | 17 class SyncData; |
| 16 class SyncableService; | 18 class SyncableService; |
| 17 | 19 |
| 18 typedef std::vector<SyncData> SyncDataList; | 20 typedef std::vector<SyncData> SyncDataList; |
| 19 | 21 |
| 20 namespace browser_sync { | 22 namespace browser_sync { |
| 21 | 23 |
| 22 // TODO(sync): deprecate all change processors and have them replaced by | 24 // TODO(sync): deprecate all change processors and have them replaced by |
| 23 // instances of this. | 25 // instances of this. |
| 24 // Datatype agnostic change processor. One instance of GenericChangeProcessor | 26 // Datatype agnostic change processor. One instance of GenericChangeProcessor |
| 25 // is created for each datatype and lives on the datatype's thread. It then | 27 // is created for each datatype and lives on the datatype's thread. It then |
| 26 // handles all interaction with the sync api, both translating pushes from the | 28 // handles all interaction with the sync api, both translating pushes from the |
| 27 // local service into transactions and receiving changes from the sync model, | 29 // local service into transactions and receiving changes from the sync model, |
| 28 // which then get converted into SyncChange's and sent to the local service. | 30 // which then get converted into SyncChange's and sent to the local service. |
| 31 // | |
| 32 // As a rule, the GenericChangeProcessor is not thread safe, and should only | |
| 33 // be used on the same thread in which it was created. | |
| 29 class GenericChangeProcessor : public ChangeProcessor, | 34 class GenericChangeProcessor : public ChangeProcessor, |
| 30 public SyncChangeProcessor { | 35 public SyncChangeProcessor, |
| 36 public base::NonThreadSafe { | |
| 31 public: | 37 public: |
| 32 GenericChangeProcessor(SyncableService* local_service, | 38 // Create a change processor and connect it to the syncer. |
| 33 UnrecoverableErrorHandler* error_handler, | 39 GenericChangeProcessor(UnrecoverableErrorHandler* error_handler, |
| 40 const base::WeakPtr<SyncableService>& local_service, | |
| 34 sync_api::UserShare* user_share); | 41 sync_api::UserShare* user_share); |
| 35 virtual ~GenericChangeProcessor(); | 42 virtual ~GenericChangeProcessor(); |
| 36 | 43 |
| 37 // ChangeProcessor interface. | 44 // ChangeProcessor interface. |
| 38 // Build and store a list of all changes into |syncer_changes_|. | 45 // Build and store a list of all changes into |syncer_changes_|. |
| 39 virtual void ApplyChangesFromSyncModel( | 46 virtual void ApplyChangesFromSyncModel( |
| 40 const sync_api::BaseTransaction* trans, | 47 const sync_api::BaseTransaction* trans, |
| 41 const sync_api::ImmutableChangeRecordList& changes) OVERRIDE; | 48 const sync_api::ImmutableChangeRecordList& changes) OVERRIDE; |
| 42 // Passes |syncer_changes_|, built in ApplyChangesFromSyncModel, onto | 49 // Passes |syncer_changes_|, built in ApplyChangesFromSyncModel, onto |
| 43 // |local_service_| by way of it's ProcessSyncChanges method. | 50 // |local_service_| by way of it's ProcessSyncChanges method. |
| 44 virtual void CommitChangesFromSyncModel() OVERRIDE; | 51 virtual void CommitChangesFromSyncModel() OVERRIDE; |
| 45 | 52 |
| 46 // SyncChangeProcessor implementation. | 53 // SyncChangeProcessor implementation. |
| 47 virtual SyncError ProcessSyncChanges( | 54 virtual SyncError ProcessSyncChanges( |
| 48 const tracked_objects::Location& from_here, | 55 const tracked_objects::Location& from_here, |
| 49 const SyncChangeList& change_list) OVERRIDE; | 56 const SyncChangeList& change_list) OVERRIDE; |
| 50 | 57 |
| 51 // Fills |current_sync_data| with all the syncer data for the specified type. | 58 // Fills |current_sync_data| with all the syncer data for the specified type. |
| 52 virtual SyncError GetSyncDataForType(syncable::ModelType type, | 59 SyncError GetSyncDataForType(syncable::ModelType type, |
| 53 SyncDataList* current_sync_data); | 60 SyncDataList* current_sync_data); |
|
akalin
2011/10/12 19:54:21
indent
Nicolas Zea
2011/10/12 23:47:43
Done.
| |
| 54 | 61 |
| 55 // Generic versions of AssociatorInterface methods. Called by | 62 // Generic versions of AssociatorInterface methods. Called by |
| 56 // SyncableServiceAdapter. | 63 // SyncableServiceAdapter or the DataTypeController. |
| 57 bool SyncModelHasUserCreatedNodes(syncable::ModelType type, | 64 bool SyncModelHasUserCreatedNodes(syncable::ModelType type, |
| 58 bool* has_nodes); | 65 bool* has_nodes); |
|
akalin
2011/10/12 19:54:21
indent
Nicolas Zea
2011/10/12 23:47:43
Done.
| |
| 59 bool CryptoReadyIfNecessary(syncable::ModelType type); | 66 bool CryptoReadyIfNecessary(syncable::ModelType type); |
| 67 | |
| 60 protected: | 68 protected: |
| 61 // ChangeProcessor interface. | 69 // ChangeProcessor interface. |
| 62 virtual void StartImpl(Profile* profile) OVERRIDE; // Not implemented. | 70 virtual void StartImpl(Profile* profile) OVERRIDE; // Does nothing. |
| 63 virtual void StopImpl() OVERRIDE; // Not implemented. | 71 // Called from UI thread (as part of deactivating datatype), but does |
| 64 virtual sync_api::UserShare* share_handle() OVERRIDE; | 72 // nothing and is guaranteed to still be alive, so it's okay. |
| 73 virtual void StopImpl() OVERRIDE; // Does nothing. | |
| 74 virtual sync_api::UserShare* share_handle() const OVERRIDE; | |
| 75 | |
| 65 private: | 76 private: |
| 66 // The SyncableService this change processor will forward changes on to. | 77 // The SyncableService this change processor will forward changes on to. |
| 67 SyncableService* local_service_; | 78 base::WeakPtr<SyncableService> local_service_; |
|
akalin
2011/10/12 19:54:21
const base::WeakPtr
Nicolas Zea
2011/10/12 23:47:43
Done.
| |
| 68 | 79 |
| 69 // The current list of changes received from the syncer. We buffer because | 80 // The current list of changes received from the syncer. We buffer because |
| 70 // we must ensure no syncapi transaction is held when we pass it on to | 81 // we must ensure no syncapi transaction is held when we pass it on to |
| 71 // |local_service_|. | 82 // |local_service_|. |
| 72 // Set in ApplyChangesFromSyncModel, consumed in CommitChangesFromSyncModel. | 83 // Set in ApplyChangesFromSyncModel, consumed in CommitChangesFromSyncModel. |
| 73 SyncChangeList syncer_changes_; | 84 SyncChangeList syncer_changes_; |
| 74 | 85 |
| 75 // Our handle to the sync model. Unlike normal ChangeProcessors, we need to | 86 // Our handle to the sync model. Unlike normal ChangeProcessors, we need to |
| 76 // be able to access the sync model before the change processor begins | 87 // be able to access the sync model before the change processor begins |
| 77 // listening to changes (the local_service_ will be interacting with us | 88 // listening to changes (the local_service_ will be interacting with us |
| 78 // when it starts up). As such we can't wait until Start(_) has been called, | 89 // when it starts up). As such we can't wait until Start(_) has been called, |
| 79 // and have to keep a local pointer to the user_share. | 90 // and have to keep a local pointer to the user_share. |
| 80 sync_api::UserShare* user_share_; | 91 sync_api::UserShare* share_handle_; |
|
akalin
2011/10/12 19:54:21
* -> * const
Nicolas Zea
2011/10/12 23:47:43
Done.
| |
| 92 | |
| 93 DISALLOW_COPY_AND_ASSIGN(GenericChangeProcessor); | |
| 81 }; | 94 }; |
| 82 | 95 |
| 83 } // namespace browser_sync | 96 } // namespace browser_sync |
| 84 | 97 |
| 85 #endif // CHROME_BROWSER_SYNC_GLUE_GENERIC_CHANGE_PROCESSOR_H_ | 98 #endif // CHROME_BROWSER_SYNC_GLUE_GENERIC_CHANGE_PROCESSOR_H_ |
| OLD | NEW |