| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "sdch_test_util.h" | 5 #include "sdch_test_util.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
| 11 #include "base/android/scoped_java_ref.h" | 11 #include "base/android/scoped_java_ref.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "components/cronet/android/cronet_url_request_context_adapter.h" | |
| 15 #include "jni/SdchObserver_jni.h" | 14 #include "jni/SdchObserver_jni.h" |
| 16 #include "net/base/sdch_manager.h" | 15 #include "net/base/sdch_manager.h" |
| 17 #include "net/base/sdch_observer.h" | 16 #include "net/base/sdch_observer.h" |
| 18 #include "net/url_request/url_request_context.h" | 17 #include "net/url_request/url_request_context.h" |
| 19 #include "url/gurl.h" | 18 #include "url/gurl.h" |
| 20 | 19 |
| 21 using base::android::JavaParamRef; | 20 using base::android::JavaParamRef; |
| 22 | 21 |
| 23 namespace cronet { | 22 namespace cronet { |
| 24 | 23 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 if (url_request_context->sdch_manager()->GetDictionarySet(target_url)) { | 72 if (url_request_context->sdch_manager()->GetDictionarySet(target_url)) { |
| 74 Java_SdchObserver_onDictionarySetAlreadyPresent(env, jsdch_observer_ref); | 73 Java_SdchObserver_onDictionarySetAlreadyPresent(env, jsdch_observer_ref); |
| 75 return; | 74 return; |
| 76 } | 75 } |
| 77 | 76 |
| 78 url_request_context->sdch_manager()->AddObserver(new TestSdchObserver( | 77 url_request_context->sdch_manager()->AddObserver(new TestSdchObserver( |
| 79 target_url, url_request_context->sdch_manager(), jsdch_observer_ref)); | 78 target_url, url_request_context->sdch_manager(), jsdch_observer_ref)); |
| 80 Java_SdchObserver_onAddSdchObserverCompleted(env, jsdch_observer_ref); | 79 Java_SdchObserver_onAddSdchObserverCompleted(env, jsdch_observer_ref); |
| 81 } | 80 } |
| 82 | 81 |
| 83 void AddSdchObserverOnNetworkThread( | |
| 84 const GURL& target_url, | |
| 85 const base::android::ScopedJavaGlobalRef<jobject>& jsdch_observer_ref, | |
| 86 CronetURLRequestContextAdapter* context_adapter) { | |
| 87 AddSdchObserverHelper(target_url, jsdch_observer_ref, | |
| 88 context_adapter->GetURLRequestContext()); | |
| 89 } | |
| 90 | |
| 91 } // namespace | 82 } // namespace |
| 92 | 83 |
| 93 void AddSdchObserver(JNIEnv* env, | 84 void AddSdchObserverOnNetworkThread(JNIEnv* env, |
| 94 const JavaParamRef<jobject>& jsdch_observer, | 85 const JavaParamRef<jobject>& jsdch_observer, |
| 95 const JavaParamRef<jstring>& jtarget_url, | 86 const JavaParamRef<jstring>& jtarget_url, |
| 96 jlong jadapter) { | 87 jlong jcontext) { |
| 97 base::android::ScopedJavaGlobalRef<jobject> jsdch_observer_ref; | 88 base::android::ScopedJavaGlobalRef<jobject> jsdch_observer_ref; |
| 98 // ScopedJavaGlobalRef do not hold onto the env reference, so it is safe to | 89 // ScopedJavaGlobalRef do not hold onto the env reference, so it is safe to |
| 99 // use it across threads. |AddSdchObserverHelper| will acquire a new | 90 // use it across threads. |AddSdchObserverHelper| will acquire a new |
| 100 // JNIEnv before calling into Java. | 91 // JNIEnv before calling into Java. |
| 101 jsdch_observer_ref.Reset(env, jsdch_observer); | 92 jsdch_observer_ref.Reset(env, jsdch_observer); |
| 102 | 93 |
| 103 GURL target_url(base::android::ConvertJavaStringToUTF8(env, jtarget_url)); | 94 GURL target_url(base::android::ConvertJavaStringToUTF8(env, jtarget_url)); |
| 104 CronetURLRequestContextAdapter* context_adapter = | 95 net::URLRequestContext* context = |
| 105 reinterpret_cast<CronetURLRequestContextAdapter*>(jadapter); | 96 reinterpret_cast<net::URLRequestContext*>(jcontext); |
| 106 context_adapter->PostTaskToNetworkThread( | 97 AddSdchObserverHelper(target_url, jsdch_observer_ref, context); |
| 107 FROM_HERE, | |
| 108 base::Bind(&AddSdchObserverOnNetworkThread, target_url, | |
| 109 jsdch_observer_ref, base::Unretained(context_adapter))); | |
| 110 } | 98 } |
| 111 | 99 |
| 112 bool RegisterSdchTestUtil(JNIEnv* env) { | 100 bool RegisterSdchTestUtil(JNIEnv* env) { |
| 113 return RegisterNativesImpl(env); | 101 return RegisterNativesImpl(env); |
| 114 } | 102 } |
| 115 | 103 |
| 116 } // namespace cronet | 104 } // namespace cronet |
| OLD | NEW |