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

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

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