Skip to content

Commit 4900968

Browse files
Harry Terkelsenditman
Harry Terkelsen
authored andcommitted
[firebase_core] Add platform interface (#1324)
* Move firebase_core to firebase_core/firebase_core * Add firebase_core_platform_interface package * Update cirrus scripts and documentation
1 parent 9c4d0f4 commit 4900968

File tree

91 files changed

+606
-10
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+606
-10
lines changed

packages/firebase_core/CHANGELOG.md renamed to packages/firebase_core/firebase_core/CHANGELOG.md

Lines changed: 4 additions & 0 deletions

packages/firebase_core/pubspec.yaml renamed to packages/firebase_core/firebase_core/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ name: firebase_core
22
description: Flutter plugin for Firebase Core, enabling connecting to multiple
33
Firebase apps.
44
author: Flutter Team <[email protected]>
5-
homepage: https://github.com/FirebaseExtended/flutterfire/tree/master/packages/firebase_core
6-
version: 0.4.1+5
5+
homepage: https://github.com/FirebaseExtended/flutterfire/tree/master/packages/firebase_core/firebase_core
6+
version: 0.4.1+6
77

88
flutter:
99
plugin:
Lines changed: 3 additions & 0 deletions
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2017 The Chromium Authors. All rights reserved.
2+
//
3+
// Redistribution and use in source and binary forms, with or without
4+
// modification, are permitted provided that the following conditions are
5+
// met:
6+
//
7+
// * Redistributions of source code must retain the above copyright
8+
// notice, this list of conditions and the following disclaimer.
9+
// * Redistributions in binary form must reproduce the above
10+
// copyright notice, this list of conditions and the following disclaimer
11+
// in the documentation and/or other materials provided with the
12+
// distribution.
13+
// * Neither the name of Google Inc. nor the names of its
14+
// contributors may be used to endorse or promote products derived from
15+
// this software without specific prior written permission.
16+
//
17+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Lines changed: 26 additions & 0 deletions
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// Copyright 2019 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'dart:async';
6+
7+
import 'package:meta/meta.dart' show visibleForTesting;
8+
9+
import 'src/firebase_options.dart';
10+
import 'src/method_channel_firebase_core.dart';
11+
import 'src/platform_firebase_app.dart';
12+
13+
export 'src/firebase_options.dart';
14+
export 'src/method_channel_firebase_core.dart';
15+
export 'src/platform_firebase_app.dart';
16+
17+
/// The interface that implementations of `firebase_core` must extend.
18+
///
19+
/// Platform implementations should extend this class rather than implement it
20+
/// as `firebase_core` does not consider newly added methods to be breaking
21+
/// changes. Extending this class (using `extends`) ensures that the subclass
22+
/// will get the default implementation, while platform implementations that
23+
/// `implements` this interface will be broken by newly added
24+
/// [FirebaseCorePlatform] methods.
25+
abstract class FirebaseCorePlatform {
26+
/// Only mock implementations should set this to `true`.
27+
///
28+
/// Mockito mocks implement this class with `implements` which is forbidden
29+
/// (see class docs). This property provides a backdoor for mocks to skip the
30+
/// verification that the class isn't implemented with `implements`.
31+
@visibleForTesting
32+
bool get isMock => false;
33+
34+
/// The default instance of [FirebaseCorePlatform] to use.
35+
///
36+
/// Platform-specific plugins should override this with their own class
37+
/// that extends [FirebaseCorePlatform] when they register themselves.
38+
///
39+
/// Defaults to [MethodChannelFirebaseCore].
40+
static FirebaseCorePlatform get instance => _instance;
41+
42+
static FirebaseCorePlatform _instance = MethodChannelFirebaseCore();
43+
44+
// TODO(amirh): Extract common platform interface logic.
45+
// https://github.com/flutter/flutter/issues/43368
46+
static set instance(FirebaseCorePlatform instance) {
47+
if (!instance.isMock) {
48+
try {
49+
instance._verifyProvidesDefaultImplementations();
50+
} on NoSuchMethodError catch (_) {
51+
throw AssertionError(
52+
'Platform interfaces must not be implemented with `implements`');
53+
}
54+
}
55+
_instance = instance;
56+
}
57+
58+
/// This method ensures that [FirebaseCorePlatform] isn't implemented with `implements`.
59+
///
60+
/// See class docs for more details on why using `implements` to implement
61+
/// [FirebaseCorePlatform] is forbidden.
62+
///
63+
/// This private method is called by the [instance] setter, which should fail
64+
/// if the provided instance is a class implemented with `implements`.
65+
void _verifyProvidesDefaultImplementations() {}
66+
67+
/// Returns the data for the Firebase app with the given [name].
68+
///
69+
/// If there is no such app, returns null.
70+
Future<PlatformFirebaseApp> appNamed(String name) {
71+
throw UnimplementedError('appNamed() has not been implemented.');
72+
}
73+
74+
/// Configures the app named [name] with the given [options].
75+
Future<void> configure(String name, FirebaseOptions options) {
76+
throw UnimplementedError('configure() has not been implemented.');
77+
}
78+
79+
/// Returns a list of all extant Firebase app instances.
80+
///
81+
/// If there are no live Firebase apps, returns `null`.
82+
Future<List<PlatformFirebaseApp>> allApps() {
83+
throw UnimplementedError('allApps() has not been implemented.');
84+
}
85+
}
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
// Copyright 2019 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:meta/meta.dart' show required;
6+
import 'package:quiver_hashcode/hashcode.dart';
7+
8+
/// The options used to configure a Firebase app.
9+
class FirebaseOptions {
10+
const FirebaseOptions({
11+
this.apiKey,
12+
this.bundleID,
13+
this.clientID,
14+
this.trackingID,
15+
this.gcmSenderID,
16+
this.projectID,
17+
this.androidClientID,
18+
@required this.googleAppID,
19+
this.databaseURL,
20+
this.deepLinkURLScheme,
21+
this.storageBucket,
22+
}) : assert(googleAppID != null);
23+
24+
FirebaseOptions.from(Map<dynamic, dynamic> map)
25+
: apiKey = map['APIKey'],
26+
bundleID = map['bundleID'],
27+
clientID = map['clientID'],
28+
trackingID = map['trackingID'],
29+
gcmSenderID = map['GCMSenderID'],
30+
projectID = map['projectID'],
31+
androidClientID = map['androidClientID'],
32+
googleAppID = map['googleAppID'],
33+
databaseURL = map['databaseURL'],
34+
deepLinkURLScheme = map['deepLinkURLScheme'],
35+
storageBucket = map['storageBucket'] {
36+
assert(googleAppID != null);
37+
}
38+
39+
/// An API key used for authenticating requests from your app, e.g.
40+
/// "AIzaSyDdVgKwhZl0sTTTLZ7iTmt1r3N2cJLnaDk", used to identify your app to
41+
/// Google servers.
42+
///
43+
/// This property is required on Android.
44+
final String apiKey;
45+
46+
/// The iOS bundle ID for the application. Defaults to
47+
/// `[[NSBundle mainBundle] bundleID]` when not set manually or in a plist.
48+
///
49+
/// This property is used on iOS only.
50+
final String bundleID;
51+
52+
/// The OAuth2 client ID for iOS application used to authenticate Google
53+
/// users, for example "12345.apps.googleusercontent.com", used for signing in
54+
/// with Google.
55+
///
56+
/// This property is used on iOS only.
57+
final String clientID;
58+
59+
/// The tracking ID for Google Analytics, e.g. "UA-12345678-1", used to
60+
/// configure Google Analytics.
61+
///
62+
/// This property is used on iOS only.
63+
final String trackingID;
64+
65+
/// The Project Number from the Google Developer’s console, for example
66+
/// "012345678901", used to configure Google Cloud Messaging.
67+
///
68+
/// This property is required on iOS.
69+
final String gcmSenderID;
70+
71+
/// The Project ID from the Firebase console, for example "abc-xyz-123."
72+
final String projectID;
73+
74+
/// The Android client ID, for example "12345.apps.googleusercontent.com."
75+
///
76+
/// This property is used on iOS only.
77+
final String androidClientID;
78+
79+
/// The Google App ID that is used to uniquely identify an instance of an app.
80+
///
81+
/// This property cannot be `null`.
82+
final String googleAppID;
83+
84+
/// The database root URL, e.g. "http://abc-xyz-123.firebaseio.com."
85+
///
86+
/// This property should be set for apps that use Firebase Database.
87+
final String databaseURL;
88+
89+
/// The URL scheme used to set up Durable Deep Link service.
90+
///
91+
/// This property is used on iOS only.
92+
final String deepLinkURLScheme;
93+
94+
/// The Google Cloud Storage bucket name, e.g.
95+
/// "abc-xyz-123.storage.firebase.com."
96+
final String storageBucket;
97+
98+
Map<String, String> get asMap {
99+
return <String, String>{
100+
'APIKey': apiKey,
101+
'bundleID': bundleID,
102+
'clientID': clientID,
103+
'trackingID': trackingID,
104+
'GCMSenderID': gcmSenderID,
105+
'projectID': projectID,
106+
'androidClientID': androidClientID,
107+
'googleAppID': googleAppID,
108+
'databaseURL': databaseURL,
109+
'deepLinkURLScheme': deepLinkURLScheme,
110+
'storageBucket': storageBucket,
111+
};
112+
}
113+
114+
@override
115+
bool operator ==(dynamic other) {
116+
if (identical(this, other)) return true;
117+
if (other is! FirebaseOptions) return false;
118+
return other.apiKey == apiKey &&
119+
other.bundleID == bundleID &&
120+
other.clientID == clientID &&
121+
other.trackingID == trackingID &&
122+
other.gcmSenderID == gcmSenderID &&
123+
other.projectID == projectID &&
124+
other.androidClientID == androidClientID &&
125+
other.googleAppID == googleAppID &&
126+
other.databaseURL == databaseURL &&
127+
other.deepLinkURLScheme == deepLinkURLScheme &&
128+
other.storageBucket == storageBucket;
129+
}
130+
131+
@override
132+
int get hashCode {
133+
return hashObjects(
134+
<String>[
135+
apiKey,
136+
bundleID,
137+
clientID,
138+
trackingID,
139+
gcmSenderID,
140+
projectID,
141+
androidClientID,
142+
googleAppID,
143+
databaseURL,
144+
deepLinkURLScheme,
145+
storageBucket,
146+
],
147+
);
148+
}
149+
150+
@override
151+
String toString() => asMap.toString();
152+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright 2019 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'dart:async';
6+
7+
import 'package:flutter/services.dart';
8+
import 'package:meta/meta.dart' show visibleForTesting;
9+
10+
import '../firebase_core_platform_interface.dart';
11+
12+
class MethodChannelFirebaseCore extends FirebaseCorePlatform {
13+
@visibleForTesting
14+
static const MethodChannel channel = MethodChannel(
15+
'plugins.flutter.io/firebase_core',
16+
);
17+
18+
@override
19+
Future<PlatformFirebaseApp> appNamed(String name) async {
20+
final Map<String, dynamic> app =
21+
await channel.invokeMapMethod<String, dynamic>(
22+
'FirebaseApp#appNamed',
23+
name,
24+
);
25+
if (app == null) return null;
26+
return PlatformFirebaseApp(
27+
app['name'], FirebaseOptions.from(app['options']));
28+
}
29+
30+
@override
31+
Future<void> configure(String name, FirebaseOptions options) {
32+
return channel.invokeMethod<void>(
33+
'FirebaseApp#configure',
34+
<String, dynamic>{'name': name, 'options': options.asMap},
35+
);
36+
}
37+
38+
@override
39+
Future<List<PlatformFirebaseApp>> allApps() async {
40+
final List<dynamic> result = await channel.invokeListMethod<dynamic>(
41+
'FirebaseApp#allApps',
42+
);
43+
return result
44+
?.map<PlatformFirebaseApp>(
45+
(dynamic app) => PlatformFirebaseApp(
46+
app['name'],
47+
FirebaseOptions.from(app['options']),
48+
),
49+
)
50+
?.toList();
51+
}
52+
}

0 commit comments

Comments
 (0)