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

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: Try harder trybot (rebase). 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/memory/weak_ptr.h"
13 #include "base/synchronization/lock.h"
14 #include "base/threading/thread_checker.h"
15 #include "chrome/browser/sync/api/sync_change_processor.h"
16 #include "chrome/browser/sync/api/sync_error.h"
17 #include "chrome/browser/sync/engine/model_safe_worker.h"
18
19 class ProfileSyncFactory;
20 class ProfileSyncService;
21 class SyncData;
22 class SyncableService;
23
24 typedef std::vector<SyncData> SyncDataList;
25
26 namespace browser_sync {
27
28 class UnrecoverableErrorHandler;
29
30 class GenericChangeProcessor;
31
32 // A ref-counted wrapper around a GenericChangeProcessor for use with datatypes
33 // that don't live on the UI thread.
34 //
35 // We need to make it refcounted as the ownership transfer from the
36 // DataTypeController is dependent on threading, and hence racy. The
37 // SharedChangeProcessor should be created on the UI thread, but should only be
38 // connected and used on the same thread as the datatype it interacts with.
39 //
40 // The only thread-safe method is Disconnect, which will disconnect from the
41 // generic change processor, letting us shut down the syncer/datatype without
42 // waiting for non-UI threads.
43 //
44 // Note: since we control the work being done while holding the lock, we ensure
45 // no I/O or other intensive work is done while blocking the UI thread (all
46 // the work is in-memory sync interactions).
47 //
48 // We use virtual methods so that we can use mock's in testing.
49 class SharedChangeProcessor
50 : public base::RefCountedThreadSafe<SharedChangeProcessor>,
51 public base::ThreadChecker {
52 public:
53 // Create an uninitialized SharedChangeProcessor (to be later connected).
54 SharedChangeProcessor();
55
56 // Connect to the Syncer. Will create and hold a new GenericChangeProcessor.
57 // Returns: true if successful, false if disconnected or |local_service| was
58 // NULL.
59 virtual bool Connect(
60 ProfileSyncFactory* sync_factory,
61 ProfileSyncService* sync_service,
62 UnrecoverableErrorHandler* error_handler,
63 const base::WeakPtr<SyncableService>& local_service);
64
65 // Disconnects from the generic change processor. May be called from any
66 // thread. After this, all attempts to interact with the change processor by
67 // |local_service_| are dropped and return errors. The syncer will be safe to
68 // shut down from the point of view of this datatype.
69 // Note: Once disconnected, you cannot reconnect without creating a new
70 // SharedChangeProcessor.
71 // Returns: true if we were previously succesfully connected, false if we were
72 // already disconnected.
73 virtual bool Disconnect();
74
75 // GenericChangeProcessor stubs (with disconnect support).
76 // Should only be called on the same thread the datatype resides.
77 virtual SyncError ProcessSyncChanges(
78 const tracked_objects::Location& from_here,
79 const SyncChangeList& change_list);
80 virtual SyncError GetSyncDataForType(syncable::ModelType type,
81 SyncDataList* current_sync_data);
82 virtual bool SyncModelHasUserCreatedNodes(syncable::ModelType type,
83 bool* has_nodes);
84 virtual bool CryptoReadyIfNecessary(syncable::ModelType type);
85
86 // Register |generic_change_processor_| as the change processor for
87 // |model_type| with the |sync_service|.
88 // Does nothing if |disconnected_| is true.
89 virtual void ActivateDataType(
90 ProfileSyncService* sync_service,
91 syncable::ModelType model_type,
92 browser_sync::ModelSafeGroup model_safe_group);
93
94 protected:
95 friend class base::RefCountedThreadSafe<SharedChangeProcessor>;
96 virtual ~SharedChangeProcessor();
97
98 private:
99 // Monitor lock for this object. All methods that interact with the change
100 // processor must aquire this lock and check whether we're disconnected or
101 // not. Once disconnected, all attempted changes to or loads from the change
102 // processor return errors. This enables us to shut down the syncer without
103 // having to wait for possibly non-UI thread datatypes to complete work.
104 mutable base::Lock monitor_lock_;
105 bool disconnected_;
106
107 scoped_ptr<GenericChangeProcessor> generic_change_processor_;
108
109 DISALLOW_COPY_AND_ASSIGN(SharedChangeProcessor);
110 };
111
112 } // namespace browser_sync
113
114 #endif // CHROME_BROWSER_SYNC_GLUE_SHARED_CHANGE_PROCESSOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698