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" |
(...skipping 23 matching lines...) Expand all Loading... |
34 : target_url_(target_url), manager_(manager) { | 34 : target_url_(target_url), manager_(manager) { |
35 jsdch_observer_ref_.Reset(jsdch_observer_ref); | 35 jsdch_observer_ref_.Reset(jsdch_observer_ref); |
36 } | 36 } |
37 | 37 |
38 // SdchObserver implementation | 38 // SdchObserver implementation |
39 void OnDictionaryAdded(const GURL& dictionary_url, | 39 void OnDictionaryAdded(const GURL& dictionary_url, |
40 const std::string& server_hash) override { | 40 const std::string& server_hash) override { |
41 // Only notify if the dictionary for the |target_url_| has been added. | 41 // Only notify if the dictionary for the |target_url_| has been added. |
42 if (manager_->GetDictionarySet(target_url_)) { | 42 if (manager_->GetDictionarySet(target_url_)) { |
43 JNIEnv* env = base::android::AttachCurrentThread(); | 43 JNIEnv* env = base::android::AttachCurrentThread(); |
44 Java_SdchObserver_onDictionaryAdded(env, jsdch_observer_ref_.obj()); | 44 Java_SdchObserver_onDictionaryAdded(env, jsdch_observer_ref_); |
45 manager_->RemoveObserver(this); | 45 manager_->RemoveObserver(this); |
46 delete this; | 46 delete this; |
47 } | 47 } |
48 } | 48 } |
49 | 49 |
50 void OnDictionaryRemoved(const std::string& server_hash) override {} | 50 void OnDictionaryRemoved(const std::string& server_hash) override {} |
51 | 51 |
52 void OnDictionaryUsed(const std::string& server_hash) override {} | 52 void OnDictionaryUsed(const std::string& server_hash) override {} |
53 | 53 |
54 void OnGetDictionary(const GURL& request_url, | 54 void OnGetDictionary(const GURL& request_url, |
(...skipping 10 matching lines...) Expand all Loading... |
65 }; | 65 }; |
66 | 66 |
67 void AddSdchObserverHelper( | 67 void AddSdchObserverHelper( |
68 const GURL& target_url, | 68 const GURL& target_url, |
69 const base::android::ScopedJavaGlobalRef<jobject>& jsdch_observer_ref, | 69 const base::android::ScopedJavaGlobalRef<jobject>& jsdch_observer_ref, |
70 net::URLRequestContext* url_request_context) { | 70 net::URLRequestContext* url_request_context) { |
71 JNIEnv* env = base::android::AttachCurrentThread(); | 71 JNIEnv* env = base::android::AttachCurrentThread(); |
72 // If dictionaries for |target_url| are already added, skip adding the | 72 // If dictionaries for |target_url| are already added, skip adding the |
73 // observer. | 73 // observer. |
74 if (url_request_context->sdch_manager()->GetDictionarySet(target_url)) { | 74 if (url_request_context->sdch_manager()->GetDictionarySet(target_url)) { |
75 Java_SdchObserver_onDictionarySetAlreadyPresent(env, | 75 Java_SdchObserver_onDictionarySetAlreadyPresent(env, jsdch_observer_ref); |
76 jsdch_observer_ref.obj()); | |
77 return; | 76 return; |
78 } | 77 } |
79 | 78 |
80 url_request_context->sdch_manager()->AddObserver(new TestSdchObserver( | 79 url_request_context->sdch_manager()->AddObserver(new TestSdchObserver( |
81 target_url, url_request_context->sdch_manager(), jsdch_observer_ref)); | 80 target_url, url_request_context->sdch_manager(), jsdch_observer_ref)); |
82 Java_SdchObserver_onAddSdchObserverCompleted(env, jsdch_observer_ref.obj()); | 81 Java_SdchObserver_onAddSdchObserverCompleted(env, jsdch_observer_ref); |
83 } | 82 } |
84 | 83 |
85 void AddSdchObserverOnNetworkThread( | 84 void AddSdchObserverOnNetworkThread( |
86 const GURL& target_url, | 85 const GURL& target_url, |
87 const base::android::ScopedJavaGlobalRef<jobject>& jsdch_observer_ref, | 86 const base::android::ScopedJavaGlobalRef<jobject>& jsdch_observer_ref, |
88 CronetURLRequestContextAdapter* context_adapter) { | 87 CronetURLRequestContextAdapter* context_adapter) { |
89 AddSdchObserverHelper(target_url, jsdch_observer_ref, | 88 AddSdchObserverHelper(target_url, jsdch_observer_ref, |
90 context_adapter->GetURLRequestContext()); | 89 context_adapter->GetURLRequestContext()); |
91 } | 90 } |
92 | 91 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 FROM_HERE, | 135 FROM_HERE, |
137 base::Bind(&AddSdchObserverOnNetworkThreadLegacyAPI, target_url, | 136 base::Bind(&AddSdchObserverOnNetworkThreadLegacyAPI, target_url, |
138 jsdch_observer_ref, base::Unretained(context_adapter))); | 137 jsdch_observer_ref, base::Unretained(context_adapter))); |
139 } | 138 } |
140 | 139 |
141 bool RegisterSdchTestUtil(JNIEnv* env) { | 140 bool RegisterSdchTestUtil(JNIEnv* env) { |
142 return RegisterNativesImpl(env); | 141 return RegisterNativesImpl(env); |
143 } | 142 } |
144 | 143 |
145 } // namespace cronet | 144 } // namespace cronet |
OLD | NEW |