summaryrefslogtreecommitdiff
path: root/chromium/content/browser/android/nfc_host.cc
blob: 90a17ec4d3efc400daea450363802e7b0d3afb15 (plain)
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
// 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/android/nfc_host.h"

#include <utility>

#include "base/atomic_sequence_num.h"
#include "content/public/browser/android/content_view_core.h"
#include "content/public/common/service_manager_connection.h"
#include "jni/NfcHost_jni.h"
#include "services/device/public/interfaces/constants.mojom.h"
#include "services/device/public/interfaces/nfc.mojom.h"
#include "services/service_manager/public/cpp/connector.h"

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_);

  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();
    connector->BindInterface(device::mojom::kServiceName,
                             mojo::MakeRequest(&nfc_provider_));
  }
}

void NFCHost::GetNFC(device::mojom::NFCRequest request) {
  // Connect to an NFC object, associating it with |id_|.
  nfc_provider_->GetNFCForHost(id_, std::move(request));
}

NFCHost::~NFCHost() {}

}  // namespace content