Delete unused downloads page asset.
[chromium-blink-merge.git] / net / test / embedded_test_server / android / embedded_test_server_android.cc
blob7cca9d933fcc86495da844b07b509f8d85bbbbcb
1 // Copyright 2015 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.
5 #include "net/test/embedded_test_server/android/embedded_test_server_android.h"
7 #include "base/android/jni_string.h"
8 #include "base/android/scoped_java_ref.h"
9 #include "base/bind.h"
10 #include "base/files/file_path.h"
11 #include "base/trace_event/trace_event.h"
12 #include "net/test/jni/EmbeddedTestServer_jni.h"
14 namespace net {
15 namespace test_server {
17 EmbeddedTestServerAndroid::EmbeddedTestServerAndroid(JNIEnv* env, jobject jobj)
18 : weak_java_server_(env, jobj), test_server_() {
19 Java_EmbeddedTestServer_setNativePtr(env, jobj,
20 reinterpret_cast<intptr_t>(this));
23 EmbeddedTestServerAndroid::~EmbeddedTestServerAndroid() {
24 JNIEnv* env = base::android::AttachCurrentThread();
25 Java_EmbeddedTestServer_clearNativePtr(env, weak_java_server_.get(env).obj());
28 jboolean EmbeddedTestServerAndroid::InitializeAndWaitUntilReady(JNIEnv* env,
29 jobject jobj) {
30 return test_server_.InitializeAndWaitUntilReady();
33 jboolean EmbeddedTestServerAndroid::ShutdownAndWaitUntilComplete(JNIEnv* env,
34 jobject jobj) {
35 return test_server_.ShutdownAndWaitUntilComplete();
38 base::android::ScopedJavaLocalRef<jstring> EmbeddedTestServerAndroid::GetURL(
39 JNIEnv* env,
40 jobject jobj,
41 jstring jrelative_url) const {
42 const GURL gurl(test_server_.GetURL(
43 base::android::ConvertJavaStringToUTF8(env, jrelative_url)));
44 return base::android::ConvertUTF8ToJavaString(env, gurl.spec());
47 void EmbeddedTestServerAndroid::ServeFilesFromDirectory(
48 JNIEnv* env,
49 jobject jobj,
50 jstring jdirectory_path) {
51 const base::FilePath directory(
52 base::android::ConvertJavaStringToUTF8(env, jdirectory_path));
53 test_server_.ServeFilesFromDirectory(directory);
56 void EmbeddedTestServerAndroid::Destroy(JNIEnv* env, jobject jobj) {
57 delete this;
60 static void Init(JNIEnv* env, jobject jobj) {
61 TRACE_EVENT0("native", "EmbeddedTestServerAndroid::Init");
62 new EmbeddedTestServerAndroid(env, jobj);
65 // static
66 bool EmbeddedTestServerAndroid::RegisterEmbeddedTestServerAndroid(JNIEnv* env) {
67 return RegisterNativesImpl(env);
70 } // namespace test_server
71 } // namespace net