Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(181)

Side by Side Diff: chrome/browser/sync/glue/generic_change_processor.h

Issue 8065016: [Sync] Refactor non-frontend DTC to handle new API properly. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase and self review Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/threading/non_thread_safe.h"
12 #include "chrome/browser/sync/api/sync_change_processor.h" 13 #include "chrome/browser/sync/api/sync_change_processor.h"
13 #include "chrome/browser/sync/glue/change_processor.h" 14 #include "chrome/browser/sync/glue/change_processor.h"
14 15
15 class SyncData; 16 class SyncData;
16 class SyncableService; 17 class SyncableService;
17 18
18 typedef std::vector<SyncData> SyncDataList; 19 typedef std::vector<SyncData> SyncDataList;
19 20
20 namespace browser_sync { 21 namespace browser_sync {
21 22
22 // TODO(sync): deprecate all change processors and have them replaced by 23 // TODO(sync): deprecate all change processors and have them replaced by
23 // instances of this. 24 // instances of this.
24 // Datatype agnostic change processor. One instance of GenericChangeProcessor 25 // Datatype agnostic change processor. One instance of GenericChangeProcessor
25 // is created for each datatype and lives on the datatype's thread. It then 26 // 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 27 // 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 // 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 // which then get converted into SyncChange's and sent to the local service.
30 //
31 // As a rule, the GenericChangeProcessor is not thread safe, and should only
32 // be used on the same thread in which it was created.
29 class GenericChangeProcessor : public ChangeProcessor, 33 class GenericChangeProcessor : public ChangeProcessor,
30 public SyncChangeProcessor { 34 public SyncChangeProcessor,
35 public base::NonThreadSafe {
31 public: 36 public:
32 GenericChangeProcessor(SyncableService* local_service, 37 // Create a change processor and connect it to the syncer.
33 UnrecoverableErrorHandler* error_handler, 38 GenericChangeProcessor(UnrecoverableErrorHandler* error_handler,
39 SyncableService* local_service,
34 sync_api::UserShare* user_share); 40 sync_api::UserShare* user_share);
35 virtual ~GenericChangeProcessor(); 41 virtual ~GenericChangeProcessor() OVERRIDE;
36 42
37 // ChangeProcessor interface. 43 // ChangeProcessor interface.
38 // Build and store a list of all changes into |syncer_changes_|. 44 // Build and store a list of all changes into |syncer_changes_|.
39 virtual void ApplyChangesFromSyncModel( 45 virtual void ApplyChangesFromSyncModel(
40 const sync_api::BaseTransaction* trans, 46 const sync_api::BaseTransaction* trans,
41 const sync_api::ImmutableChangeRecordList& changes) OVERRIDE; 47 const sync_api::ImmutableChangeRecordList& changes) OVERRIDE;
42 // Passes |syncer_changes_|, built in ApplyChangesFromSyncModel, onto 48 // Passes |syncer_changes_|, built in ApplyChangesFromSyncModel, onto
43 // |local_service_| by way of it's ProcessSyncChanges method. 49 // |local_service_| by way of it's ProcessSyncChanges method.
44 virtual void CommitChangesFromSyncModel() OVERRIDE; 50 virtual void CommitChangesFromSyncModel() OVERRIDE;
45 51
46 // SyncChangeProcessor implementation. 52 // SyncChangeProcessor implementation.
47 virtual SyncError ProcessSyncChanges( 53 virtual SyncError ProcessSyncChanges(
48 const tracked_objects::Location& from_here, 54 const tracked_objects::Location& from_here,
49 const SyncChangeList& change_list) OVERRIDE; 55 const SyncChangeList& change_list) OVERRIDE;
50 56
51 // Fills |current_sync_data| with all the syncer data for the specified type. 57 // Fills |current_sync_data| with all the syncer data for the specified type.
52 virtual SyncError GetSyncDataForType(syncable::ModelType type, 58 virtual SyncError GetSyncDataForType(syncable::ModelType type,
53 SyncDataList* current_sync_data); 59 SyncDataList* current_sync_data);
54 60
55 // Generic versions of AssociatorInterface methods. Called by 61 // Generic versions of AssociatorInterface methods. Called by
56 // SyncableServiceAdapter. 62 // SyncableServiceAdapter or the DataTypeController.
57 bool SyncModelHasUserCreatedNodes(syncable::ModelType type, 63 virtual bool SyncModelHasUserCreatedNodes(syncable::ModelType type,
58 bool* has_nodes); 64 bool* has_nodes);
59 bool CryptoReadyIfNecessary(syncable::ModelType type); 65 virtual bool CryptoReadyIfNecessary(syncable::ModelType type);
66
60 protected: 67 protected:
68 // Create an uninitialized change processor.
69 explicit GenericChangeProcessor(UnrecoverableErrorHandler* error_handler);
70
71 virtual void set_local_service(SyncableService* local_service);
72 virtual SyncableService* local_service() const;
73 virtual void set_share_handle(sync_api::UserShare* user_share);
74
61 // ChangeProcessor interface. 75 // ChangeProcessor interface.
62 virtual void StartImpl(Profile* profile) OVERRIDE; // Not implemented. 76 virtual void StartImpl(Profile* profile) OVERRIDE; // Does nothing.
63 virtual void StopImpl() OVERRIDE; // Not implemented. 77 virtual void StopImpl() OVERRIDE; // Does nothing.
64 virtual sync_api::UserShare* share_handle() OVERRIDE; 78 virtual sync_api::UserShare* share_handle() const OVERRIDE;
79
65 private: 80 private:
66 // The SyncableService this change processor will forward changes on to. 81 // The SyncableService this change processor will forward changes on to.
67 SyncableService* local_service_; 82 SyncableService* local_service_;
68 83
69 // The current list of changes received from the syncer. We buffer because 84 // 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 85 // we must ensure no syncapi transaction is held when we pass it on to
71 // |local_service_|. 86 // |local_service_|.
72 // Set in ApplyChangesFromSyncModel, consumed in CommitChangesFromSyncModel. 87 // Set in ApplyChangesFromSyncModel, consumed in CommitChangesFromSyncModel.
73 SyncChangeList syncer_changes_; 88 SyncChangeList syncer_changes_;
74 89
75 // Our handle to the sync model. Unlike normal ChangeProcessors, we need to 90 // 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 91 // be able to access the sync model before the change processor begins
77 // listening to changes (the local_service_ will be interacting with us 92 // 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, 93 // 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. 94 // and have to keep a local pointer to the user_share.
80 sync_api::UserShare* user_share_; 95 sync_api::UserShare* share_handle_;
96
97 DISALLOW_COPY_AND_ASSIGN(GenericChangeProcessor);
81 }; 98 };
82 99
83 } // namespace browser_sync 100 } // namespace browser_sync
84 101
85 #endif // CHROME_BROWSER_SYNC_GLUE_GENERIC_CHANGE_PROCESSOR_H_ 102 #endif // CHROME_BROWSER_SYNC_GLUE_GENERIC_CHANGE_PROCESSOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698