Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / sync / engine / cryptographer_provider.h
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.
4
5 #ifndef SYNC_ENGINE_CRYPTOGRAPHER_PROVIDER_H_
6 #define SYNC_ENGINE_CRYPTOGRAPHER_PROVIDER_H_
7
8 #include "base/memory/scoped_ptr.h"
9 #include "sync/base/sync_export.h"
10
11 namespace syncer {
12
13 class Cryptographer;
14 class ScopedCryptographerRef;
15 class ScopedCryptographerInternal;
16
17 // An interface for providing clients with a ScopedCryptographerRef.
18 //
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 {
22  public:
23   CryptographerProvider();
24   virtual ~CryptographerProvider();
25
26   virtual bool InitScopedCryptographerRef(ScopedCryptographerRef* scoped) = 0;
27 };
28
29 // A concrete class representing a reference to a cryptographer.
30 //
31 // Access to the cryptographer is lost when this class goes out of scope.
32 class SYNC_EXPORT_PRIVATE ScopedCryptographerRef {
33  public:
34   ScopedCryptographerRef();
35   ~ScopedCryptographerRef();
36
37   bool Initialize(ScopedCryptographerInternal* impl);
38   bool IsValid() const;
39   Cryptographer* Get() const;
40
41  private:
42   scoped_ptr<ScopedCryptographerInternal> scoped_cryptographer_internal_;
43
44   DISALLOW_COPY_AND_ASSIGN(ScopedCryptographerRef);
45 };
46
47 // An interface class used in the implementation of the ScopedCryptographerRef.
48 //
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
53 // intialize it.
54 class SYNC_EXPORT_PRIVATE ScopedCryptographerInternal {
55  public:
56   ScopedCryptographerInternal();
57   virtual ~ScopedCryptographerInternal();
58
59   virtual Cryptographer* Get() const = 0;
60 };
61
62 }  // namespace syncer
63
64 #endif  // SYNC_ENGINE_CRYPTOGRAPHER_PROVIDER_H_