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_CRYPTOGRAPHER_PROVIDER_H_
6 #define SYNC_ENGINE_CRYPTOGRAPHER_PROVIDER_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "sync/base/sync_export.h"
14 class ScopedCryptographerRef;
15 class ScopedCryptographerInternal;
17 // An interface for providing clients with a ScopedCryptographerRef.
19 // Used to expose the syncable::Directory's cryptographer to clients that
20 // would otherwise not have access to the Directory.
21 class SYNC_EXPORT_PRIVATE CryptographerProvider {
23 CryptographerProvider();
24 virtual ~CryptographerProvider();
26 virtual bool InitScopedCryptographerRef(ScopedCryptographerRef* scoped) = 0;
29 // A concrete class representing a reference to a cryptographer.
31 // Access to the cryptographer is lost when this class goes out of scope.
32 class SYNC_EXPORT_PRIVATE ScopedCryptographerRef {
34 ScopedCryptographerRef();
35 ~ScopedCryptographerRef();
37 bool Initialize(ScopedCryptographerInternal* impl);
39 Cryptographer* Get() const;
42 scoped_ptr<ScopedCryptographerInternal> scoped_cryptographer_internal_;
44 DISALLOW_COPY_AND_ASSIGN(ScopedCryptographerRef);
47 // An interface class used in the implementation of the ScopedCryptographerRef.
49 // We use this class to allow different implementations of
50 // CryptographerProvider to implement InitScopedCryptographer in different
51 // ways. The ScopedCryptographerRef itself must be stack-allocated, so it
52 // can't vary depending on which kind of CryptographerProvider is used to
54 class SYNC_EXPORT_PRIVATE ScopedCryptographerInternal {
56 ScopedCryptographerInternal();
57 virtual ~ScopedCryptographerInternal();
59 virtual Cryptographer* Get() const = 0;
64 #endif // SYNC_ENGINE_CRYPTOGRAPHER_PROVIDER_H_