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> |
| 10 |
| 11 #include "base/compiler_specific.h" |
| 12 #include "chrome/browser/sync/api/sync_change_processor.h" |
9 #include "chrome/browser/sync/glue/change_processor.h" | 13 #include "chrome/browser/sync/glue/change_processor.h" |
10 | 14 |
| 15 class SyncData; |
11 class SyncableService; | 16 class SyncableService; |
12 | 17 |
| 18 typedef std::vector<SyncData> SyncDataList; |
| 19 |
13 namespace browser_sync { | 20 namespace browser_sync { |
14 | 21 |
15 // TODO(sync): Have this become a SyncableService implementation and deprecate | 22 // TODO(sync): deprecate all change processors and have them replaced by |
16 // ChangeProcessor. | 23 // instances of this. |
17 // For now, it acts as a dummy change processor that just passes all | 24 // Datatype agnostic change processor. One instance of GenericChangeProcessor |
18 // ApplySyncChanges commands onto the local SyncableService.. | 25 // is created for each datatype and lives on the datatype's thread. It then |
19 class GenericChangeProcessor : public ChangeProcessor { | 26 // handles all interaction with the sync api, both translating pushes from the |
| 27 // 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. |
| 29 class GenericChangeProcessor : public ChangeProcessor, |
| 30 public SyncChangeProcessor { |
20 public: | 31 public: |
21 GenericChangeProcessor(SyncableService* local_service, | 32 GenericChangeProcessor(SyncableService* local_service, |
22 UnrecoverableErrorHandler* error_handler); | 33 UnrecoverableErrorHandler* error_handler, |
| 34 sync_api::UserShare* user_share); |
23 ~GenericChangeProcessor(); | 35 ~GenericChangeProcessor(); |
24 | 36 |
25 // ChangeProcessor interface. | 37 // ChangeProcessor interface. |
26 // Just passes all arguments onto the |local_service_| | 38 // Build and store a list of all changes into |syncer_changes_|. |
27 virtual void ApplyChangesFromSyncModel( | 39 virtual void ApplyChangesFromSyncModel( |
28 const sync_api::BaseTransaction* trans, | 40 const sync_api::BaseTransaction* trans, |
29 const sync_api::SyncManager::ChangeRecord* changes, | 41 const sync_api::SyncManager::ChangeRecord* changes, |
30 int change_count); | 42 int change_count) OVERRIDE; |
| 43 // Passes |syncer_changes_|, built in ApplyChangesFromSyncModel, onto |
| 44 // |local_service_| by way of it's ProcessSyncChanges method. |
| 45 virtual void CommitChangesFromSyncModel() OVERRIDE; |
| 46 |
| 47 // SyncChangeProcessor implementation. |
| 48 virtual void ProcessSyncChanges(const SyncChangeList& change_list) OVERRIDE; |
| 49 |
| 50 // Fills |current_sync_data| with all the syncer data for the specified type. |
| 51 virtual bool GetSyncDataForType(syncable::ModelType type, |
| 52 SyncDataList* current_sync_data); |
| 53 |
| 54 // Generic versions of AssociatorInterface methods. Called by |
| 55 // SyncableServiceAdapter. |
| 56 bool SyncModelHasUserCreatedNodes(syncable::ModelType type, |
| 57 bool* has_nodes); |
| 58 bool CryptoReadyIfNecessary(syncable::ModelType type); |
31 protected: | 59 protected: |
32 // ChangeProcessor interface. | 60 // ChangeProcessor interface. |
33 virtual void StartImpl(Profile* profile); // Not implemented. | 61 virtual void StartImpl(Profile* profile) OVERRIDE; // Not implemented. |
34 virtual void StopImpl(); // Not implemented. | 62 virtual void StopImpl() OVERRIDE; // Not implemented. |
| 63 virtual sync_api::UserShare* share_handle() OVERRIDE; |
35 private: | 64 private: |
| 65 // The SyncableService this change processor will forward changes on to. |
36 SyncableService* local_service_; | 66 SyncableService* local_service_; |
| 67 |
| 68 // The current list of changes received from the syncer. We buffer because |
| 69 // we must ensure no syncapi transaction is held when we pass it on to |
| 70 // |local_service_|. |
| 71 // Set in ApplyChangesFromSyncModel, consumed in CommitChangesFromSyncModel. |
| 72 SyncChangeList syncer_changes_; |
| 73 |
| 74 // Our handle to the sync model. Unlike normal ChangeProcessors, we need to |
| 75 // be able to access the sync model before the change processor begins |
| 76 // listening to changes (the local_service_ will be interacting with us |
| 77 // when it starts up). As such we can't wait until Start(_) has been called, |
| 78 // and have to keep a local pointer to the user_share. |
| 79 sync_api::UserShare* user_share_; |
37 }; | 80 }; |
38 | 81 |
39 } // namespace browser_sync | 82 } // namespace browser_sync |
40 | 83 |
41 #endif // CHROME_BROWSER_SYNC_GLUE_GENERIC_CHANGE_PROCESSOR_H_ | 84 #endif // CHROME_BROWSER_SYNC_GLUE_GENERIC_CHANGE_PROCESSOR_H_ |
OLD | NEW |