summaryrefslogtreecommitdiffstats
path: root/sync/engine
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 /sync/engine
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
Diffstat (limited to 'sync/engine')
-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
4 files changed, 195 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_