Skip to content

Commit fd390f7

Browse files
committed
Add Deferred<T> api definitions.
This is needed to start preparing interop interfaces before we enable deferred lint enforcement.
1 parent 3932951 commit fd390f7

File tree

5 files changed

+124
-5
lines changed

5 files changed

+124
-5
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2020 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.firebase.components.annotations;
16+
17+
import com.google.firebase.inject.Deferred.DeferredHandler;
18+
import java.lang.annotation.ElementType;
19+
import java.lang.annotation.Inherited;
20+
import java.lang.annotation.Retention;
21+
import java.lang.annotation.RetentionPolicy;
22+
import java.lang.annotation.Target;
23+
24+
/**
25+
* Indicates that the annotated symbol should be called from a {@link
26+
* com.google.firebase.inject.Deferred} dependency.
27+
*
28+
* <p>This is particularly important for callback-style APIs in the context of <a
29+
* href="https://developer.android.com/guide/app-bundle/play-feature-delivery">dynamically loaded
30+
* modules</a>.
31+
*
32+
* <p>Calling {@link DeferredApi }-annotated methods is allowed only from:
33+
*
34+
* <ol>
35+
* <li>{@link com.google.firebase.inject.Deferred#whenAvailable(DeferredHandler)} handlers.
36+
* <li>Any method that is itself annotated with {@link DeferredApi}(Useful to be able to call such
37+
* methods from {@link com.google.firebase.inject.Deferred#whenAvailable(DeferredHandler)}).
38+
*/
39+
@Target({ElementType.METHOD, ElementType.CONSTRUCTOR})
40+
@Retention(RetentionPolicy.CLASS)
41+
@Inherited
42+
public @interface DeferredApi {}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2018 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/** @hide */
16+
package com.google.firebase.components.annotations;
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright 2020 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.firebase.inject;
16+
17+
import androidx.annotation.NonNull;
18+
import com.google.firebase.components.annotations.DeferredApi;
19+
20+
/**
21+
* Represents a continuation-style dependency.
22+
*
23+
* <p>The motivation for it is to model optional dependencies that may become available in the
24+
* future and once they do, the depender will get notified automatically via the registered {@link
25+
* DeferredHandler}.
26+
*
27+
* <p>Example:
28+
*
29+
* <pre>{@code
30+
* class Foo {
31+
* Foo(Deferred<Bar> bar) {
32+
* bar.whenAvailable(barProvider -> {
33+
* // automatically called when Bar becomes available
34+
* use(barProvider.get());
35+
* });
36+
* }
37+
* }
38+
* }</pre>
39+
*/
40+
public interface Deferred<T> {
41+
/** Used by dependers to register their callbacks. */
42+
interface DeferredHandler<T> {
43+
@DeferredApi
44+
void handle(Provider<T> provider);
45+
}
46+
47+
/** Register a callback that is executed once {@link T} becomes available */
48+
void whenAvailable(@NonNull DeferredHandler<T> handler);
49+
}

firebase-components/src/main/java/com/google/firebase/inject/Provider.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@
1414

1515
package com.google.firebase.inject;
1616

17-
/**
18-
* Provides instances of T.
19-
*
20-
* @hide
21-
*/
17+
/** Provides instances of T. */
2218
public interface Provider<T> {
2319
/** Provides a fully constructed instance of T. */
2420
T get();
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2018 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/** @hide */
16+
package com.google.firebase.inject;

0 commit comments

Comments
 (0)