forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathudev_loader.cc
52 lines (38 loc) · 1.09 KB
/
udev_loader.cc
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
// Copyright 2014 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 "device/udev_linux/udev_loader.h"
#include <memory>
#include "base/check.h"
#include "device/udev_linux/udev0_loader.h"
#include "device/udev_linux/udev1_loader.h"
namespace device {
namespace {
UdevLoader* g_udev_loader = NULL;
} // namespace
// static
UdevLoader* UdevLoader::Get() {
if (g_udev_loader)
return g_udev_loader;
std::unique_ptr<UdevLoader> udev_loader;
udev_loader.reset(new Udev1Loader);
if (udev_loader->Init()) {
g_udev_loader = udev_loader.release();
return g_udev_loader;
}
udev_loader.reset(new Udev0Loader);
if (udev_loader->Init()) {
g_udev_loader = udev_loader.release();
return g_udev_loader;
}
CHECK(false);
return nullptr;
}
// static
void UdevLoader::SetForTesting(UdevLoader* loader, bool delete_previous) {
if (g_udev_loader && delete_previous)
delete g_udev_loader;
g_udev_loader = loader;
}
UdevLoader::~UdevLoader() = default;
} // namespace device