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 SyncableService* local_service, | |
34 sync_api::UserShare* user_share); | 41 sync_api::UserShare* user_share); |
35 virtual ~GenericChangeProcessor(); | 42 virtual ~GenericChangeProcessor() OVERRIDE; |
akalin
2011/10/11 22:41:08
OVERRIDE on destructor is kinda weird, as the beha
Nicolas Zea
2011/10/12 04:24:19
Done.
| |
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 virtual SyncError GetSyncDataForType(syncable::ModelType type, |
53 SyncDataList* current_sync_data); | 60 SyncDataList* current_sync_data); |
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 virtual bool SyncModelHasUserCreatedNodes(syncable::ModelType type, |
akalin
2011/10/11 22:41:08
Hm, why are these virtual? are they overridden fr
Nicolas Zea
2011/10/12 04:24:19
Removed virtual.
| |
58 bool* has_nodes); | 65 bool* has_nodes); |
59 bool CryptoReadyIfNecessary(syncable::ModelType type); | 66 virtual 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 virtual void StopImpl() OVERRIDE; // Does nothing. |
64 virtual sync_api::UserShare* share_handle() OVERRIDE; | 72 virtual sync_api::UserShare* share_handle() const OVERRIDE; |
73 | |
65 private: | 74 private: |
66 // The SyncableService this change processor will forward changes on to. | 75 // The SyncableService this change processor will forward changes on to. |
67 SyncableService* local_service_; | 76 base::WeakPtr<SyncableService> local_service_; |
68 | 77 |
69 // The current list of changes received from the syncer. We buffer because | 78 // 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 | 79 // we must ensure no syncapi transaction is held when we pass it on to |
71 // |local_service_|. | 80 // |local_service_|. |
72 // Set in ApplyChangesFromSyncModel, consumed in CommitChangesFromSyncModel. | 81 // Set in ApplyChangesFromSyncModel, consumed in CommitChangesFromSyncModel. |
73 SyncChangeList syncer_changes_; | 82 SyncChangeList syncer_changes_; |
74 | 83 |
75 // Our handle to the sync model. Unlike normal ChangeProcessors, we need to | 84 // 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 | 85 // be able to access the sync model before the change processor begins |
77 // listening to changes (the local_service_ will be interacting with us | 86 // 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, | 87 // 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. | 88 // and have to keep a local pointer to the user_share. |
80 sync_api::UserShare* user_share_; | 89 sync_api::UserShare* share_handle_; |
90 | |
91 DISALLOW_COPY_AND_ASSIGN(GenericChangeProcessor); | |
81 }; | 92 }; |
82 | 93 |
83 } // namespace browser_sync | 94 } // namespace browser_sync |
84 | 95 |
85 #endif // CHROME_BROWSER_SYNC_GLUE_GENERIC_CHANGE_PROCESSOR_H_ | 96 #endif // CHROME_BROWSER_SYNC_GLUE_GENERIC_CHANGE_PROCESSOR_H_ |
OLD | NEW |