Require an explicit ServiceName annotation for interfaces in Java
The names added match the current implicit service names.
BUG=https://github.com/domokit/mojo/issues/498
R=ppi@chromium.org
Review URL: https://codereview.chromium.org/1457383005 .
diff --git a/mojo/public/interfaces/bindings/tests/sample_factory.mojom b/mojo/public/interfaces/bindings/tests/sample_factory.mojom
index 37066e3..f6ec869 100644
--- a/mojo/public/interfaces/bindings/tests/sample_factory.mojom
+++ b/mojo/public/interfaces/bindings/tests/sample_factory.mojom
@@ -24,6 +24,7 @@
handle<message_pipe>? pipe;
};
+[ServiceName="sample::NamedObject"]
interface NamedObject {
SetName(string name);
GetName() => (string name);
diff --git a/mojo/public/java/application/src/org/chromium/mojo/application/ShellHelper.java b/mojo/public/java/application/src/org/chromium/mojo/application/ShellHelper.java
index 705e22e..c26b37b 100644
--- a/mojo/public/java/application/src/org/chromium/mojo/application/ShellHelper.java
+++ b/mojo/public/java/application/src/org/chromium/mojo/application/ShellHelper.java
@@ -22,12 +22,12 @@
* @param core Implementation of the {@link Core} api.
* @param shell Instance of the shell.
* @param application URL to the application to use.
- * @param manager {@link org.chromium.mojo.bindings.Interface.Manager} for the service to
+ * @param manager {@link org.chromium.mojo.bindings.Interface.NamedManager} for the service to
* connect to.
* @return a proxy to the service.
*/
public static <I extends Interface, P extends Proxy> P connectToService(
- Core core, Shell shell, String application, Interface.Manager<I, P> manager) {
+ Core core, Shell shell, String application, Interface.NamedManager<I, P> manager) {
Pair<ServiceProvider.Proxy, InterfaceRequest<ServiceProvider>> providerRequest =
ServiceProvider.MANAGER.getInterfaceRequest(core);
try (ServiceProvider.Proxy provider = providerRequest.first) {
diff --git a/mojo/public/java/bindings/src/org/chromium/mojo/bindings/Interface.java b/mojo/public/java/bindings/src/org/chromium/mojo/bindings/Interface.java
index 3167e87..38d8114 100644
--- a/mojo/public/java/bindings/src/org/chromium/mojo/bindings/Interface.java
+++ b/mojo/public/java/bindings/src/org/chromium/mojo/bindings/Interface.java
@@ -333,12 +333,6 @@
abstract class Manager<I extends Interface, P extends Proxy> {
/**
- * Returns the name of the interface. This is an opaque (but human readable) identifier used
- * by the service provider to identify services.
- */
- public abstract String getName();
-
- /**
* Returns the version of the managed interface.
*/
public abstract int getVersion();
@@ -440,4 +434,15 @@
protected abstract P buildProxy(Core core, MessageReceiverWithResponder messageReceiver);
}
+
+ /**
+ * The |Manager| object for interfaces having an associated service name in the bindings.
+ */
+ abstract class NamedManager<I extends Interface, P extends Proxy> extends Manager<I, P> {
+ /**
+ * Returns the name of the service. This is an opaque (but human readable) identifier used
+ * by the service provider to identify services.
+ */
+ public abstract String getName();
+ }
}
diff --git a/mojo/public/tools/bindings/generators/java_templates/interface_definition.tmpl b/mojo/public/tools/bindings/generators/java_templates/interface_definition.tmpl
index 527e15f..0aec7fa 100644
--- a/mojo/public/tools/bindings/generators/java_templates/interface_definition.tmpl
+++ b/mojo/public/tools/bindings/generators/java_templates/interface_definition.tmpl
@@ -51,16 +51,18 @@
{%- endmacro -%}
{%- macro manager_class(interface, fully_qualified=False) -%}
-{% if fully_qualified %}org.chromium.mojo.bindings.Interface.{% endif %}Manager<{{interface|name}}, {{interface|name}}.Proxy>
+{% if fully_qualified %}org.chromium.mojo.bindings.Interface.{% endif %}{% if interface.service_name %}Named{% endif %}Manager<{{interface|name}}, {{interface|name}}.Proxy>
{%- endmacro -%}
{%- macro manager_def(interface) -%}
public static final {{manager_class(interface, True)}} MANAGER =
new {{manager_class(interface, True)}}() {
+{% if interface.service_name %}
public String getName() {
- return "{{namespace|replace(".","::")}}::{{interface.name}}";
+ return "{{interface.service_name}}";
}
+{% endif %}
public int getVersion() {
return {{interface.version}};
diff --git a/mojo/services/camera/interfaces/camera.mojom b/mojo/services/camera/interfaces/camera.mojom
index b7cc5cb..9f607b0 100644
--- a/mojo/services/camera/interfaces/camera.mojom
+++ b/mojo/services/camera/interfaces/camera.mojom
@@ -18,6 +18,7 @@
// The camera roll is exposed as a snapshot of all photos available as a list.
// The head of the list (element with index 0) is a photo with the latest
// timestamp and subsequent elements are in decreasing order of timestamp.
+[ServiceName="mojo::CameraRollService"]
interface CameraRollService {
// Updates the snapshot of all photos available. Photos might have been added
// or removed after the service was started or |Update| was called.
@@ -30,6 +31,7 @@
};
// |CameraService| provides access to the device's camera video stream.
+[ServiceName="mojo::CameraService"]
interface CameraService {
// Returns the most recent frame captured by the device's camera
// in preview mode.
diff --git a/mojo/services/input/interfaces/input.mojom b/mojo/services/input/interfaces/input.mojom
index d61ad9d..23458aa 100644
--- a/mojo/services/input/interfaces/input.mojom
+++ b/mojo/services/input/interfaces/input.mojom
@@ -9,6 +9,7 @@
OnBackButton() => ();
};
+[ServiceName="input::InputService"]
interface InputService {
SetClient(InputClient client);
};
diff --git a/mojo/services/location/interfaces/location_service.mojom b/mojo/services/location/interfaces/location_service.mojom
index ab7a6d8..da1a85f 100644
--- a/mojo/services/location/interfaces/location_service.mojom
+++ b/mojo/services/location/interfaces/location_service.mojom
@@ -13,6 +13,7 @@
// Google Play Services Location API. If we ever want to expand this to multiple
// platforms or if it starts growing in complexity, we should strongly consider
// use of Chromium's geolocation code.
+[ServiceName="mojo::LocationService"]
interface LocationService {
enum UpdatePriority {
// Use this setting to request location precision to within a city block.
diff --git a/mojo/services/sensors/interfaces/sensors.mojom b/mojo/services/sensors/interfaces/sensors.mojom
index 8b9a08c..4de533c 100644
--- a/mojo/services/sensors/interfaces/sensors.mojom
+++ b/mojo/services/sensors/interfaces/sensors.mojom
@@ -38,6 +38,7 @@
OnSensorChanged(SensorData data);
};
+[ServiceName="sensors::SensorService"]
interface SensorService {
AddListener(SensorType type, SensorListener listener);
};
diff --git a/mojo/services/sharing/interfaces/sharing.mojom b/mojo/services/sharing/interfaces/sharing.mojom
index 494b552..59dc510 100644
--- a/mojo/services/sharing/interfaces/sharing.mojom
+++ b/mojo/services/sharing/interfaces/sharing.mojom
@@ -5,6 +5,7 @@
[DartPackage="mojo_services"]
module mojo;
+[ServiceName="mojo::SharingService"]
interface SharingService {
ShareText(string text);
};
diff --git a/mojo/services/speech_recognizer/interfaces/speech_recognizer.mojom b/mojo/services/speech_recognizer/interfaces/speech_recognizer.mojom
index 526b3a6..9039589 100644
--- a/mojo/services/speech_recognizer/interfaces/speech_recognizer.mojom
+++ b/mojo/services/speech_recognizer/interfaces/speech_recognizer.mojom
@@ -33,6 +33,7 @@
// |SpeechRecognizerService| provides access to a speech recognition service.
// It is responsible for reading microphone input, deciding when the user is
// done speaking, and performing speech recognition on the result.
+[ServiceName="speech_recognizer::SpeechRecognizerService"]
interface SpeechRecognizerService {
// Starts listening to the user. When listening has finished or an error
// occurs, returns |result_or_error|. Any call to Listen() made while another
@@ -42,4 +43,4 @@
// Stops the SpeechRecognizer from listening and finishes any previous call
// to Listen() causing it to return.
StopListening();
-};
\ No newline at end of file
+};
diff --git a/mojo/services/vsync/interfaces/vsync.mojom b/mojo/services/vsync/interfaces/vsync.mojom
index 5cc66a1..10fb50f 100644
--- a/mojo/services/vsync/interfaces/vsync.mojom
+++ b/mojo/services/vsync/interfaces/vsync.mojom
@@ -5,6 +5,7 @@
[DartPackage="mojo_services"]
module vsync;
+[ServiceName="vsync::VSyncProvider"]
interface VSyncProvider {
// Waits for the next vsync and returns its timestamp once it happens. The
// timestamps can only be compared with other calls of this method.
diff --git a/services/intent_receiver/intent_receiver.mojom b/services/intent_receiver/intent_receiver.mojom
index 8ca92b4..a88874c 100644
--- a/services/intent_receiver/intent_receiver.mojom
+++ b/services/intent_receiver/intent_receiver.mojom
@@ -6,6 +6,7 @@
module intent_receiver;
// Service to interact with android intents.
+[ServiceName="intent_receiver::IntentReceiverManager"]
interface IntentReceiverManager {
// This method takes an |IntentReceiver| and returns a serialized intent.
// The serialized intent can be deserialized using an android parcel. The
diff --git a/services/nfc_message_sink/nfc_message_sink.mojom b/services/nfc_message_sink/nfc_message_sink.mojom
index d7adb85..e0c0598 100644
--- a/services/nfc_message_sink/nfc_message_sink.mojom
+++ b/services/nfc_message_sink/nfc_message_sink.mojom
@@ -8,6 +8,7 @@
// Private interface for the shell. When the shell connects to |Nfc| this
// interface will be returned which can be used to send NFC data to registered
// apps.
+[ServiceName="nfc_message_sink::NfcMessageSink"]
interface NfcMessageSink {
OnNfcMessage(array<uint8> data);
};
diff --git a/services/sharing_sink/sharing_sink.mojom b/services/sharing_sink/sharing_sink.mojom
index 28b221a..6128f11 100644
--- a/services/sharing_sink/sharing_sink.mojom
+++ b/services/sharing_sink/sharing_sink.mojom
@@ -8,6 +8,7 @@
// Private interface for the shell. When the shell connects to the sharing
// service this interface will be returned which can be used to send shareable
// data to registered apps.
+[ServiceName="sharing_sink::SharingSink"]
interface SharingSink {
OnTextShared(string data);
};