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

Issue 2865653002: [Device Service] Decouple NFC implementation from //content (Closed)

Created:
3 years, 7 months ago by blundell
Modified:
3 years, 7 months ago
CC:
Aaron Boodman, abarth-chromium, agrieve+watch_chromium.org, chromium-reviews, creis+watch_chromium.org, darin (slow to review), darin-cc_chromium.org, jam, nasko+codewatch_chromium.org, qsr+mojo_chromium.org, viettrungluu+watch_chromium.org, yzshen+watch_chromium.org
Target Ref:
refs/heads/master
Project:
chromium
Visibility:
Public.

Description

[Device Service] Decouple NFC implementation from //content This CL ports the NFC implementation from being hosted by //content to being hosted by the Device Service. This task is challenging because the NFC implementation needs access to the Activity of the WebContents that is associated with the requesting render frame. Moreore, that Activity can change if the WebContents is reparented (e.g., moved from being in a custom tab to being in Chrome by the user). To handle these challenges, this CL takes a similar approach to that taken for WakeLock: information is passed to the Device Service that allows the NFC implementation to map a host ID to the Activity associated with that ID. Specifically: - The NFCProvider Mojo interface is introduced. It supports connecting to an NFC instance associated with a given host ID. - The NFCDelegate.java interface is introduced. This interface supports mapping from host IDs to Activity, including tracking when the Activity associated with a host ID changes. This interface is passed into the Device Service by its embedder. - NfcImpl.java uses the NFCDelegate to access the Activity that it needs. - //content provides a ContentNFCDelegate implementation. This implementation maps host IDs to WebContents instances via an NfcHost internal helper class. - //content/browser now handles requests to connect to NFC by forwarding them on to the Device Service (i.e., NFCProvider), passing the host ID associated with the WebContents in question in order to allow the NFC implementation to map back to that WebContents via NFCDelegate. The net sum of the above is that //content's dependence on the NFC implementation is removed. Note that in addition to the below-described test, I also tested reparenting as follows: - Close Chromium on the device - On the host, execute: adb shell "am start -a 'android.intent.action.VIEW' -n org.chromium.chrome/com.google.android.apps.chrome.Main -d https://colinblundell.github.io/nfc.html --es \"android.support.customtabs.extra.SESSION\" \"bla\"" - On the phone, you should see a custom tab pop up. Push a message. - Reparent the tab by tapping "Open in Chromium." Verify that the tab was reparented, i.e., there was no reload operation. - Bring the device close to the NFC tag and verify that you see "Message pushed" on the webpage. BUG=680924 TEST=On Chrome on Android, go to about://flags and turn on "Experimental Web Platform features" and "WebNFC Android". Restart Chrome. Obtain a physical NFC tag. Go to https://colinblundell.github.io/nfc.html and verify that the page says "NFC API found". Enter a message on the webpage and press "Push message to tag". Bring the phone near the tag and verifiy that the page outputs "Message pushed." Press "Read data from tag", bring the phone near the tag, and verify that the webpage outputs the message that you just pushed to the tag. CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_site_isolation Review-Url: https://codereview.chromium.org/2865653002 Cr-Commit-Position: refs/heads/master@{#471727} Committed: https://chromium.googlesource.com/chromium/src/+/f5316fccc7bac30a357a1254aef8dc4a605bc045

Patch Set 1 #

Patch Set 2 : Self-review #

Patch Set 3 : More self-review #

Patch Set 4 : Move code to NfcHost.java constructor now that it's possible #

Patch Set 5 : Stab at fixing NFCTest #

Patch Set 6 : extra fix #

Total comments: 6

Patch Set 7 : Rebase #

Patch Set 8 : Response to review + fix for tests that don't actually run on bots #

Total comments: 4

Patch Set 9 : Response to reviews #

Total comments: 25

Patch Set 10 : Rebase #

Patch Set 11 : Response to review #

Total comments: 6

Patch Set 12 : Response to review #

Patch Set 13 : Rebase #

