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

Side by Side Diff: chrome/browser/sync/glue/shared_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: Reffffactor 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
(Empty)
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
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 #pragma once
8
9 #include "base/location.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/synchronization/lock.h"
13 #include "base/threading/non_thread_safe.h"
14 #include "chrome/browser/sync/api/sync_change_processor.h"
15 #include "chrome/browser/sync/api/sync_error.h"
16 #include "chrome/browser/sync/engine/model_safe_worker.h"
17
18 class ProfileSyncService;
19 class SyncData;
20 class SyncableService;
21
22 typedef std::vector<SyncData> SyncDataList;
23
24 namespace browser_sync {
25
26 class GenericChangeProcessor;
27
28 // A ref-counted wrapper around a GenericChangeProcessor for use with datatypes
29 // that don't live on the UI thread.
30 //
31 // We need to make it refcounted as the ownership transfer from the
32 // DataTypeController is dependent on threading, and hence racy. The
33 // SharedChangeProcessor should be created on the UI thread, but should only be
34 // connected and used on the same thread as the datatype it interacts with.
35 //
36 // The only thread-safe methods is Disconnect, which will disconnect from the
akalin 2011/10/11 22:41:08 methods is -> method is
Nicolas Zea 2011/10/12 04:24:19 Done.
37 // generic change processor, letting us shut down the syncer/datatype without
38 // waiting for non-UI threads.
39 //
40 // Note: since we control the work being done while holding the lock, we ensure
41 // no I/O or other intensive work is done while blocking the UI thread (all
42 // the work is in-memory sync interactions).
43 class SharedChangeProcessor
44 : public base::RefCountedThreadSafe<SharedChangeProcessor>,
45 public base::NonThreadSafe {
akalin 2011/10/11 22:41:08 I don't think this class counts as NonThreadSafe.
Nicolas Zea 2011/10/12 04:24:19 Done.
46 public:
47 // Create a blank SharedChangeProcessor (to be later connected).
akalin 2011/10/11 22:41:08 blank -> disconnected?
Nicolas Zea 2011/10/12 04:24:19 No, once disconnected it can't be connected. This
48 SharedChangeProcessor();
49
50 // Connect to the GenericChangeProcessor provided. We take ownership of
51 // |generic_change_processor_| and delete on when disconnected or destroyed.
akalin 2011/10/11 22:41:08 on when -> when
Nicolas Zea 2011/10/12 04:24:19 Changed to take in the sync components and create
52 virtual void Connect(GenericChangeProcessor* generic_change_processor_);
akalin 2011/10/11 22:41:08 do any of these methods have to be virtual? Ah, I
Nicolas Zea 2011/10/12 04:24:19 Done.
53
54 // Disconnects from the generic change processor. May be called from any
55 // thread. After this, all attempts to interact with the change processor by
56 // |local_service_| are dropped and return errors. The syncer will be safe to
57 // shut down from the point of view of this datatype.
58 // Note: Once disconnected, you cannot reconnect without creating a new
59 // SharedChangeProcessor.
60 virtual void Disconnect();
61
62 // GenericChangeProcessor stubs (with disconnect support).
63 // Should only be called on the same thread the datatype resides.
64 virtual SyncError ProcessSyncChanges(
65 const tracked_objects::Location& from_here,
66 const SyncChangeList& change_list);
67 virtual SyncError GetSyncDataForType(syncable::ModelType type,
68 SyncDataList* current_sync_data);
69 virtual bool SyncModelHasUserCreatedNodes(syncable::ModelType type,
70 bool* has_nodes);
71 virtual bool CryptoReadyIfNecessary(syncable::ModelType type);
72
73 // Register |generic_change_processor_| as the change processor for
74 // |model_type| with the |sync_service|.
75 // Does nothing if |disconnected_| is true.
76 virtual void ActivateDataType(
77 ProfileSyncService* sync_service,
78 syncable::ModelType model_type,
79 browser_sync::ModelSafeGroup model_safe_group);
80
81 protected:
82 friend class base::RefCountedThreadSafe<SharedChangeProcessor>;
83 virtual ~SharedChangeProcessor();
84
85 private:
86 // Monitor lock for this object. All methods that interact with the change
87 // processor must aquire this lock and check whether we're disconnected or
88 // not. Once disconnected, all attempted changes to or loads from the change
89 // processor return errors. This enables us to shut down the syncer without
90 // having to wait for possibly non-UI thread datatypes to complete work.
91 mutable base::Lock monitor_lock_;
92 bool disconnected_;
93
94 scoped_ptr<GenericChangeProcessor> generic_change_processor_;
95
96 DISALLOW_COPY_AND_ASSIGN(SharedChangeProcessor);
97 };
98
99 } // namespace browser_sync
100
101 #endif // CHROME_BROWSER_SYNC_GLUE_SHARED_CHANGE_PROCESSOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698