Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
66ada54
Java side of FirebasePerformance rewrite
bparrishMines Apr 22, 2019
784ebc1
Performance rewrite dart side
bparrishMines Apr 22, 2019
7b061ed
Merge branch 'master' of github.com:flutter/plugins into perf_rewrite…
bparrishMines Apr 22, 2019
f20ad54
Merge branch 'master' of github.com:flutter/plugins into perf_rewrite
bparrishMines Apr 22, 2019
b3d698c
Undo changes
bparrishMines Apr 22, 2019
cfa200c
Formatting and suppressing warnings
bparrishMines Apr 22, 2019
e3aa0e9
Update metric take individual parameters
bparrishMines Apr 23, 2019
db5acb6
Update HttpMetric
bparrishMines Apr 23, 2019
588c7fb
Unregister MethodCallHandler
bparrishMines Apr 23, 2019
55d6999
Parse HttpMethod
bparrishMines Apr 23, 2019
236da2c
Fix MethodChannel Unit tests
bparrishMines Apr 23, 2019
08d976f
Extra space
bparrishMines Apr 23, 2019
8a8ab77
Remove awaits and ayncs
bparrishMines Apr 23, 2019
3c3ed91
Remove mentions of asynchronous
bparrishMines Apr 23, 2019
bd971ab
cache state
bparrishMines Apr 23, 2019
849d625
Comments/Testings/Variables/Misc
bparrishMines Apr 24, 2019
b08ad05
Change putMetric to setMetric to match iOS API. Also add name variable
bparrishMines Apr 24, 2019
353641e
Change method name to setMetric
bparrishMines Apr 24, 2019
0295e2e
Start of perf iOS
bparrishMines Apr 24, 2019
f581dd9
Firebase Performance iOS finish
bparrishMines Apr 25, 2019
c07c810
Redesign of flutter plugin objects
bparrishMines Apr 30, 2019
7800e5d
3rd redesign :(
bparrishMines Apr 30, 2019
f9f05b7
Fix some method calls
bparrishMines Apr 30, 2019
1a35bde
Move ConstantConditions and generic handler call
bparrishMines Apr 30, 2019
3e6fe50
Redesign for iOS
bparrishMines May 1, 2019
21fd8cb
Formatting
bparrishMines May 1, 2019
209ce96
Merge remote-tracking branch 'origin/perf_rewrite' into perf_combine
bparrishMines May 1, 2019
5548da9
Merge remote-tracking branch 'origin/perf_rewrite_dart' into perf_com…
bparrishMines May 1, 2019
41f354e
Merge remote-tracking branch 'origin/perf_rewrite_ios' into perf_combine
bparrishMines May 1, 2019
dab9281
Merge remote-tracking branch 'origin/perf_rewrite' into perf_combine
bparrishMines May 1, 2019
2993ed9
Merge remote-tracking branch 'origin/perf_rewrite_dart' into perf_com…
bparrishMines May 1, 2019
83aa1a9
formattinn
bparrishMines May 1, 2019
03fca3f
Merge remote-tracking branch 'origin/perf_rewrite_ios' into perf_combine
bparrishMines May 1, 2019
acfa84a
integeration testing
bparrishMines May 1, 2019
9d8ff82
Update testing
bparrishMines May 1, 2019
2a3f0b2
attribute to name
bparrishMines May 1, 2019
e206958
Merge remote-tracking branch 'origin/perf_rewrite_dart' into perf_com…
bparrishMines May 1, 2019
320fbb7
Merge remote-tracking branch 'origin/perf_rewrite' into perf_combine
bparrishMines May 1, 2019
96ffe49
Fix method call name
bparrishMines May 1, 2019
912e3bf
Merge branch 'perf_rewrite_ios' into perf_combine
bparrishMines May 1, 2019
ecd0add
use block notation
bparrishMines May 1, 2019
22ccd63
Merge remote-tracking branch 'origin/perf_rewrite_ios' into perf_combine
bparrishMines May 1, 2019
f1b7a7e
Missed https://
bparrishMines May 1, 2019
d6f2519
Temporarily remove integration tests
bparrishMines May 1, 2019
7f96745
Temporarily remove integration tests
bparrishMines May 2, 2019
52f04b8
Make sharedInstance a constructor
bparrishMines May 6, 2019
3b04e84
Merge remote-tracking branch 'origin/perf_rewrite_ios' into perf_combine
bparrishMines May 6, 2019
fda650f
Update FirebasePerformancePlugin.m
bparrishMines May 6, 2019
c023985
Update FirebasePerformancePlugin.m
bparrishMines May 6, 2019
71ad2ea
Create internal methods
bparrishMines May 7, 2019
2bef24d
Merge remote-tracking branch 'origin/perf_rewrite_ios' into perf_combine
bparrishMines May 7, 2019
58f736d
testin
bparrishMines May 7, 2019
21a67f8
Use MethodCallHandler protocol
bparrishMines May 9, 2019
22164f3
Merge branch 'perf_rewrite_ios' into perf_combine
bparrishMines May 9, 2019
a04ef6a
Add note about leaking
bparrishMines May 9, 2019
1a16eb6
Merge remote-tracking branch 'origin/perf_rewrite_dart' into perf_com…
bparrishMines May 9, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,160 +5,53 @@
package io.flutter.plugins.firebaseperformance;

import android.util.SparseArray;
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;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugin.common.PluginRegistry.Registrar;
import java.util.Map;

/** FirebasePerformancePlugin */
public class FirebasePerformancePlugin implements MethodCallHandler {
private FirebasePerformance firebasePerformance;
public class FirebasePerformancePlugin implements MethodChannel.MethodCallHandler {
private static final String CHANNEL_NAME = "plugins.flutter.io/firebase_performance";

private final SparseArray<Trace> traces = new SparseArray<>();
private final SparseArray<HttpMetric> httpMetrics = new SparseArray<>();
private static final SparseArray<MethodChannel.MethodCallHandler> handlers = new SparseArray<>();

public static void registerWith(Registrar registrar) {
final MethodChannel channel =
new MethodChannel(registrar.messenger(), "plugins.flutter.io/firebase_performance");
final MethodChannel channel = new MethodChannel(registrar.messenger(), CHANNEL_NAME);
channel.setMethodCallHandler(new FirebasePerformancePlugin());
}

private FirebasePerformancePlugin() {
firebasePerformance = FirebasePerformance.getInstance();
}

@Override
public void onMethodCall(MethodCall call, Result result) {
switch (call.method) {
case "FirebasePerformance#isPerformanceCollectionEnabled":
result.success(firebasePerformance.isPerformanceCollectionEnabled());
break;
case "FirebasePerformance#setPerformanceCollectionEnabled":
final boolean enabled = (boolean) call.arguments;
firebasePerformance.setPerformanceCollectionEnabled(enabled);
result.success(null);
break;
case "Trace#start":
handleTraceStart(call, result);
break;
case "Trace#stop":
handleTraceStop(call, result);
break;
case "HttpMetric#start":
handleHttpMetricStart(call, result);
break;
case "HttpMetric#stop":
handleHttpMetricStop(call, result);
break;
default:
public void onMethodCall(MethodCall call, MethodChannel.Result result) {
if (call.method.equals("FirebasePerformance#instance")) {
FlutterFirebasePerformance.getInstance(call, result);
} else {
final MethodChannel.MethodCallHandler handler = getHandler(call);

if (handler != null) {
handler.onMethodCall(call, result);
} else {
result.notImplemented();
}
}
}

private void handleTraceStart(MethodCall call, Result result) {
Integer handle = call.argument("handle");
String name = call.argument("name");

Trace trace = firebasePerformance.newTrace(name);

traces.put(handle, trace);

trace.start();
result.success(null);
}

private void handleTraceStop(MethodCall call, Result result) {
Integer handle = call.argument("handle");
Trace trace = traces.get(handle);

Map<String, Integer> metrics = call.argument("metrics");
for (Map.Entry<String, Integer> entry : metrics.entrySet()) {
trace.incrementMetric(entry.getKey(), entry.getValue());
}

Map<String, String> attributes = call.argument("attributes");
for (Map.Entry<String, String> entry : attributes.entrySet()) {
trace.putAttribute(entry.getKey(), entry.getValue());
static void addHandler(final int handle, final MethodChannel.MethodCallHandler handler) {
if (handlers.get(handle) != null) {
final String message = String.format("Object for handle already exists: %s", handle);
throw new IllegalArgumentException(message);
}

trace.stop();
traces.remove(handle);
result.success(null);
handlers.put(handle, handler);
}

private void handleHttpMetricStart(MethodCall call, Result result) {
Integer handle = call.argument("handle");
String url = call.argument("url");

int httpMethod = call.argument("httpMethod");
String httpMethodStr;
switch (httpMethod) {
case 0:
httpMethodStr = FirebasePerformance.HttpMethod.CONNECT;
break;
case 1:
httpMethodStr = FirebasePerformance.HttpMethod.DELETE;
break;
case 2:
httpMethodStr = FirebasePerformance.HttpMethod.GET;
break;
case 3:
httpMethodStr = FirebasePerformance.HttpMethod.HEAD;
break;
case 4:
httpMethodStr = FirebasePerformance.HttpMethod.OPTIONS;
break;
case 5:
httpMethodStr = FirebasePerformance.HttpMethod.PATCH;
break;
case 6:
httpMethodStr = FirebasePerformance.HttpMethod.POST;
break;
case 7:
httpMethodStr = FirebasePerformance.HttpMethod.PUT;
break;
case 8:
httpMethodStr = FirebasePerformance.HttpMethod.TRACE;
break;
default:
httpMethodStr = null;
break;
}

HttpMetric metric = firebasePerformance.newHttpMetric(url, httpMethodStr);

httpMetrics.put(handle, metric);

metric.start();
result.success(null);
static void removeHandler(final int handle) {
handlers.remove(handle);
}

private void handleHttpMetricStop(MethodCall call, Result result) {
Integer handle = call.argument("handle");
HttpMetric metric = httpMetrics.get(handle);

Integer httpResponseCode = call.argument("httpResponseCode");
Number requestPayloadSize = call.argument("requestPayloadSize");
String responseContentType = call.argument("responseContentType");
Number responsePayloadSize = call.argument("responsePayloadSize");

if (requestPayloadSize != null) metric.setRequestPayloadSize(requestPayloadSize.longValue());
if (httpResponseCode != null) metric.setHttpResponseCode(httpResponseCode);
if (responseContentType != null) metric.setResponseContentType(responseContentType);
if (responsePayloadSize != null) metric.setResponsePayloadSize(responsePayloadSize.longValue());

Map<String, String> attributes = call.argument("attributes");
for (Map.Entry<String, String> entry : attributes.entrySet()) {
metric.putAttribute(entry.getKey(), entry.getValue());
}
private static MethodChannel.MethodCallHandler getHandler(final MethodCall call) {
final Integer handle = call.argument("handle");

metric.stop();
httpMetrics.remove(handle);
result.success(null);
if (handle == null) return null;
return handlers.get(handle);
}
}
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);
}
}
Loading