Unified diffs Side-by-side diffs Delta from patch set Stats (+580 lines, -159 lines) Patch
M content/browser/BUILD.gn View 1 2 3 4 5 6 7 8 9 10 11 12 1 chunk +2 lines, -0 lines 0 comments Download
M content/browser/android/content_feature_list.cc View 1 2 1 chunk +1 line, -1 line 0 comments Download
A content/browser/android/nfc_host.h View 1 2 3 4 5 6 7 8 9 10 1 chunk +41 lines, -0 lines 0 comments Download
A content/browser/android/nfc_host.cc View 1 2 3 4 5 6 7 8 9 10 1 chunk +49 lines, -0 lines 0 comments Download
M content/browser/frame_host/render_frame_host_delegate.h View 1 2 3 4 5 6 7 8 9 10 11 12 2 chunks +6 lines, -0 lines 0 comments Download
M content/browser/frame_host/render_frame_host_delegate.cc View 1 2 3 4 5 6 7 8 9 10 11 12 1 chunk +4 lines, -0 lines 0 comments Download
M content/browser/frame_host/render_frame_host_impl.h View 1 2 3 4 5 6 7 8 2 chunks +9 lines, -0 lines 0 comments Download
M content/browser/frame_host/render_frame_host_impl.cc View 1 2 3 4 5 6 7 8 9 10 11 12 3 chunks +17 lines, -0 lines 0 comments Download
M content/browser/service_manager/service_manager_context.cc View 1 2 3 4 5 6 7 8 9 10 11 12 2 chunks +16 lines, -3 lines 0 comments Download
M content/browser/web_contents/web_contents_impl.h View 1 2 3 4 5 6 7 8 9 10 3 chunks +11 lines, -0 lines 0 comments Download
M content/browser/web_contents/web_contents_impl.cc View 1 2 3 4 5 6 7 8 9 10 11 12 2 chunks +8 lines, -4 lines 0 comments Download
M content/public/android/BUILD.gn View 1 2 3 4 5 6 7 8 9 10 11 12 5 chunks +5 lines, -2 lines 0 comments Download
M content/public/android/java/src/org/chromium/content/browser/ContentFeatureList.java View 1 2 1 chunk +0 lines, -1 line 0 comments Download
A content/public/android/java/src/org/chromium/content/browser/ContentNfcDelegate.java View 1 2 3 4 5 6 7 8 9 10 11 1 chunk +38 lines, -0 lines 0 comments Download
M content/public/android/java/src/org/chromium/content/browser/InterfaceRegistrarImpl.java View 1 2 3 4 5 6 7 8 9 10 11 12 3 chunks +0 lines, -13 lines 0 comments Download
D content/public/android/java/src/org/chromium/content/browser/NfcFactory.java View 1 chunk +0 lines, -61 lines 0 comments Download
A content/public/android/java/src/org/chromium/content/browser/NfcHost.java View 1 2 3 4 5 6 7 8 9 10 11 1 chunk +112 lines, -0 lines 0 comments Download
M content/public/app/mojo/content_browser_manifest.json View 1 2 3 4 5 6 7 8 9 10 11 12 1 chunk +1 line, -1 line 0 comments Download
M device/BUILD.gn View 1 2 3 4 5 6 7 8 9 10 11 12 1 chunk +1 line, -0 lines 0 comments Download
M device/nfc/BUILD.gn View 1 chunk +1 line, -0 lines 0 comments Download
M device/nfc/android/BUILD.gn View 2 chunks +4 lines, -0 lines 0 comments Download
M device/nfc/android/java/src/org/chromium/device/nfc/NfcImpl.java View 1 2 3 4 5 6 7 8 9 10 11 4 chunks +18 lines, -4 lines 0 comments Download
A device/nfc/android/java/src/org/chromium/device/nfc/NfcProviderImpl.java View 1 2 1 chunk +56 lines, -0 lines 0 comments Download
M device/nfc/android/java/src/org/chromium/device/nfc/NfcTagHandler.java View 1 chunk +1 line, -1 line 0 comments Download
M device/nfc/android/junit/src/org/chromium/device/nfc/NFCTest.java View 1 2 3 4 5 6 7 26 chunks +66 lines, -49 lines 0 comments Download
M device/nfc/nfc.mojom View 1 chunk +1 line, -1 line 0 comments Download
A device/nfc/nfc_provider.mojom View 1 2 3 4 5 6 7 1 chunk +15 lines, -0 lines 0 comments Download
A device/nfc/public/java/BUILD.gn View 1 chunk +12 lines, -0 lines 0 comments Download
A device/nfc/public/java/src/org/chromium/device/nfc/NfcDelegate.java View 1 2 3 4 5 6 7 8 9 10 11 1 chunk +24 lines, -0 lines 0 comments Download
M services/device/BUILD.gn View 1 2 3 4 5 6 2 chunks +4 lines, -0 lines 0 comments Download
M services/device/android/java/src/org/chromium/services/device/InterfaceRegistrar.java View 1 2 3 4 5 6 2 chunks +7 lines, -1 line 0 comments Download
M services/device/device_service.h View 1 2 3 4 5 6 7 8 9 10 11 12 7 chunks +22 lines, -7 lines 0 comments Download
M services/device/device_service.cc View 1 2 3 4 5 6 7 8 9 10 11 12 6 chunks +26 lines, -9 lines 0 comments Download
M services/device/device_service_test_base.cc View 1 2 1 chunk +1 line, -1 line 0 comments Download
M services/device/manifest.json View 1 2 3 4 5 6 7 8 9 10 11 12 1 chunk +1 line, -0 lines 0 comments Download

