Chromium Code Reviews| Index: content/browser/nfc/nfc_host.cc |
| diff --git a/content/browser/nfc/nfc_host.cc b/content/browser/nfc/nfc_host.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ea53ca73179e1eb24ad43a14f2079b53156ec481 |
| --- /dev/null |
| +++ b/content/browser/nfc/nfc_host.cc |
| @@ -0,0 +1,53 @@ |
| +// Copyright 2017 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 "content/browser/nfc/nfc_host.h" |
| + |
| +#include "base/atomic_sequence_num.h" |
| +#include "content/public/common/service_manager_connection.h" |
| +#include "device/nfc/nfc.mojom.h" |
| +#include "services/device/public/interfaces/constants.mojom.h" |
| +#include "services/service_manager/public/cpp/connector.h" |
| + |
| +#if defined(OS_ANDROID) |
| +#include "jni/NfcHost_jni.h" |
| +#endif |
| + |
| +namespace content { |
| + |
| +namespace { |
| + |
| +base::StaticAtomicSequenceNumber g_unique_id; |
| + |
| +} // namespace |
| + |
| +NFCHost::NFCHost(WebContents* web_contents) |
| + : id_(g_unique_id.GetNext()), web_contents_(web_contents) { |
| + DCHECK(web_contents_); |
| + |
| +#if defined(OS_ANDROID) |
| + JNIEnv* env = base::android::AttachCurrentThread(); |
| + java_nfc_host_.Reset( |
| + Java_NfcHost_create(env, web_contents_->GetJavaWebContents().obj(), id_)); |
| + |
| + if (ServiceManagerConnection::GetForProcess()) { |
| + service_manager::Connector* connector = |
| + ServiceManagerConnection::GetForProcess()->GetConnector(); |
| + DCHECK(connector); |
|
jam
2017/05/09 15:11:16
nit: since the pointer is used in the next line, t
blundell
2017/05/10 13:15:25
Done.
|
| + connector->BindInterface(device::mojom::kServiceName, |
| + mojo::MakeRequest(&nfc_provider_)); |
| + } |
| +#endif |
| +} |
| + |
| +void NFCHost::GetNFC(device::nfc::mojom::NFCRequest request) { |
| +#if defined(OS_ANDROID) |
| + // Connect to an NFC object, associating it with |id_|. |
| + nfc_provider_->GetNFCForHost(id_, std::move(request)); |
|
dcheng
2017/05/10 06:20:18
Nit: #include <utility>
blundell
2017/05/10 13:15:25
Done.
|
| +#endif |
| +} |
| + |
| +NFCHost::~NFCHost() {} |
| + |
| +} // namespace content |