summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-26 18:34:30 +0000
committerrlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-26 18:34:30 +0000
commit35a317204e3c4ec6165fc8125670d0d9af312be1 (patch)
tree7abee14a047ab7928ef1812cfa2373c1173f2a79
parent9f3f286a4c0246ff07386f86820cd1d32d56e377 (diff)
downloadchromium_src-35a317204e3c4ec6165fc8125670d0d9af312be1.zip
chromium_src-35a317204e3c4ec6165fc8125670d0d9af312be1.tar.gz
chromium_src-35a317204e3c4ec6165fc8125670d0d9af312be1.tar.bz2
sync: Introduce CryptographerProvider interface
Creates a CryptographerProvider interface that can be used to expose the syncable::Directory's Cryptographer without exposing the directory itself. Since the directory's cryptographer is protected by a lock, this requires the creation of several helper classes to manage the acquistion of the lock. This CL includes the interface, an implementationthat exposes the directory's cryptographer (DirectoryCryptographerProvider) and a SimpleCryptographerProvider that wraps a non-owned Cryptographer for testing purposes. These interfaces will be used to implement and test encryption of non-blocking sync types. BUG=351005 Review URL: https://codereview.chromium.org/413833002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@285777 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--sync/engine/cryptographer_provider.cc42
-rw-r--r--sync/engine/cryptographer_provider.h64
-rw-r--r--sync/engine/directory_cryptographer_provider.cc38
-rw-r--r--sync/engine/directory_cryptographer_provider.h51
-rw-r--r--sync/sync_core.gypi4
-rw-r--r--sync/sync_tests.gypi2
-rw-r--r--sync/test/engine/simple_cryptographer_provider.cc35
-rw-r--r--sync/test/engine/simple_cryptographer_provider.h44
8 files changed, 280 insertions, 0 deletions
diff --git a/sync/engine/cryptographer_provider.cc b/sync/engine/cryptographer_provider.cc
new file mode 100644
index 0000000..2c16bc4
--- /dev/null
+++ b/sync/engine/cryptographer_provider.cc
@@ -0,0 +1,42 @@
+// 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.
+
+#include "sync/engine/cryptographer_provider.h"
+
+namespace syncer {
+
+CryptographerProvider::CryptographerProvider() {
+}
+
+CryptographerProvider::~CryptographerProvider() {
+}
+
+ScopedCryptographerRef::ScopedCryptographerRef() {
+}
+
+ScopedCryptographerRef::~ScopedCryptographerRef() {
+}
+
+bool ScopedCryptographerRef::Initialize(ScopedCryptographerInternal* impl) {
+ scoped_cryptographer_internal_.reset(impl);
+ return IsValid();
+}
+
+bool ScopedCryptographerRef::IsValid() const {
+ return !!Get();
+}
+
+Cryptographer* ScopedCryptographerRef::Get() const {
+ if (!scoped_cryptographer_internal_)
+ return NULL;
+ return scoped_cryptographer_internal_->Get();
+}
+
+ScopedCryptographerInternal::ScopedCryptographerInternal() {
+}
+
+ScopedCryptographerInternal::~ScopedCryptographerInternal() {
+}
+
+} // namespace syncer
diff --git a/sync/engine/cryptographer_provider.h b/sync/engine/cryptographer_provider.h
new file mode 100644
index 0000000..f38bd185
--- /dev/null
+++ b/sync/engine/cryptographer_provider.h
@@ -0,0 +1,64 @@
+// 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_CRYPTOGRAPHER_PROVIDER_H_
+#define SYNC_ENGINE_CRYPTOGRAPHER_PROVIDER_H_
+
+#include "base/memory/scoped_ptr.h"
+#include "sync/base/sync_export.h"
+
+namespace syncer {
+
+class Cryptographer;
+class ScopedCryptographerRef;
+class ScopedCryptographerInternal;
+
+// An interface for providing clients with a ScopedCryptographerRef.
+//
+// Used to expose the syncable::Directory's cryptographer to clients that
+// would otherwise not have access to the Directory.
+class SYNC_EXPORT_PRIVATE CryptographerProvider {
+ public:
+ CryptographerProvider();
+ virtual ~CryptographerProvider();
+
+ virtual bool InitScopedCryptographerRef(ScopedCryptographerRef* scoped) = 0;
+};
+
+// A concrete class representing a reference to a cryptographer.
+//
+// Access to the cryptographer is lost when this class goes out of scope.
+class SYNC_EXPORT_PRIVATE ScopedCryptographerRef {
+ public:
+ ScopedCryptographerRef();
+ ~ScopedCryptographerRef();
+
+ bool Initialize(ScopedCryptographerInternal* impl);
+ bool IsValid() const;
+ Cryptographer* Get() const;
+
+ private:
+ scoped_ptr<ScopedCryptographerInternal> scoped_cryptographer_internal_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScopedCryptographerRef);
+};
+
+// An interface class used in the implementation of the ScopedCryptographerRef.
+//
+// We use this class to allow different implementations of
+// CryptographerProvider to implement InitScopedCryptographer in different
+// ways. The ScopedCryptographerRef itself must be stack-allocated, so it
+// can't vary depending on which kind of CryptographerProvider is used to
+// intialize it.
+class SYNC_EXPORT_PRIVATE ScopedCryptographerInternal {
+ public:
+ ScopedCryptographerInternal();
+ virtual ~ScopedCryptographerInternal();
+
+ virtual Cryptographer* Get() const = 0;
+};
+
+} // namespace syncer
+
+#endif // SYNC_ENGINE_CRYPTOGRAPHER_PROVIDER_H_
diff --git a/sync/engine/directory_cryptographer_provider.cc b/sync/engine/directory_cryptographer_provider.cc
new file mode 100644
index 0000000..a9cd2a2
--- /dev/null
+++ b/sync/engine/directory_cryptographer_provider.cc
@@ -0,0 +1,38 @@
+// 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.
+
+#include "sync/engine/directory_cryptographer_provider.h"
+
+#include "sync/syncable/directory.h"
+#include "sync/syncable/syncable_read_transaction.h"
+
+namespace syncer {
+
+DirectoryCryptographerProvider::DirectoryCryptographerProvider(
+ syncable::Directory* dir)
+ : dir_(dir) {
+}
+
+DirectoryCryptographerProvider::~DirectoryCryptographerProvider() {
+}
+
+bool DirectoryCryptographerProvider::InitScopedCryptographerRef(
+ ScopedCryptographerRef* scoped) {
+ scoped->Initialize(new ScopedDirectoryCryptographerInternal(dir_));
+ return scoped->IsValid();
+}
+
+ScopedDirectoryCryptographerInternal::ScopedDirectoryCryptographerInternal(
+ syncable::Directory* dir)
+ : dir_(dir), trans_(FROM_HERE, dir) {
+}
+
+ScopedDirectoryCryptographerInternal::~ScopedDirectoryCryptographerInternal() {
+}
+
+Cryptographer* ScopedDirectoryCryptographerInternal::Get() const {
+ return dir_->GetCryptographer(&trans_);
+}
+
+} // namespace syncer
diff --git a/sync/engine/directory_cryptographer_provider.h b/sync/engine/directory_cryptographer_provider.h
new file mode 100644
index 0000000..36b1c0f
--- /dev/null
+++ b/sync/engine/directory_cryptographer_provider.h
@@ -0,0 +1,51 @@
+// 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_DIRECTORY_CRYPTOGRAPHER_PROVIDER_H_
+#define SYNC_ENGINE_DIRECTORY_CRYPTOGRAPHER_PROVIDER_H_
+
+#include "sync/engine/cryptographer_provider.h"
+
+#include "sync/syncable/syncable_read_transaction.h"
+
+namespace syncer {
+
+namespace syncable {
+class Directory;
+}
+
+// Provides access to the Directory's cryptographer through the
+// CryptographerProvider interface.
+class DirectoryCryptographerProvider : public CryptographerProvider {
+ public:
+ DirectoryCryptographerProvider(syncable::Directory* dir);
+ virtual ~DirectoryCryptographerProvider();
+
+ virtual bool InitScopedCryptographerRef(
+ ScopedCryptographerRef* scoped) OVERRIDE;
+
+ private:
+ syncable::Directory* dir_;
+};
+
+// An implementation detail of the DirectoryCryptographerProvider. Contains
+// the ReadTransaction used to safely access the Cryptographer.
+class ScopedDirectoryCryptographerInternal
+ : public ScopedCryptographerInternal {
+ public:
+ ScopedDirectoryCryptographerInternal(syncable::Directory* dir);
+ virtual ~ScopedDirectoryCryptographerInternal();
+
+ virtual Cryptographer* Get() const OVERRIDE;
+
+ private:
+ syncable::Directory* dir_;
+ syncable::ReadTransaction trans_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScopedDirectoryCryptographerInternal);
+};
+
+} // namespace syncer
+
+#endif // SYNC_ENGINE_DIRECTORY_CRYPTOGRAPHER_PROVIDER_H_
diff --git a/sync/sync_core.gypi b/sync/sync_core.gypi
index 0474fd4..3f4631f 100644
--- a/sync/sync_core.gypi
+++ b/sync/sync_core.gypi
@@ -48,10 +48,14 @@
'engine/conflict_resolver.h',
'engine/conflict_util.cc',
'engine/conflict_util.h',
+ 'engine/cryptographer_provider.cc',
+ 'engine/cryptographer_provider.h',
'engine/directory_commit_contribution.cc',
'engine/directory_commit_contribution.h',
'engine/directory_commit_contributor.cc',
'engine/directory_commit_contributor.h',
+ 'engine/directory_cryptographer_provider.cc',
+ 'engine/directory_cryptographer_provider.h',
'engine/directory_update_handler.cc',
'engine/directory_update_handler.h',
'engine/entity_tracker.cc',
diff --git a/sync/sync_tests.gypi b/sync/sync_tests.gypi
index 31ac9f9..5c84c25 100644
--- a/sync/sync_tests.gypi
+++ b/sync/sync_tests.gypi
@@ -50,6 +50,8 @@
'test/engine/mock_nudge_handler.h',
'test/engine/mock_update_handler.cc',
'test/engine/mock_update_handler.h',
+ 'test/engine/simple_cryptographer_provider.cc',
+ 'test/engine/simple_cryptographer_provider.h',
'test/engine/single_type_mock_server.cc',
'test/engine/single_type_mock_server.h',
'test/engine/test_directory_setter_upper.cc',
diff --git a/sync/test/engine/simple_cryptographer_provider.cc b/sync/test/engine/simple_cryptographer_provider.cc
new file mode 100644
index 0000000..0e2fa99
--- /dev/null
+++ b/sync/test/engine/simple_cryptographer_provider.cc
@@ -0,0 +1,35 @@
+// 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.
+
+#include "sync/test/engine/simple_cryptographer_provider.h"
+
+namespace syncer {
+
+SimpleCryptographerProvider::SimpleCryptographerProvider(
+ Cryptographer* cryptographer)
+ : cryptographer_(cryptographer) {
+}
+
+SimpleCryptographerProvider::~SimpleCryptographerProvider() {
+}
+
+bool SimpleCryptographerProvider::InitScopedCryptographerRef(
+ ScopedCryptographerRef* scoped) {
+ scoped->Initialize(new SimpleScopedCryptographerInternal(cryptographer_));
+ return scoped->IsValid();
+}
+
+SimpleScopedCryptographerInternal::SimpleScopedCryptographerInternal(
+ Cryptographer* cryptographer)
+ : cryptographer_(cryptographer) {
+}
+
+SimpleScopedCryptographerInternal::~SimpleScopedCryptographerInternal() {
+}
+
+Cryptographer* SimpleScopedCryptographerInternal::Get() const {
+ return cryptographer_;
+}
+
+} // namespace syncer
diff --git a/sync/test/engine/simple_cryptographer_provider.h b/sync/test/engine/simple_cryptographer_provider.h
new file mode 100644
index 0000000..b23c5c4
--- /dev/null
+++ b/sync/test/engine/simple_cryptographer_provider.h
@@ -0,0 +1,44 @@
+// 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_TEST_ENGINE_SIMPLE_CRYPTOGRAPHER_PROVIDER_H_
+#define SYNC_TEST_ENGINE_SIMPLE_CRYPTOGRAPHER_PROVIDER_H_
+
+#include "sync/engine/cryptographer_provider.h"
+
+#include "sync/util/cryptographer.h"
+
+namespace syncer {
+
+// A trivial cryptographer provider. Exposes the given Cryptographer through
+// the CryptographerProvider interface. Does not take ownership of the
+// |cryptographer|.
+class SimpleCryptographerProvider : public CryptographerProvider {
+ public:
+ explicit SimpleCryptographerProvider(Cryptographer* cryptographer);
+ virtual ~SimpleCryptographerProvider();
+
+ // Implementation of CryptographerProvider.
+ virtual bool InitScopedCryptographerRef(
+ ScopedCryptographerRef* scoped) OVERRIDE;
+
+ private:
+ Cryptographer* cryptographer_;
+};
+
+class SimpleScopedCryptographerInternal : public ScopedCryptographerInternal {
+ public:
+ explicit SimpleScopedCryptographerInternal(Cryptographer* cryptographer);
+ virtual ~SimpleScopedCryptographerInternal();
+
+ // Implementation of ScopedCryptographerInternal.
+ virtual Cryptographer* Get() const OVERRIDE;
+
+ private:
+ Cryptographer* cryptographer_;
+};
+
+} // namespace syncer
+
+#endif // SYNC_TEST_ENGINE_SIMPLE_CRYPTOGRAPHER_PROVIDER_H_