-
Notifications
You must be signed in to change notification settings - Fork 4k
[firebase_core] Add platform interface #1324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ditman
merged 12 commits into
firebase:master
from
harryterkelsen:firebase-core-platform
Nov 14, 2019
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
480cb20
Move firebase_core to firebase_core/firebase_core
harryterkelsen f1703bb
Add firebase_core_platform_interface package
harryterkelsen 1a0a5a9
Update cirrus scripts and add README
harryterkelsen 3b47add
Merge branch 'master' into firebase-core-platform
harryterkelsen 2112a41
Fix typos and homepage url. Clean up `configure` method.
harryterkelsen df8f5c4
Merge branch 'master' into firebase-core-platform
harryterkelsen 4ee2edc
Rename FirebaseAppData to PlatformFirebaseApp
harryterkelsen c8d5bd3
Sort imports alphabetically
harryterkelsen fc51b1f
dartfmt
harryterkelsen 2bb9878
Merge branch 'master' into firebase-core-platform
harryterkelsen def089b
Try testing with mojave-xcode-11.2.1-flutter
harryterkelsen c6df031
Merge branch 'master' into firebase-core-platform
harryterkelsen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
4 changes: 4 additions & 0 deletions
4
packages/firebase_core/CHANGELOG.md → .../firebase_core/firebase_core/CHANGELOG.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,8 @@ name: firebase_core | |
description: Flutter plugin for Firebase Core, enabling connecting to multiple | ||
Firebase apps. | ||
author: Flutter Team <[email protected]> | ||
homepage: https://github.com/FirebaseExtended/flutterfire/tree/master/packages/firebase_core | ||
version: 0.4.1+5 | ||
homepage: https://github.com/FirebaseExtended/flutterfire/tree/master/packages/firebase_core/firebase_core | ||
version: 0.4.1+6 | ||
|
||
flutter: | ||
plugin: | ||
|
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions
3
packages/firebase_core/firebase_core_platform_interface/CHANGELOG.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## 1.0.0 | ||
|
||
- Initial open-source release. |
27 changes: 27 additions & 0 deletions
27
packages/firebase_core/firebase_core_platform_interface/LICENSE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2017 The Chromium Authors. All rights reserved. | ||
// | ||
// Redistribution and use in source and binary forms, with or without | ||
// modification, are permitted provided that the following conditions are | ||
// met: | ||
// | ||
// * Redistributions of source code must retain the above copyright | ||
// notice, this list of conditions and the following disclaimer. | ||
// * Redistributions in binary form must reproduce the above | ||
// copyright notice, this list of conditions and the following disclaimer | ||
// in the documentation and/or other materials provided with the | ||
// distribution. | ||
// * Neither the name of Google Inc. nor the names of its | ||
// contributors may be used to endorse or promote products derived from | ||
// this software without specific prior written permission. | ||
// | ||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 changes: 26 additions & 0 deletions
26
packages/firebase_core/firebase_core_platform_interface/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# firebase_core_platform_interface | ||
|
||
A common platform interface for the [`firebase_core`][1] plugin. | ||
|
||
This interface allows platform-specific implementations of the `firebase_core` | ||
plugin, as well as the plugin itself, to ensure they are supporting the | ||
same interface. | ||
|
||
# Usage | ||
|
||
To implement a new platform-specific implementation of `firebase_core`, extend | ||
[`FirebaseCorePlatform`][2] with an implementation that performs the | ||
platform-specific behavior, and when you register your plugin, set the default | ||
`FirebaseCorePlatform` by calling | ||
`FirebaseCorePlatform.instance = MyFirebaseCore()`. | ||
|
||
# Note on breaking changes | ||
|
||
Strongly prefer non-breaking changes (such as adding a method to the interface) | ||
over breaking changes for this package. | ||
|
||
See https://flutter.dev/go/platform-interface-breaking-changes for a discussion | ||
on why a less-clean interface is preferable to a breaking change. | ||
|
||
[1]: ../firebase_core | ||
[2]: lib/firebase_core_platform_interface.dart |
85 changes: 85 additions & 0 deletions
85
.../firebase_core/firebase_core_platform_interface/lib/firebase_core_platform_interface.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Copyright 2019 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. | ||
|
||
import 'dart:async'; | ||
|
||
import 'package:meta/meta.dart' show visibleForTesting; | ||
|
||
import 'src/firebase_options.dart'; | ||
import 'src/method_channel_firebase_core.dart'; | ||
import 'src/platform_firebase_app.dart'; | ||
|
||
export 'src/firebase_options.dart'; | ||
export 'src/method_channel_firebase_core.dart'; | ||
export 'src/platform_firebase_app.dart'; | ||
|
||
/// The interface that implementations of `firebase_core` must extend. | ||
/// | ||
/// Platform implementations should extend this class rather than implement it | ||
/// as `firebase_core` does not consider newly added methods to be breaking | ||
/// changes. Extending this class (using `extends`) ensures that the subclass | ||
/// will get the default implementation, while platform implementations that | ||
/// `implements` this interface will be broken by newly added | ||
/// [FirebaseCorePlatform] methods. | ||
abstract class FirebaseCorePlatform { | ||
/// Only mock implementations should set this to `true`. | ||
/// | ||
/// Mockito mocks implement this class with `implements` which is forbidden | ||
/// (see class docs). This property provides a backdoor for mocks to skip the | ||
/// verification that the class isn't implemented with `implements`. | ||
@visibleForTesting | ||
bool get isMock => false; | ||
|
||
/// The default instance of [FirebaseCorePlatform] to use. | ||
/// | ||
/// Platform-specific plugins should override this with their own class | ||
/// that extends [FirebaseCorePlatform] when they register themselves. | ||
/// | ||
/// Defaults to [MethodChannelFirebaseCore]. | ||
static FirebaseCorePlatform get instance => _instance; | ||
|
||
static FirebaseCorePlatform _instance = MethodChannelFirebaseCore(); | ||
|
||
// TODO(amirh): Extract common platform interface logic. | ||
// https://github.com/flutter/flutter/issues/43368 | ||
static set instance(FirebaseCorePlatform instance) { | ||
if (!instance.isMock) { | ||
try { | ||
instance._verifyProvidesDefaultImplementations(); | ||
} on NoSuchMethodError catch (_) { | ||
throw AssertionError( | ||
'Platform interfaces must not be implemented with `implements`'); | ||
} | ||
} | ||
_instance = instance; | ||
} | ||
|
||
/// This method ensures that [FirebaseCorePlatform] isn't implemented with `implements`. | ||
/// | ||
/// See class docs for more details on why using `implements` to implement | ||
/// [FirebaseCorePlatform] is forbidden. | ||
/// | ||
/// This private method is called by the [instance] setter, which should fail | ||
/// if the provided instance is a class implemented with `implements`. | ||
void _verifyProvidesDefaultImplementations() {} | ||
|
||
/// Returns the data for the Firebase app with the given [name]. | ||
/// | ||
/// If there is no such app, returns null. | ||
Future<PlatformFirebaseApp> appNamed(String name) { | ||
throw UnimplementedError('appNamed() has not been implemented.'); | ||
} | ||
|
||
/// Configures the app named [name] with the given [options]. | ||
Future<void> configure(String name, FirebaseOptions options) { | ||
throw UnimplementedError('configure() has not been implemented.'); | ||
} | ||
|
||
/// Returns a list of all extant Firebase app instances. | ||
/// | ||
/// If there are no live Firebase apps, returns `null`. | ||
Future<List<PlatformFirebaseApp>> allApps() { | ||
throw UnimplementedError('allApps() has not been implemented.'); | ||
} | ||
} |
152 changes: 152 additions & 0 deletions
152
packages/firebase_core/firebase_core_platform_interface/lib/src/firebase_options.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
// Copyright 2019 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. | ||
|
||
import 'package:meta/meta.dart' show required; | ||
import 'package:quiver_hashcode/hashcode.dart'; | ||
|
||
/// The options used to configure a Firebase app. | ||
class FirebaseOptions { | ||
const FirebaseOptions({ | ||
this.apiKey, | ||
this.bundleID, | ||
this.clientID, | ||
this.trackingID, | ||
this.gcmSenderID, | ||
this.projectID, | ||
this.androidClientID, | ||
@required this.googleAppID, | ||
this.databaseURL, | ||
this.deepLinkURLScheme, | ||
this.storageBucket, | ||
}) : assert(googleAppID != null); | ||
|
||
FirebaseOptions.from(Map<dynamic, dynamic> map) | ||
: apiKey = map['APIKey'], | ||
bundleID = map['bundleID'], | ||
clientID = map['clientID'], | ||
trackingID = map['trackingID'], | ||
gcmSenderID = map['GCMSenderID'], | ||
projectID = map['projectID'], | ||
androidClientID = map['androidClientID'], | ||
googleAppID = map['googleAppID'], | ||
databaseURL = map['databaseURL'], | ||
deepLinkURLScheme = map['deepLinkURLScheme'], | ||
storageBucket = map['storageBucket'] { | ||
assert(googleAppID != null); | ||
} | ||
|
||
/// An API key used for authenticating requests from your app, e.g. | ||
/// "AIzaSyDdVgKwhZl0sTTTLZ7iTmt1r3N2cJLnaDk", used to identify your app to | ||
/// Google servers. | ||
/// | ||
/// This property is required on Android. | ||
final String apiKey; | ||
|
||
/// The iOS bundle ID for the application. Defaults to | ||
/// `[[NSBundle mainBundle] bundleID]` when not set manually or in a plist. | ||
/// | ||
/// This property is used on iOS only. | ||
final String bundleID; | ||
|
||
/// The OAuth2 client ID for iOS application used to authenticate Google | ||
/// users, for example "12345.apps.googleusercontent.com", used for signing in | ||
/// with Google. | ||
/// | ||
/// This property is used on iOS only. | ||
final String clientID; | ||
|
||
/// The tracking ID for Google Analytics, e.g. "UA-12345678-1", used to | ||
/// configure Google Analytics. | ||
/// | ||
/// This property is used on iOS only. | ||
final String trackingID; | ||
|
||
/// The Project Number from the Google Developer’s console, for example | ||
/// "012345678901", used to configure Google Cloud Messaging. | ||
/// | ||
/// This property is required on iOS. | ||
final String gcmSenderID; | ||
|
||
/// The Project ID from the Firebase console, for example "abc-xyz-123." | ||
final String projectID; | ||
|
||
/// The Android client ID, for example "12345.apps.googleusercontent.com." | ||
/// | ||
/// This property is used on iOS only. | ||
final String androidClientID; | ||
|
||
/// The Google App ID that is used to uniquely identify an instance of an app. | ||
/// | ||
/// This property cannot be `null`. | ||
final String googleAppID; | ||
|
||
/// The database root URL, e.g. "http://abc-xyz-123.firebaseio.com." | ||
/// | ||
/// This property should be set for apps that use Firebase Database. | ||
final String databaseURL; | ||
|
||
/// The URL scheme used to set up Durable Deep Link service. | ||
/// | ||
/// This property is used on iOS only. | ||
final String deepLinkURLScheme; | ||
|
||
/// The Google Cloud Storage bucket name, e.g. | ||
/// "abc-xyz-123.storage.firebase.com." | ||
final String storageBucket; | ||
|
||
Map<String, String> get asMap { | ||
return <String, String>{ | ||
'APIKey': apiKey, | ||
'bundleID': bundleID, | ||
'clientID': clientID, | ||
'trackingID': trackingID, | ||
'GCMSenderID': gcmSenderID, | ||
'projectID': projectID, | ||
'androidClientID': androidClientID, | ||
'googleAppID': googleAppID, | ||
'databaseURL': databaseURL, | ||
'deepLinkURLScheme': deepLinkURLScheme, | ||
'storageBucket': storageBucket, | ||
}; | ||
} | ||
|
||
@override | ||
bool operator ==(dynamic other) { | ||
harryterkelsen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (identical(this, other)) return true; | ||
if (other is! FirebaseOptions) return false; | ||
return other.apiKey == apiKey && | ||
other.bundleID == bundleID && | ||
other.clientID == clientID && | ||
other.trackingID == trackingID && | ||
other.gcmSenderID == gcmSenderID && | ||
other.projectID == projectID && | ||
other.androidClientID == androidClientID && | ||
other.googleAppID == googleAppID && | ||
other.databaseURL == databaseURL && | ||
other.deepLinkURLScheme == deepLinkURLScheme && | ||
other.storageBucket == storageBucket; | ||
} | ||
|
||
@override | ||
int get hashCode { | ||
return hashObjects( | ||
<String>[ | ||
apiKey, | ||
bundleID, | ||
clientID, | ||
trackingID, | ||
gcmSenderID, | ||
projectID, | ||
androidClientID, | ||
googleAppID, | ||
databaseURL, | ||
deepLinkURLScheme, | ||
storageBucket, | ||
], | ||
); | ||
} | ||
|
||
@override | ||
String toString() => asMap.toString(); | ||
} |
52 changes: 52 additions & 0 deletions
52
.../firebase_core/firebase_core_platform_interface/lib/src/method_channel_firebase_core.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2019 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. | ||
|
||
import 'dart:async'; | ||
|
||
import 'package:flutter/services.dart'; | ||
import 'package:meta/meta.dart' show visibleForTesting; | ||
|
||
import '../firebase_core_platform_interface.dart'; | ||
|
||
class MethodChannelFirebaseCore extends FirebaseCorePlatform { | ||
@visibleForTesting | ||
static const MethodChannel channel = MethodChannel( | ||
'plugins.flutter.io/firebase_core', | ||
); | ||
|
||
@override | ||
Future<PlatformFirebaseApp> appNamed(String name) async { | ||
final Map<String, dynamic> app = | ||
await channel.invokeMapMethod<String, dynamic>( | ||
'FirebaseApp#appNamed', | ||
name, | ||
); | ||
if (app == null) return null; | ||
return PlatformFirebaseApp( | ||
app['name'], FirebaseOptions.from(app['options'])); | ||
} | ||
|
||
@override | ||
Future<void> configure(String name, FirebaseOptions options) { | ||
return channel.invokeMethod<void>( | ||
'FirebaseApp#configure', | ||
<String, dynamic>{'name': name, 'options': options.asMap}, | ||
); | ||
} | ||
|
||
@override | ||
Future<List<PlatformFirebaseApp>> allApps() async { | ||
final List<dynamic> result = await channel.invokeListMethod<dynamic>( | ||
'FirebaseApp#allApps', | ||
); | ||
return result | ||
?.map<PlatformFirebaseApp>( | ||
(dynamic app) => PlatformFirebaseApp( | ||
app['name'], | ||
FirebaseOptions.from(app['options']), | ||
), | ||
) | ||
?.toList(); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.