1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
// Copyright (c) 2012 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 "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/cros/burn_library.h"
#include "chrome/browser/chromeos/cros/cert_library.h"
#include "chrome/browser/chromeos/cros/cryptohome_library.h"
#include "chrome/browser/chromeos/cros/network_library.h"
#define DEFINE_GET_LIBRARY_METHOD(class_prefix, var_prefix) \
class_prefix##Library* CrosLibrary::Get##class_prefix##Library() { \
return var_prefix##_lib_.GetDefaultImpl(use_stub_impl_); \
}
#define DEFINE_SET_LIBRARY_METHOD(class_prefix, var_prefix) \
void CrosLibrary::TestApi::Set##class_prefix##Library( \
class_prefix##Library* library, bool own) { \
library_->var_prefix##_lib_.SetImpl(library, own); \
}
namespace chromeos {
static CrosLibrary* g_cros_library = NULL;
CrosLibrary::CrosLibrary(bool use_stub)
: use_stub_impl_(use_stub),
test_api_(NULL) {
}
CrosLibrary::~CrosLibrary() {
}
// static
void CrosLibrary::Initialize(bool use_stub) {
CHECK(!g_cros_library) << "CrosLibrary: Multiple calls to Initialize().";
g_cros_library = new CrosLibrary(use_stub);
VLOG_IF(1, use_stub) << "CrosLibrary Initialized with Stub Impl.";
}
// static
void CrosLibrary::Shutdown() {
CHECK(g_cros_library) << "CrosLibrary::Shutdown() called with NULL library";
VLOG(1) << "CrosLibrary Shutting down...";
delete g_cros_library;
g_cros_library = NULL;
VLOG(1) << " CrosLibrary Shutdown completed.";
}
// static
CrosLibrary* CrosLibrary::Get() {
return g_cros_library;
}
DEFINE_GET_LIBRARY_METHOD(Burn, burn);
DEFINE_GET_LIBRARY_METHOD(Cert, cert);
DEFINE_GET_LIBRARY_METHOD(Cryptohome, crypto);
DEFINE_GET_LIBRARY_METHOD(Network, network);
CrosLibrary::TestApi* CrosLibrary::GetTestApi() {
if (!test_api_.get())
test_api_.reset(new TestApi(this));
return test_api_.get();
}
DEFINE_SET_LIBRARY_METHOD(Cert, cert);
DEFINE_SET_LIBRARY_METHOD(Burn, burn);
DEFINE_SET_LIBRARY_METHOD(Cryptohome, crypto);
DEFINE_SET_LIBRARY_METHOD(Network, network);
} // namespace chromeos
|