Depends on Patchset:

Messages

Total messages: 51 (39 generated)
blundell
https://www.youtube.com/watch?v=xJBB7l7cOqc
3 years, 7 months ago (2017-05-05 16:15:36 UTC) #18
Ken Rockot(use gerrit already)
I think this looks right to me! LGTM. https://codereview.chromium.org/2865653002/diff/100001/content/public/android/java/src/org/chromium/content/browser/InterfaceRegistrarImpl.java File content/public/android/java/src/org/chromium/content/browser/InterfaceRegistrarImpl.java (right): https://codereview.chromium.org/2865653002/diff/100001/content/public/android/java/src/org/chromium/content/browser/InterfaceRegistrarImpl.java#newcode60 content/public/android/java/src/org/chromium/content/browser/InterfaceRegistrarImpl.java:60: InterfaceRegistrar.Registry.addWebContentsRegistrar( ...
3 years, 7 months ago (2017-05-08 15:45:07 UTC) #19
blundell
+tedchoc@ for //content/public/android OWNERS +jam@ for //content OWNERS outside of the java stuff +dcheng@ for ...
3 years, 7 months ago (2017-05-09 14:46:19 UTC) #21
jam
lgtm curious why a bunch of the code isn't behind android ifdefs? I thought NFC ...
3 years, 7 months ago (2017-05-09 15:11:17 UTC) #24
dcheng
mojo LGTM, though I have the same question as rockot@ regarding #ifdefs https://codereview.chromium.org/2865653002/diff/140001/content/browser/nfc/nfc_host.cc File content/browser/nfc/nfc_host.cc ...
3 years, 7 months ago (2017-05-10 06:20:18 UTC) #27
blundell
Thanks for the reviews! Changed so that the NFC code in //content is entirely Android-only ...
3 years, 7 months ago (2017-05-10 13:15:25 UTC) #28
Ted C
https://codereview.chromium.org/2865653002/diff/160001/content/browser/nfc/nfc_host.h File content/browser/nfc/nfc_host.h (right): https://codereview.chromium.org/2865653002/diff/160001/content/browser/nfc/nfc_host.h#newcode5 content/browser/nfc/nfc_host.h:5: #ifndef CONTENT_BROWSER_NFC_NFC_HOST_H_ In the same vein as the ifdef ...
3 years, 7 months ago (2017-05-10 14:37:41 UTC) #29
blundell
Thanks, Ted! Question back to you in the comments about lifetime relationship between WebContents and ...
3 years, 7 months ago (2017-05-11 15:13:52 UTC) #30
Ted C
lgtm There are cases where no CVC is present, but I suspect NFC as a ...
3 years, 7 months ago (2017-05-11 16:36:49 UTC) #35
blundell
Thanks! All comments addressed, and comments rewrapped. I discovered a somewhat subtle issue with how ...
3 years, 7 months ago (2017-05-12 11:01:15 UTC) #39
commit-bot: I haz the power
CQ is trying da patch. Follow status at: https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.org/2865653002/260001
3 years, 7 months ago (2017-05-15 11:43:43 UTC) #48
commit-bot: I haz the power
3 years, 7 months ago (2017-05-15 11:49:27 UTC) #51
Message was sent while issue was closed.
Committed patchset #13 (id:260001) as
https://chromium.googlesource.com/chromium/src/+/f5316fccc7bac30a357a1254aef8...

Powered by Google App Engine
This is Rietveld 408576698