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

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

Issue 303263002: sync: move SharedChangeProcessor to components/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review Created 6 years, 6 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
(Empty)
1 // Copyright (c) 2012 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.
4
5 #ifndef CHROME_BROWSER_SYNC_GLUE_SHARED_CHANGE_PROCESSOR_H_
6 #define CHROME_BROWSER_SYNC_GLUE_SHARED_CHANGE_PROCESSOR_H_
7
8 #include "base/location.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/weak_ptr.h"
11 #include "base/message_loop/message_loop_proxy.h"
12 #include "base/synchronization/lock.h"
13 #include "components/sync_driver/data_type_error_handler.h"
14 #include "sync/api/sync_change_processor.h"
15 #include "sync/api/sync_data.h"
16 #include "sync/api/sync_error.h"
17 #include "sync/api/sync_error_factory.h"
18 #include "sync/api/sync_merge_result.h"
19 #include "sync/internal_api/public/engine/model_safe_worker.h"
20
21 class ProfileSyncService;
22
23 namespace syncer {
24 class SyncableService;
25 struct UserShare;
26 } // namespace syncer
27
28 namespace browser_sync {
29
30 class ChangeProcessor;
31 class GenericChangeProcessor;
32 class GenericChangeProcessorFactory;
33 class DataTypeErrorHandler;
34 class SyncApiComponentFactory;
35
36 // A ref-counted wrapper around a GenericChangeProcessor for use with datatypes
37 // that don't live on the UI thread.
38 //
39 // We need to make it refcounted as the ownership transfer from the
40 // DataTypeController is dependent on threading, and hence racy. The
41 // SharedChangeProcessor should be created on the UI thread, but should only be
42 // connected and used on the same thread as the datatype it interacts with.
43 //
44 // The only thread-safe method is Disconnect, which will disconnect from the
45 // generic change processor, letting us shut down the syncer/datatype without
46 // waiting for non-UI threads.
47 //
48 // Note: since we control the work being done while holding the lock, we ensure
49 // no I/O or other intensive work is done while blocking the UI thread (all
50 // the work is in-memory sync interactions).
51 //
52 // We use virtual methods so that we can use mock's in testing.
53 class SharedChangeProcessor
54 : public base::RefCountedThreadSafe<SharedChangeProcessor> {
55 public:
56 // Create an uninitialized SharedChangeProcessor.
57 SharedChangeProcessor();
58
59 // Connect to the Syncer and prepare to handle changes for |type|. Will
60 // create and store a new GenericChangeProcessor and return a weak pointer to
61 // the syncer::SyncableService associated with |type|.
62 // Note: If this SharedChangeProcessor has been disconnected, or the
63 // syncer::SyncableService was not alive, will return a null weak pointer.
64 virtual base::WeakPtr<syncer::SyncableService> Connect(
65 browser_sync::SyncApiComponentFactory* sync_factory,
66 GenericChangeProcessorFactory* processor_factory,
67 syncer::UserShare* user_share,
68 DataTypeErrorHandler* error_handler,
69 syncer::ModelType type,
70 const base::WeakPtr<syncer::SyncMergeResult>& merge_result);
71
72 // Disconnects from the generic change processor. May be called from any
73 // thread. After this, all attempts to interact with the change processor by
74 // |local_service_| are dropped and return errors. The syncer will be safe to
75 // shut down from the point of view of this datatype.
76 // Note: Once disconnected, you cannot reconnect without creating a new
77 // SharedChangeProcessor.
78 // Returns: true if we were previously succesfully connected, false if we were
79 // already disconnected.
80 virtual bool Disconnect();
81
82 // GenericChangeProcessor stubs (with disconnect support).
83 // Should only be called on the same thread the datatype resides.
84 virtual int GetSyncCount();
85 virtual syncer::SyncError ProcessSyncChanges(
86 const tracked_objects::Location& from_here,
87 const syncer::SyncChangeList& change_list);
88 virtual syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const;
89 virtual syncer::SyncError GetAllSyncDataReturnError(
90 syncer::ModelType type,
91 syncer::SyncDataList* data) const;
92 virtual syncer::SyncError UpdateDataTypeContext(
93 syncer::ModelType type,
94 syncer::SyncChangeProcessor::ContextRefreshStatus refresh_status,
95 const std::string& context);
96 virtual bool SyncModelHasUserCreatedNodes(bool* has_nodes);
97 virtual bool CryptoReadyIfNecessary();
98
99 // If a datatype context associated with the current type exists, fills
100 // |context| and returns true. Otheriwse, if there has not been a context
101 // set, returns false.
102 virtual bool GetDataTypeContext(std::string* context) const;
103
104 virtual syncer::SyncError CreateAndUploadError(
105 const tracked_objects::Location& location,
106 const std::string& message);
107
108 ChangeProcessor* generic_change_processor();
109
110 protected:
111 friend class base::RefCountedThreadSafe<SharedChangeProcessor>;
112 virtual ~SharedChangeProcessor();
113
114 private:
115 // Monitor lock for this object. All methods that interact with the change
116 // processor must aquire this lock and check whether we're disconnected or
117 // not. Once disconnected, all attempted changes to or loads from the change
118 // processor return errors. This enables us to shut down the syncer without
119 // having to wait for possibly non-UI thread datatypes to complete work.
120 mutable base::Lock monitor_lock_;
121 bool disconnected_;
122
123 // The sync datatype we were last connected to.
124 syncer::ModelType type_;
125
126 // The frontend / UI MessageLoop this object is constructed on. May also be
127 // destructed and/or disconnected on this loop, see ~SharedChangeProcessor.
128 const scoped_refptr<const base::MessageLoopProxy> frontend_loop_;
129
130 // The loop that all methods except the constructor, destructor, and
131 // Disconnect() should be called on. Set in Connect().
132 scoped_refptr<base::MessageLoopProxy> backend_loop_;
133
134 // Used only on |backend_loop_|.
135 GenericChangeProcessor* generic_change_processor_;
136
137 DataTypeErrorHandler* error_handler_;
138
139 DISALLOW_COPY_AND_ASSIGN(SharedChangeProcessor);
140 };
141
142 } // namespace browser_sync
143
144 #endif // CHROME_BROWSER_SYNC_GLUE_SHARED_CHANGE_PROCESSOR_H_
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/non_ui_data_type_controller.cc ('k') | chrome/browser/sync/glue/shared_change_processor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698