Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(274)

Side by Side Diff: chrome/browser/chromeos/cros/cros_library.h

Issue 14179007: Move cryptohome_library to src/chromeos (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_CHROMEOS_CROS_CROS_LIBRARY_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_CROS_CROS_LIBRARY_H_
6 #define CHROME_BROWSER_CHROMEOS_CROS_CROS_LIBRARY_H_ 6 #define CHROME_BROWSER_CHROMEOS_CROS_CROS_LIBRARY_H_
7 7
8 #include <string> 8 #include <string>
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 11
12 namespace base { 12 namespace base {
13 template <typename T> struct DefaultLazyInstanceTraits; 13 template <typename T> struct DefaultLazyInstanceTraits;
14 } 14 }
15 15
16 namespace chromeos { 16 namespace chromeos {
17 17
18 class CertLibrary; 18 class CertLibrary;
19 class CryptohomeLibrary;
20 class NetworkLibrary; 19 class NetworkLibrary;
21 20
22 // This class handles access to sub-parts of ChromeOS library. it provides 21 // This class handles access to sub-parts of ChromeOS library. it provides
23 // a level of indirection so individual libraries that it exposes can 22 // a level of indirection so individual libraries that it exposes can
24 // be mocked for testing. 23 // be mocked for testing.
25 class CrosLibrary { 24 class CrosLibrary {
26 public: 25 public:
27 // This class provides access to internal members of CrosLibrary class for 26 // This class provides access to internal members of CrosLibrary class for
28 // purpose of testing (i.e. replacement of members' implementation with 27 // purpose of testing (i.e. replacement of members' implementation with
29 // mock objects). 28 // mock objects).
30 class TestApi { 29 class TestApi {
31 public: 30 public:
32 // Passing true for own for these setters will cause them to be deleted 31 // Passing true for own for these setters will cause them to be deleted
33 // when the CrosLibrary is deleted (or other mocks are set). 32 // when the CrosLibrary is deleted (or other mocks are set).
34 void SetCertLibrary(CertLibrary* library, bool own); 33 void SetCertLibrary(CertLibrary* library, bool own);
35 void SetCryptohomeLibrary(CryptohomeLibrary* library, bool own);
36 void SetNetworkLibrary(NetworkLibrary* library, bool own); 34 void SetNetworkLibrary(NetworkLibrary* library, bool own);
37 35
38 private: 36 private:
39 friend class CrosLibrary; 37 friend class CrosLibrary;
40 explicit TestApi(CrosLibrary* library) : library_(library) {} 38 explicit TestApi(CrosLibrary* library) : library_(library) {}
41 CrosLibrary* library_; 39 CrosLibrary* library_;
42 }; 40 };
43 41
44 // Sets the global instance. Must be called before any calls to Get(). 42 // Sets the global instance. Must be called before any calls to Get().
45 static void Initialize(bool use_stub); 43 static void Initialize(bool use_stub);
46 44
47 // Destroys the global instance. Must be called before AtExitManager is 45 // Destroys the global instance. Must be called before AtExitManager is
48 // destroyed to ensure a clean shutdown. 46 // destroyed to ensure a clean shutdown.
49 static void Shutdown(); 47 static void Shutdown();
50 48
51 // Gets the global instance. Returns NULL if Initialize() has not been 49 // Gets the global instance. Returns NULL if Initialize() has not been
52 // called (or Shutdown() has been called). 50 // called (or Shutdown() has been called).
53 static CrosLibrary* Get(); 51 static CrosLibrary* Get();
54 52
55 CertLibrary* GetCertLibrary(); 53 CertLibrary* GetCertLibrary();
56 CryptohomeLibrary* GetCryptohomeLibrary();
57 NetworkLibrary* GetNetworkLibrary(); 54 NetworkLibrary* GetNetworkLibrary();
58 55
59 // Getter for Test API that gives access to internal members of this class. 56 // Getter for Test API that gives access to internal members of this class.
60 TestApi* GetTestApi(); 57 TestApi* GetTestApi();
61 58
62 // Note: Since we are no longer loading Libcros, we can return true here 59 // Note: Since we are no longer loading Libcros, we can return true here
63 // whenever the used libraries are not stub. 60 // whenever the used libraries are not stub.
64 // TODO(hashimoto): Remove this method. 61 // TODO(hashimoto): Remove this method.
65 bool libcros_loaded() { return !use_stub_impl_; } 62 bool libcros_loaded() { return !use_stub_impl_; }
66 63
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 own_ = own; 96 own_ = own;
100 } 97 }
101 } 98 }
102 99
103 private: 100 private:
104 L* library_; 101 L* library_;
105 bool own_; 102 bool own_;
106 }; 103 };
107 104
108 Library<CertLibrary> cert_lib_; 105 Library<CertLibrary> cert_lib_;
109 Library<CryptohomeLibrary> crypto_lib_;
110 Library<NetworkLibrary> network_lib_; 106 Library<NetworkLibrary> network_lib_;
111 107
112 // Stub implementations of the libraries should be used. 108 // Stub implementations of the libraries should be used.
113 bool use_stub_impl_; 109 bool use_stub_impl_;
114 scoped_ptr<TestApi> test_api_; 110 scoped_ptr<TestApi> test_api_;
115 111
116 DISALLOW_COPY_AND_ASSIGN(CrosLibrary); 112 DISALLOW_COPY_AND_ASSIGN(CrosLibrary);
117 }; 113 };
118 114
119 // The class is used for enabling the stub libcros, and cleaning it up at 115 // The class is used for enabling the stub libcros, and cleaning it up at
120 // the end of the object lifetime. Useful for testing. 116 // the end of the object lifetime. Useful for testing.
121 class ScopedStubCrosEnabler { 117 class ScopedStubCrosEnabler {
122 public: 118 public:
123 ScopedStubCrosEnabler() { 119 ScopedStubCrosEnabler() {
124 chromeos::CrosLibrary::Initialize(true); 120 chromeos::CrosLibrary::Initialize(true);
125 } 121 }
126 122
127 ~ScopedStubCrosEnabler() { 123 ~ScopedStubCrosEnabler() {
128 chromeos::CrosLibrary::Shutdown(); 124 chromeos::CrosLibrary::Shutdown();
129 } 125 }
130 126
131 private: 127 private:
132 DISALLOW_COPY_AND_ASSIGN(ScopedStubCrosEnabler); 128 DISALLOW_COPY_AND_ASSIGN(ScopedStubCrosEnabler);
133 }; 129 };
134 130
135 } // namespace chromeos 131 } // namespace chromeos
136 132
137 #endif // CHROME_BROWSER_CHROMEOS_CROS_CROS_LIBRARY_H_ 133 #endif // CHROME_BROWSER_CHROMEOS_CROS_CROS_LIBRARY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698