This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[firebase_performance] Java side of FirebasePerformance rewrite #1529
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
66ada54
Java side of FirebasePerformance rewrite
bparrishMines f20ad54
Merge branch 'master' of github.com:flutter/plugins into perf_rewrite
bparrishMines cfa200c
Formatting and suppressing warnings
bparrishMines e3aa0e9
Update metric take individual parameters
bparrishMines 588c7fb
Unregister MethodCallHandler
bparrishMines 55d6999
Parse HttpMethod
bparrishMines 08d976f
Extra space
bparrishMines 353641e
Change method name to setMetric
bparrishMines c07c810
Redesign of flutter plugin objects
bparrishMines f9f05b7
Fix some method calls
bparrishMines 1a35bde
Move ConstantConditions and generic handler call
bparrishMines 2a3f0b2
attribute to name
bparrishMines 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
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
107 changes: 107 additions & 0 deletions
107
...roid/src/main/java/io/flutter/plugins/firebaseperformance/FlutterFirebasePerformance.java
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,107 @@ | ||
| // 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. | ||
|
|
||
| package io.flutter.plugins.firebaseperformance; | ||
|
|
||
| import com.google.firebase.perf.FirebasePerformance; | ||
| import com.google.firebase.perf.metrics.HttpMetric; | ||
| import com.google.firebase.perf.metrics.Trace; | ||
| import io.flutter.plugin.common.MethodCall; | ||
| import io.flutter.plugin.common.MethodChannel; | ||
|
|
||
| public class FlutterFirebasePerformance implements MethodChannel.MethodCallHandler { | ||
| private static String parseHttpMethod(String httpMethod) { | ||
| switch (httpMethod) { | ||
| case "HttpMethod.Connect": | ||
| return FirebasePerformance.HttpMethod.CONNECT; | ||
| case "HttpMethod.Delete": | ||
| return FirebasePerformance.HttpMethod.DELETE; | ||
| case "HttpMethod.Get": | ||
| return FirebasePerformance.HttpMethod.GET; | ||
| case "HttpMethod.Head": | ||
| return FirebasePerformance.HttpMethod.HEAD; | ||
| case "HttpMethod.Options": | ||
| return FirebasePerformance.HttpMethod.OPTIONS; | ||
| case "HttpMethod.Patch": | ||
| return FirebasePerformance.HttpMethod.PATCH; | ||
| case "HttpMethod.Post": | ||
| return FirebasePerformance.HttpMethod.POST; | ||
| case "HttpMethod.Put": | ||
| return FirebasePerformance.HttpMethod.PUT; | ||
| case "HttpMethod.Trace": | ||
| return FirebasePerformance.HttpMethod.TRACE; | ||
| default: | ||
| throw new IllegalArgumentException(String.format("No HttpMethod for: %s", httpMethod)); | ||
| } | ||
| } | ||
|
|
||
| private final FirebasePerformance performance; | ||
|
|
||
| @SuppressWarnings("ConstantConditions") | ||
| static void getInstance(MethodCall call, MethodChannel.Result result) { | ||
| final Integer handle = call.argument("handle"); | ||
| FirebasePerformancePlugin.addHandler(handle, new FlutterFirebasePerformance()); | ||
| result.success(null); | ||
| } | ||
|
|
||
| private FlutterFirebasePerformance() { | ||
| this.performance = FirebasePerformance.getInstance(); | ||
| } | ||
|
|
||
| @Override | ||
| public void onMethodCall(MethodCall call, MethodChannel.Result result) { | ||
| switch (call.method) { | ||
| case "FirebasePerformance#isPerformanceCollectionEnabled": | ||
| isPerformanceCollectionEnabled(result); | ||
| break; | ||
| case "FirebasePerformance#setPerformanceCollectionEnabled": | ||
| setPerformanceCollectionEnabled(call, result); | ||
| break; | ||
| case "FirebasePerformance#newTrace": | ||
| newTrace(call, result); | ||
| break; | ||
| case "FirebasePerformance#newHttpMetric": | ||
| newHttpMetric(call, result); | ||
| break; | ||
| default: | ||
| result.notImplemented(); | ||
| } | ||
| } | ||
|
|
||
| private void isPerformanceCollectionEnabled(MethodChannel.Result result) { | ||
| result.success(performance.isPerformanceCollectionEnabled()); | ||
| } | ||
|
|
||
| @SuppressWarnings("ConstantConditions") | ||
| private void setPerformanceCollectionEnabled(MethodCall call, MethodChannel.Result result) { | ||
| final Boolean enable = call.argument("enable"); | ||
| performance.setPerformanceCollectionEnabled(enable); | ||
|
|
||
| result.success(null); | ||
| } | ||
|
|
||
| @SuppressWarnings("ConstantConditions") | ||
| private void newTrace(MethodCall call, MethodChannel.Result result) { | ||
| final String name = call.argument("name"); | ||
| final Trace trace = performance.newTrace(name); | ||
|
|
||
| final Integer handle = call.argument("traceHandle"); | ||
| FirebasePerformancePlugin.addHandler(handle, new FlutterTrace(trace)); | ||
|
|
||
| result.success(null); | ||
| } | ||
|
|
||
| @SuppressWarnings("ConstantConditions") | ||
| private void newHttpMetric(MethodCall call, MethodChannel.Result result) { | ||
| final String url = call.argument("url"); | ||
| final String httpMethod = call.argument("httpMethod"); | ||
|
|
||
| final HttpMetric metric = performance.newHttpMetric(url, parseHttpMethod(httpMethod)); | ||
|
|
||
| final Integer handle = call.argument("httpMetricHandle"); | ||
| FirebasePerformancePlugin.addHandler(handle, new FlutterHttpMetric(metric)); | ||
|
|
||
| result.success(null); | ||
| } | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like you split the plugin class into two parts which is different from what we're doing with other first-party plugins. Is this a new convention that you'd like to see applied to all of Flutterfire and plugins generally? If so we could file an issue to update the
flutter create -t pluginbehavior. Or if not, it might be better to leave it the way it is for consistency.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I only separated this part as the FirebasePerformance plugin doesn't have any other classes that you can instantiate on there own. (e.g. to create an object you use
FirebasePeformance.newTrace()orFirebasePeformance.newHttpMetric(). ML Kit works the same way, but Firebase Dynamic Links doesn't.I created this PR to get feedback on creating separate
MethodChannels for each class. Although its require more code, i think it's easier to read/maintain.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm on board with splitting things into more classes, generally. I'm ok with using it for this plugin as a one-off and we can discuss offline if we want to adopt the approach for plugins generally.