Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(430)

Side by Side Diff: components/cronet/android/test/experimental_options_test.cc

Issue 2954753002: Add Cronet experimental option for host cache persistence (Closed)
Patch Set: address comments Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 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.
4
5 #include "components/cronet/android/test/experimental_options_test.h"
6
7 #include <jni.h>
8
9 #include "base/android/jni_android.h"
10 #include "base/android/jni_string.h"
11 #include "base/android/scoped_java_ref.h"
12 #include "base/time/time.h"
13 #include "components/cronet/android/test/cronet_test_util.h"
14 #include "jni/ExperimentalOptionsTest_jni.h"
15 #include "net/base/address_family.h"
16 #include "net/base/net_errors.h"
17 #include "net/dns/host_cache.h"
18 #include "net/dns/host_resolver.h"
19 #include "net/url_request/url_request_context.h"
20
21 using base::android::JavaParamRef;
22
23 namespace cronet {
24
25 namespace {
26 void WriteToHostCacheOnNetworkThread(jlong jcontext_adapter,
27 const std::string& address_string) {
28 net::URLRequestContext* context =
29 TestUtil::GetURLRequestContext(jcontext_adapter);
30 net::HostCache* cache = context->host_resolver()->GetHostCache();
31 net::HostCache::Key key("host-cache-test-host",
32 net::ADDRESS_FAMILY_UNSPECIFIED, 0);
33 net::IPAddress address;
34 CHECK(address.AssignFromIPLiteral(address_string));
35 net::AddressList address_list =
36 net::AddressList::CreateFromIPAddress(address, 0);
37 net::HostCache::Entry entry(net::OK, address_list);
38 cache->Set(key, entry, base::TimeTicks::Now(),
39 base::TimeDelta::FromSeconds(1));
40 }
41 } // namespace
42
43 static void WriteToHostCache(JNIEnv* env,
44 const JavaParamRef<jclass>& jcaller,
45 jlong jcontext_adapter,
46 const JavaParamRef<jstring>& jaddress) {
47 TestUtil::RunAfterContextInit(
48 jcontext_adapter,
49 base::Bind(&WriteToHostCacheOnNetworkThread, jcontext_adapter,
50 base::android::ConvertJavaStringToUTF8(env, jaddress)));
51 }
52
53 bool RegisterExperimentalOptionsTest(JNIEnv* env) {
54 return RegisterNativesImpl(env);
55 }
56
57 } // namespace cronet
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698