Commit 48714b9b authored by mef's avatar mef Committed by Commit bot

Expose startNetLog / stopNetLog from HttpUrlRequestFactory.

BUG=417835

Review URL: https://codereview.chromium.org/610673002

Cr-Commit-Position: refs/heads/master@{#297334}
parent 5ec01d81
......@@ -55,6 +55,16 @@ public class ChromiumUrlRequestFactory extends HttpUrlRequestFactory {
headers, channel, listener);
}
@Override
public void startNetLogToFile(String fileName) {
mRequestContext.startNetLogToFile(fileName);
}
@Override
public void stopNetLog() {
mRequestContext.stopNetLog();
}
public ChromiumUrlRequestContext getRequestContext() {
return mRequestContext;
}
......
......@@ -6,6 +6,8 @@ package org.chromium.net;
import android.content.Context;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.channels.WritableByteChannel;
import java.util.Map;
......@@ -45,4 +47,19 @@ class HttpUrlConnectionUrlRequestFactory extends HttpUrlRequestFactory {
return new HttpUrlConnectionUrlRequest(mContext, url, requestPriority,
headers, channel, listener);
}
@Override
public void startNetLogToFile(String fileName) {
try {
PrintWriter out = new PrintWriter(fileName);
out.println("NetLog is not supported by " + getName());
out.close();
} catch (IOException e) {
// Ignore any exceptions.
}
}
@Override
public void stopNetLog() {
}
}
......@@ -59,6 +59,20 @@ public abstract class HttpUrlRequestFactory {
int requestPriority, Map<String, String> headers,
WritableByteChannel channel, HttpUrlRequestListener listener);
/**
* Starts NetLog logging to a file named |fileName| in the
* application temporary directory. |fileName| must not be empty. Log may
* contain user's personal information (PII). If the file exists it is
* truncated before starting. If actively logging the call is ignored.
*/
public abstract void startNetLogToFile(String fileName);
/**
* Stops NetLog logging and flushes file to disk. If a logging session is
* not in progress this call is ignored.
*/
public abstract void stopNetLog();
private static HttpUrlRequestFactory createChromiumFactory(
Context context, HttpUrlRequestFactoryConfig config) {
HttpUrlRequestFactory factory = null;
......
......@@ -84,11 +84,10 @@ public class CronetUrlTest extends CronetTestBase {
waitForActiveShellToBeDoneLoading();
File file = File.createTempFile("cronet", "json");
activity.mChromiumRequestFactory.getRequestContext().startNetLogToFile(
file.getPath());
activity.mRequestFactory.startNetLogToFile(file.getPath());
activity.startWithURL(URL);
Thread.sleep(5000);
activity.mChromiumRequestFactory.getRequestContext().stopNetLog();
activity.mRequestFactory.stopNetLog();
assertTrue(file.exists());
assertTrue(file.length() != 0);
assertTrue(file.delete());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment