summaryrefslogtreecommitdiffstats
path: root/sync/internal_api/public
diff options
context:
space:
mode:
authorrlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-27 17:13:43 +0000
committerrlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-27 17:13:43 +0000
commitbd7c4fda2b543725ec3ab29952d64674d86d6b27 (patch)
tree2707e3dfc1c1e04fbf6b07e87053a2bac48cafec /sync/internal_api/public
parent6c8715d3e19279d7b28be72c703d1af8fbfef80c (diff)
downloadchromium_src-bd7c4fda2b543725ec3ab29952d64674d86d6b27.zip
chromium_src-bd7c4fda2b543725ec3ab29952d64674d86d6b27.tar.gz
chromium_src-bd7c4fda2b543725ec3ab29952d64674d86d6b27.tar.bz2
sync: Add NonBlockingTypeProcesssor and SyncCore
Introduces the model-thread sibling of the NonBlockingTypeProcessorCore that was added in r258390. Also adds SyncCore and SyncCoreProxy, the classes that will be used to connect the two. The SyncCore lives on the sync thread and carries out requests sent to it by the SyncCoreProxy. The SyncCoreProxy is a thread-safe wrapper around the SyncCore that can be easily copied and whose methods can be called from any thread. The NonBlockingTypeProcessor is instantiated on the same thread as the data to be synced. It connects to a NonBlockingTypeProcessorCore on the sync thread by sending a request through a SyncCoreProxy. Keeping data in sync will be a collaborative effort involving both the NonBlockingTypeProcessor and NonBlockingTypeProcesssorCore, though none of this functionality has been implemented yet. As of this CL, none these classes are instantiated outside of tests. This CL should have no effect on current sync behavior. BUG=351005 Review URL: https://codereview.chromium.org/208893004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@259921 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync/internal_api/public')
-rw-r--r--sync/internal_api/public/non_blocking_type_processor.h60
-rw-r--r--sync/internal_api/public/sync_core_proxy.h55
-rw-r--r--sync/internal_api/public/sync_manager.h8
-rw-r--r--sync/internal_api/public/test/fake_sync_manager.h1
4 files changed, 122 insertions, 2 deletions
diff --git a/sync/internal_api/public/non_blocking_type_processor.h b/sync/internal_api/public/non_blocking_type_processor.h
new file mode 100644
index 0000000..a9079d5a
--- /dev/null
+++ b/sync/internal_api/public/non_blocking_type_processor.h
@@ -0,0 +1,60 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SYNC_ENGINE_NON_BLOCKING_TYPE_PROCESSOR_H_
+#define SYNC_ENGINE_NON_BLOCKING_TYPE_PROCESSOR_H_
+
+#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
+#include "base/sequenced_task_runner.h"
+#include "base/threading/non_thread_safe.h"
+#include "sync/base/sync_export.h"
+#include "sync/internal_api/public/base/model_type.h"
+#include "sync/internal_api/public/sync_core_proxy.h"
+#include "sync/protocol/sync.pb.h"
+
+namespace syncer {
+
+class NonBlockingTypeProcessorCore;
+
+// A sync component embedded on the synced type's thread that helps to handle
+// communication between sync and model type threads.
+class SYNC_EXPORT_PRIVATE NonBlockingTypeProcessor : base::NonThreadSafe {
+ public:
+ NonBlockingTypeProcessor(ModelType type);
+ virtual ~NonBlockingTypeProcessor();
+
+ // Returns true if the handshake with sync thread is complete.
+ bool IsEnabled() const;
+
+ // Returns the model type handled by this processor.
+ ModelType GetModelType() const;
+
+ // Starts the handshake with the sync thread.
+ void Enable(SyncCoreProxy core_proxy_);
+
+ // Severs all ties to the sync thread.
+ // Another call to Enable() can be used to re-establish this connection.
+ void Disable();
+
+ // Callback used to process the handshake response.
+ void OnConnect(base::WeakPtr<NonBlockingTypeProcessorCore> core,
+ scoped_refptr<base::SequencedTaskRunner> sync_thread);
+
+ base::WeakPtr<NonBlockingTypeProcessor> AsWeakPtr();
+
+ private:
+ ModelType type_;
+ sync_pb::DataTypeProgressMarker progress_marker_;
+ bool enabled_;
+
+ base::WeakPtr<NonBlockingTypeProcessorCore> core_;
+ scoped_refptr<base::SequencedTaskRunner> sync_thread_;
+
+ base::WeakPtrFactory<NonBlockingTypeProcessor> weak_ptr_factory_;
+};
+
+} // namespace syncer
+
+#endif // SYNC_ENGINE_NON_BLOCKING_TYPE_PROCESSOR_H_
diff --git a/sync/internal_api/public/sync_core_proxy.h b/sync/internal_api/public/sync_core_proxy.h
new file mode 100644
index 0000000..dd5a4ac
--- /dev/null
+++ b/sync/internal_api/public/sync_core_proxy.h
@@ -0,0 +1,55 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SYNC_INTERNAL_API_PUBLIC_SYNC_CORE_PROXY_H_
+#define SYNC_INTERNAL_API_PUBLIC_SYNC_CORE_PROXY_H_
+
+#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
+#include "base/sequenced_task_runner.h"
+#include "sync/base/sync_export.h"
+#include "sync/internal_api/public/base/model_type.h"
+
+namespace syncer {
+
+class SyncCore;
+class NonBlockingTypeProcessor;
+
+// Encapsulates a reference to the sync core and the thread it's running on.
+// Used by sync's data types to connect with the sync core.
+//
+// It is epxected that this object will be copied to and used on many different
+// threads. It is small and safe to pass by value.
+class SYNC_EXPORT_PRIVATE SyncCoreProxy {
+ public:
+ SyncCoreProxy(
+ scoped_refptr<base::SequencedTaskRunner> sync_task_runner,
+ base::WeakPtr<SyncCore> sync_core);
+ ~SyncCoreProxy();
+
+ // Attempts to connect a non-blocking type to the sync core.
+ //
+ // This may fail under some unusual circumstances, like shutdown. Due to the
+ // nature of WeakPtrs and cross-thread communication, the caller will be
+ // unable to distinguish a slow success from failure.
+ //
+ // Must be called from the thread where the data type lives.
+ void ConnectTypeToCore(
+ syncer::ModelType type,
+ base::WeakPtr<NonBlockingTypeProcessor> type_processor);
+
+ // Constructs and returns a useless instance of this object.
+ static SyncCoreProxy GetInvalidSyncCoreProxyForTest();
+
+ private:
+ // A SequencedTaskRunner representing the thread where the SyncCore lives.
+ scoped_refptr<base::SequencedTaskRunner> sync_task_runner_;
+
+ // The SyncCore this object is wrapping.
+ base::WeakPtr<SyncCore> sync_core_;
+};
+
+} // namespace syncer
+
+#endif // SYNC_INTERNAL_API_PUBLIC_SYNC_CORE_PROXY_H_
diff --git a/sync/internal_api/public/sync_manager.h b/sync/internal_api/public/sync_manager.h
index 6f6d9fc..38bad07 100644
--- a/sync/internal_api/public/sync_manager.h
+++ b/sync/internal_api/public/sync_manager.h
@@ -35,19 +35,20 @@ class EncryptedData;
namespace syncer {
class BaseTransaction;
+class CancelationSignal;
class DataTypeDebugInfoListener;
class Encryptor;
-struct Experiments;
class ExtensionsActivity;
class HttpPostProviderFactory;
class InternalComponentsFactory;
class JsBackend;
class JsEventHandler;
+class SyncCore;
class SyncEncryptionHandler;
class ProtocolEvent;
class SyncScheduler;
+struct Experiments;
struct UserShare;
-class CancelationSignal;
namespace sessions {
class SyncSessionSnapshot;
@@ -331,6 +332,9 @@ class SYNC_EXPORT SyncManager : public syncer::InvalidationHandler {
// May be called from any thread.
virtual UserShare* GetUserShare() = 0;
+ // Returns an instance of the main interface for non-blocking sync types.
+ virtual syncer::SyncCore* GetSyncCore() = 0;
+
// Returns the cache_guid of the currently open database.
// Requires that the SyncManager be initialized.
virtual const std::string cache_guid() = 0;
diff --git a/sync/internal_api/public/test/fake_sync_manager.h b/sync/internal_api/public/test/fake_sync_manager.h
index 1194399..81b7160 100644
--- a/sync/internal_api/public/test/fake_sync_manager.h
+++ b/sync/internal_api/public/test/fake_sync_manager.h
@@ -119,6 +119,7 @@ class FakeSyncManager : public SyncManager {
virtual void SaveChanges() OVERRIDE;
virtual void ShutdownOnSyncThread() OVERRIDE;
virtual UserShare* GetUserShare() OVERRIDE;
+ virtual syncer::SyncCore* GetSyncCore() OVERRIDE;
virtual const std::string cache_guid() OVERRIDE;
virtual bool ReceivedExperiment(Experiments* experiments) OVERRIDE;
virtual bool HasUnsyncedItems() OVERRIDE;