Supervised user import: Listen for profile creation/deletion
[chromium-blink-merge.git] / components / sync_driver / change_processor.h
blob30762be63d08db12c63e20dd9b9046ba19308cf3
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_SYNC_DRIVER_CHANGE_PROCESSOR_H_
6 #define COMPONENTS_SYNC_DRIVER_CHANGE_PROCESSOR_H_
8 #include "components/sync_driver/data_type_error_handler.h"
9 #include "sync/internal_api/public/base_transaction.h"
10 #include "sync/internal_api/public/change_record.h"
11 #include "sync/internal_api/public/user_share.h"
13 namespace syncer {
14 class UnrecoverableErrorHandler;
15 } // namespace syncer
17 namespace sync_driver {
19 class ModelAssociator;
21 // An interface used to apply changes from the sync model to the browser's
22 // native model. This does not currently distinguish between model data types.
23 class ChangeProcessor {
24 public:
25 explicit ChangeProcessor(DataTypeErrorHandler* error_handler);
26 virtual ~ChangeProcessor();
28 // Call when the processor should accept changes from either provided model
29 // and apply them to the other. Both the native model and sync_api are
30 // expected to be initialized and loaded. You must have set a valid
31 // ModelAssociator and UnrecoverableErrorHandler before using this method, and
32 // the two models should be associated w.r.t the ModelAssociator provided.
33 void Start(syncer::UserShare* share_handle);
35 // Changes have been applied to the backend model and are ready to be
36 // applied to the frontend model.
37 virtual void ApplyChangesFromSyncModel(
38 const syncer::BaseTransaction* trans,
39 int64 model_version,
40 const syncer::ImmutableChangeRecordList& changes) = 0;
42 // The changes found in ApplyChangesFromSyncModel may be too slow to be
43 // performed while holding a [Read/Write]Transaction lock or may interact
44 // with another thread, which might itself be waiting on the transaction lock,
45 // putting us at risk of deadlock.
46 // This function is called once the transactional lock is released and it is
47 // safe to perform inter-thread or slow I/O operations. Note that not all
48 // datatypes need this, so we provide an empty default version.
49 virtual void CommitChangesFromSyncModel();
51 // This ensures that startobserving gets called after stopobserving even
52 // if there is an early return in the function.
53 template <class T>
54 class ScopedStopObserving {
55 public:
56 explicit ScopedStopObserving(T* processor)
57 : processor_(processor) {
58 processor_->StopObserving();
60 ~ScopedStopObserving() {
61 processor_->StartObserving();
64 private:
65 ScopedStopObserving() {}
66 T* processor_;
69 protected:
70 // These methods are invoked by Start() and Stop() to do
71 // implementation-specific work.
72 virtual void StartImpl() = 0;
74 DataTypeErrorHandler* error_handler() const;
75 virtual syncer::UserShare* share_handle() const;
77 private:
78 DataTypeErrorHandler* error_handler_; // Guaranteed to outlive us.
80 // The sync model we are processing changes from.
81 syncer::UserShare* share_handle_;
83 DISALLOW_COPY_AND_ASSIGN(ChangeProcessor);
86 } // namespace sync_driver
88 #endif // COMPONENTS_SYNC_DRIVER_CHANGE_PROCESSOR_H_