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

Side by Side Diff: chrome/browser/android/net/external_estimate_provider_android.cc

Issue 1348523003: Revert "Populate EEP estimate in NQE" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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
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 "chrome/browser/android/net/external_estimate_provider_android.h" 5 #include "chrome/browser/android/net/external_estimate_provider_android.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
(...skipping 15 matching lines...) Expand all
26 DCHECK(!j_external_estimate_provider_.is_null()); 26 DCHECK(!j_external_estimate_provider_.is_null());
27 no_value_ = Java_ExternalEstimateProviderAndroid_getNoValue(env); 27 no_value_ = Java_ExternalEstimateProviderAndroid_getNoValue(env);
28 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); 28 net::NetworkChangeNotifier::AddConnectionTypeObserver(this);
29 } 29 }
30 30
31 ExternalEstimateProviderAndroid::~ExternalEstimateProviderAndroid() { 31 ExternalEstimateProviderAndroid::~ExternalEstimateProviderAndroid() {
32 DCHECK(thread_checker_.CalledOnValidThread()); 32 DCHECK(thread_checker_.CalledOnValidThread());
33 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); 33 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this);
34 } 34 }
35 35
36 void ExternalEstimateProviderAndroid::RequestUpdate() const {
37 DCHECK(thread_checker_.CalledOnValidThread());
38 JNIEnv* env = base::android::AttachCurrentThread();
39 Java_ExternalEstimateProviderAndroid_requestUpdate(
40 env, j_external_estimate_provider_.obj());
41 }
42
36 bool ExternalEstimateProviderAndroid::GetRTT(base::TimeDelta* rtt) const { 43 bool ExternalEstimateProviderAndroid::GetRTT(base::TimeDelta* rtt) const {
37 DCHECK(thread_checker_.CalledOnValidThread()); 44 DCHECK(thread_checker_.CalledOnValidThread());
38 JNIEnv* env = base::android::AttachCurrentThread(); 45 JNIEnv* env = base::android::AttachCurrentThread();
39 int32_t milliseconds = 46 int32_t milliseconds =
40 Java_ExternalEstimateProviderAndroid_getRTTMilliseconds( 47 Java_ExternalEstimateProviderAndroid_getRTTMilliseconds(
41 env, j_external_estimate_provider_.obj()); 48 env, j_external_estimate_provider_.obj());
42 DCHECK(milliseconds >= no_value_); 49 DCHECK(milliseconds >= no_value_);
43 if (milliseconds == no_value_) 50 if (milliseconds == no_value_)
44 return false; 51 return false;
45 *rtt = base::TimeDelta::FromMilliseconds(milliseconds); 52 *rtt = base::TimeDelta::FromMilliseconds(milliseconds);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 env, j_external_estimate_provider_.obj()); 89 env, j_external_estimate_provider_.obj());
83 DCHECK(seconds >= no_value_); 90 DCHECK(seconds >= no_value_);
84 if (seconds == no_value_) { 91 if (seconds == no_value_) {
85 *time_since_last_update = base::TimeDelta::Max(); 92 *time_since_last_update = base::TimeDelta::Max();
86 return false; 93 return false;
87 } 94 }
88 *time_since_last_update = base::TimeDelta::FromMilliseconds(seconds); 95 *time_since_last_update = base::TimeDelta::FromMilliseconds(seconds);
89 return true; 96 return true;
90 } 97 }
91 98
92 void ExternalEstimateProviderAndroid::SetUpdatedEstimateDelegate(
93 net::ExternalEstimateProvider::UpdatedEstimateDelegate* delegate) {
94 delegate_ = delegate;
95 }
96
97 void ExternalEstimateProviderAndroid::Update() const {
98 DCHECK(thread_checker_.CalledOnValidThread());
99 JNIEnv* env = base::android::AttachCurrentThread();
100 Java_ExternalEstimateProviderAndroid_requestUpdate(
101 env, j_external_estimate_provider_.obj());
102 }
103
104 void ExternalEstimateProviderAndroid::OnConnectionTypeChanged(
105 net::NetworkChangeNotifier::ConnectionType type) {
106 Update();
107 }
108
109 void ExternalEstimateProviderAndroid:: 99 void ExternalEstimateProviderAndroid::
110 NotifyExternalEstimateProviderAndroidUpdate(JNIEnv* env, jobject obj) { 100 NotifyExternalEstimateProviderAndroidUpdate(JNIEnv* env, jobject obj) {
111 if (!task_runner_) 101 if (!task_runner_)
112 return; 102 return;
113 task_runner_->PostTask( 103 task_runner_->PostTask(
114 FROM_HERE, 104 FROM_HERE,
115 base::Bind( 105 base::Bind(
116 &ExternalEstimateProviderAndroid::NotifyUpdatedEstimateAvailable, 106 &ExternalEstimateProviderAndroid::NotifyUpdatedEstimateAvailable,
117 weak_factory_.GetWeakPtr())); 107 weak_factory_.GetWeakPtr()));
118 } 108 }
119 109
120 void ExternalEstimateProviderAndroid::NotifyUpdatedEstimateAvailable() const { 110 void ExternalEstimateProviderAndroid::NotifyUpdatedEstimateAvailable() const {
121 DCHECK(thread_checker_.CalledOnValidThread()); 111 DCHECK(thread_checker_.CalledOnValidThread());
122 if (delegate_) 112 if (delegate_)
123 delegate_->OnUpdatedEstimateAvailable(); 113 delegate_->OnUpdatedEstimateAvailable();
124 } 114 }
125 115
116 void ExternalEstimateProviderAndroid::OnConnectionTypeChanged(
117 net::NetworkChangeNotifier::ConnectionType type) {
118 RequestUpdate();
119 }
120
126 bool RegisterExternalEstimateProviderAndroid(JNIEnv* env) { 121 bool RegisterExternalEstimateProviderAndroid(JNIEnv* env) {
127 return RegisterNativesImpl(env); 122 return RegisterNativesImpl(env);
128 } 123 }
129 124
125 void ExternalEstimateProviderAndroid::SetUpdatedEstimateDelegate(
126 net::ExternalEstimateProvider::UpdatedEstimateDelegate* delegate) {
127 delegate_ = delegate;
128 }
129
130 } // namespace android 130 } // namespace android
131 } // namespace chrome 131 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698