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 SYNC_ENGINE_NON_BLOCKING_TYPE_PROCESSOR_H_
6 #define SYNC_ENGINE_NON_BLOCKING_TYPE_PROCESSOR_H_
8 #include "base/memory/weak_ptr.h"
9 #include "base/sequenced_task_runner.h"
10 #include "base/threading/non_thread_safe.h"
11 #include "sync/base/sync_export.h"
12 #include "sync/internal_api/public/base/model_type.h"
13 #include "sync/protocol/sync.pb.h"
18 class NonBlockingTypeProcessorCore;
20 // A sync component embedded on the synced type's thread that helps to handle
21 // communication between sync and model type threads.
22 class SYNC_EXPORT_PRIVATE NonBlockingTypeProcessor : base::NonThreadSafe {
24 NonBlockingTypeProcessor(ModelType type);
25 virtual ~NonBlockingTypeProcessor();
27 // Returns true if this object believes that sync is preferred for this type.
29 // By "preferred", we mean that a policy decision has been made that this
30 // type should be synced. Most of the time this is controlled by a user
31 // clicking a checkbox on the settings page.
33 // The canonical preferred state is based on SyncPrefs on the UI thread. At
34 // best, this value is stale and may lag behind the one set on the UI thread.
35 // Before this type has registered with the UI thread, it's mostly just an
37 bool IsPreferred() const;
39 // Returns true if the handshake with sync thread is complete.
40 bool IsConnected() const;
42 // Returns the model type handled by this processor.
43 ModelType GetModelType() const;
45 // Starts the handshake with the sync thread.
46 void Enable(SyncCoreProxy* core_proxy);
48 // Severs all ties to the sync thread and may delete local sync state.
49 // Another call to Enable() can be used to re-establish this connection.
52 // Severs all ties to the sync thread.
53 // Another call to Enable() can be used to re-establish this connection.
56 // Callback used to process the handshake response.
57 void OnConnect(base::WeakPtr<NonBlockingTypeProcessorCore> core,
58 scoped_refptr<base::SequencedTaskRunner> sync_thread);
60 base::WeakPtr<NonBlockingTypeProcessor> AsWeakPtr();
64 sync_pb::DataTypeProgressMarker progress_marker_;
66 // Whether or not sync is preferred for this type. This is a cached copy of
67 // the canonical copy information on the UI thread.
70 // Whether or not this object has completed its initial handshake with the
74 base::WeakPtr<NonBlockingTypeProcessorCore> core_;
75 scoped_refptr<base::SequencedTaskRunner> sync_thread_;
77 base::WeakPtrFactory<NonBlockingTypeProcessor> weak_ptr_factory_;
82 #endif // SYNC_ENGINE_NON_BLOCKING_TYPE_PROCESSOR_H_