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

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

Issue 10626002: Reland "Remove chromeos::LibraryLoader" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove stub hack Created 8 years, 6 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 12
13 namespace base { 13 namespace base {
14 template <typename T> struct DefaultLazyInstanceTraits; 14 template <typename T> struct DefaultLazyInstanceTraits;
15 } 15 }
16 16
17 namespace chromeos { 17 namespace chromeos {
18 18
19 class BurnLibrary; 19 class BurnLibrary;
20 class CertLibrary; 20 class CertLibrary;
21 class CryptohomeLibrary; 21 class CryptohomeLibrary;
22 class LibraryLoader;
23 class NetworkLibrary; 22 class NetworkLibrary;
24 23
25 // This class handles access to sub-parts of ChromeOS library. it provides 24 // This class handles access to sub-parts of ChromeOS library. it provides
26 // a level of indirection so individual libraries that it exposes can 25 // a level of indirection so individual libraries that it exposes can
27 // be mocked for testing. 26 // be mocked for testing.
28 class CrosLibrary { 27 class CrosLibrary {
29 public: 28 public:
30 // This class provides access to internal members of CrosLibrary class for 29 // This class provides access to internal members of CrosLibrary class for
31 // purpose of testing (i.e. replacement of members' implementation with 30 // purpose of testing (i.e. replacement of members' implementation with
32 // mock objects). 31 // mock objects).
33 class TestApi { 32 class TestApi {
34 public: 33 public:
35 // Resets the stub implementation of the library and loads libcros.
36 // Used by tests that need to run with libcros (i.e. on a device).
37 void ResetUseStubImpl();
38
39 // Passing true for own for these setters will cause them to be deleted 34 // Passing true for own for these setters will cause them to be deleted
40 // when the CrosLibrary is deleted (or other mocks are set). 35 // when the CrosLibrary is deleted (or other mocks are set).
41 // Setter for LibraryLoader.
42 void SetLibraryLoader(LibraryLoader* loader, bool own);
43 void SetCertLibrary(CertLibrary* library, bool own); 36 void SetCertLibrary(CertLibrary* library, bool own);
44 void SetBurnLibrary(BurnLibrary* library, bool own); 37 void SetBurnLibrary(BurnLibrary* library, bool own);
45 void SetCryptohomeLibrary(CryptohomeLibrary* library, bool own); 38 void SetCryptohomeLibrary(CryptohomeLibrary* library, bool own);
46 void SetNetworkLibrary(NetworkLibrary* library, bool own); 39 void SetNetworkLibrary(NetworkLibrary* library, bool own);
47 40
48 private: 41 private:
49 friend class CrosLibrary; 42 friend class CrosLibrary;
50 explicit TestApi(CrosLibrary* library) : library_(library) {} 43 explicit TestApi(CrosLibrary* library) : library_(library) {}
51 CrosLibrary* library_; 44 CrosLibrary* library_;
52 }; 45 };
(...skipping 10 matching lines...) Expand all
63 static CrosLibrary* Get(); 56 static CrosLibrary* Get();
64 57
65 BurnLibrary* GetBurnLibrary(); 58 BurnLibrary* GetBurnLibrary();
66 CertLibrary* GetCertLibrary(); 59 CertLibrary* GetCertLibrary();
67 CryptohomeLibrary* GetCryptohomeLibrary(); 60 CryptohomeLibrary* GetCryptohomeLibrary();
68 NetworkLibrary* GetNetworkLibrary(); 61 NetworkLibrary* GetNetworkLibrary();
69 62
70 // Getter for Test API that gives access to internal members of this class. 63 // Getter for Test API that gives access to internal members of this class.
71 TestApi* GetTestApi(); 64 TestApi* GetTestApi();
72 65
73 bool libcros_loaded() { return libcros_loaded_; } 66 // Note: Since we are no longer loading Libcros, we can return true here
67 // whenever the used libraries are not stub.
68 // TODO(hashimoto): Remove this method.
69 bool libcros_loaded() { return !use_stub_impl_; }
74 70
75 // Returns an unlocalized string describing the last load error (if any). 71 // Returns an unlocalized string describing the last load error (if any).
76 const std::string& load_error_string() { 72 // TODO(hashimoto): Remove this method.
77 return load_error_string_; 73 std::string load_error_string() { return std::string(); }
78 }
79 74
80 private: 75 private:
81 friend struct base::DefaultLazyInstanceTraits<chromeos::CrosLibrary>; 76 friend struct base::DefaultLazyInstanceTraits<chromeos::CrosLibrary>;
82 friend class CrosLibrary::TestApi; 77 friend class CrosLibrary::TestApi;
83 78
84 explicit CrosLibrary(bool use_stub); 79 explicit CrosLibrary(bool use_stub);
85 virtual ~CrosLibrary(); 80 virtual ~CrosLibrary();
86 81
87 bool LoadLibcros();
88
89 LibraryLoader* library_loader_;
90
91 bool own_library_loader_;
92
93 // This template supports the creation, setting and optional deletion of 82 // This template supports the creation, setting and optional deletion of
94 // the cros libraries. 83 // the cros libraries.
95 template <class L> 84 template <class L>
96 class Library { 85 class Library {
97 public: 86 public:
98 Library() : library_(NULL), own_(true) {} 87 Library() : library_(NULL), own_(true) {}
99 88
100 ~Library() { 89 ~Library() {
101 if (own_) 90 if (own_)
102 delete library_; 91 delete library_;
(...skipping 21 matching lines...) Expand all
124 bool own_; 113 bool own_;
125 }; 114 };
126 115
127 Library<BurnLibrary> burn_lib_; 116 Library<BurnLibrary> burn_lib_;
128 Library<CertLibrary> cert_lib_; 117 Library<CertLibrary> cert_lib_;
129 Library<CryptohomeLibrary> crypto_lib_; 118 Library<CryptohomeLibrary> crypto_lib_;
130 Library<NetworkLibrary> network_lib_; 119 Library<NetworkLibrary> network_lib_;
131 120
132 // Stub implementations of the libraries should be used. 121 // Stub implementations of the libraries should be used.
133 bool use_stub_impl_; 122 bool use_stub_impl_;
134 // True if libcros was successfully loaded.
135 bool libcros_loaded_;
136 // True if the last load attempt had an error.
137 bool load_error_;
138 // Contains the error string from the last load attempt.
139 std::string load_error_string_;
140 scoped_ptr<TestApi> test_api_; 123 scoped_ptr<TestApi> test_api_;
141 124
142 DISALLOW_COPY_AND_ASSIGN(CrosLibrary); 125 DISALLOW_COPY_AND_ASSIGN(CrosLibrary);
143 }; 126 };
144 127
145 // The class is used for enabling the stub libcros, and cleaning it up at 128 // The class is used for enabling the stub libcros, and cleaning it up at
146 // the end of the object lifetime. Useful for testing. 129 // the end of the object lifetime. Useful for testing.
147 class ScopedStubCrosEnabler { 130 class ScopedStubCrosEnabler {
148 public: 131 public:
149 ScopedStubCrosEnabler() { 132 ScopedStubCrosEnabler() {
150 chromeos::CrosLibrary::Initialize(true); 133 chromeos::CrosLibrary::Initialize(true);
151 } 134 }
152 135
153 ~ScopedStubCrosEnabler() { 136 ~ScopedStubCrosEnabler() {
154 chromeos::CrosLibrary::Shutdown(); 137 chromeos::CrosLibrary::Shutdown();
155 } 138 }
156 139
157 private: 140 private:
158 DISALLOW_COPY_AND_ASSIGN(ScopedStubCrosEnabler); 141 DISALLOW_COPY_AND_ASSIGN(ScopedStubCrosEnabler);
159 }; 142 };
160 143
161 } // namespace chromeos 144 } // namespace chromeos
162 145
163 #endif // CHROME_BROWSER_CHROMEOS_CROS_CROS_LIBRARY_H_ 146 #endif // CHROME_BROWSER_CHROMEOS_CROS_CROS_LIBRARY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698