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

Side by Side Diff: device/nfc/nfc_adapter_factory.cc

Issue 2292703002: chromeos: Remove unused NFC D-Bus client library (Closed)
Patch Set: rebase Created 4 years, 3 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
« no previous file with comments | « device/nfc/nfc_adapter_factory.h ('k') | device/nfc/nfc_chromeos_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2013 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 #include "device/nfc/nfc_adapter_factory.h"
6
7 #include "base/lazy_instance.h"
8 #include "base/logging.h"
9 #include "base/memory/weak_ptr.h"
10 #include "build/build_config.h"
11
12 #if defined(OS_CHROMEOS)
13 #include "device/nfc/nfc_adapter_chromeos.h"
14 #endif
15
16 namespace device {
17
18 namespace {
19
20 // Shared default adapter instance, we don't want to keep this class around
21 // if nobody is using it so use a WeakPtr and create the object when needed;
22 // since Google C++ Style (and clang's static analyzer) forbids us having
23 // exit-time destructors we use a leaky lazy instance for it.
24 base::LazyInstance<base::WeakPtr<device::NfcAdapter> >::Leaky
25 default_adapter = LAZY_INSTANCE_INITIALIZER;
26
27 } // namespace
28
29 // static
30 bool NfcAdapterFactory::IsNfcAvailable() {
31 #if defined(OS_CHROMEOS)
32 return true;
33 #else
34 return false;
35 #endif
36 }
37
38 // static
39 void NfcAdapterFactory::GetAdapter(const AdapterCallback& callback) {
40 if (!IsNfcAvailable()) {
41 LOG(WARNING) << "NFC is not available on the current platform.";
42 return;
43 }
44 if (!default_adapter.Get().get()) {
45 #if defined(OS_CHROMEOS)
46 chromeos::NfcAdapterChromeOS* new_adapter =
47 new chromeos::NfcAdapterChromeOS();
48 default_adapter.Get() = new_adapter->weak_ptr_factory_.GetWeakPtr();
49 #endif
50 }
51 if (default_adapter.Get()->IsInitialized())
52 callback.Run(scoped_refptr<NfcAdapter>(default_adapter.Get().get()));
53 }
54
55 } // namespace device
OLDNEW
« no previous file with comments | « device/nfc/nfc_adapter_factory.h ('k') | device/nfc/nfc_chromeos_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698