OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "net/proxy/proxy_config_service_android.h" | 5 #include "net/proxy/proxy_config_service_android.h" |
6 | 6 |
7 #include <sys/system_properties.h> | 7 #include <sys/system_properties.h> |
8 | 8 |
9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
152 // Use Java System.getProperty to get configuration information. | 152 // Use Java System.getProperty to get configuration information. |
153 // TODO(pliard): Conversion to/from UTF8 ok here? | 153 // TODO(pliard): Conversion to/from UTF8 ok here? |
154 JNIEnv* env = AttachCurrentThread(); | 154 JNIEnv* env = AttachCurrentThread(); |
155 ScopedJavaLocalRef<jstring> str = ConvertUTF8ToJavaString(env, property); | 155 ScopedJavaLocalRef<jstring> str = ConvertUTF8ToJavaString(env, property); |
156 ScopedJavaLocalRef<jstring> result = | 156 ScopedJavaLocalRef<jstring> result = |
157 Java_ProxyChangeListener_getProperty(env, str.obj()); | 157 Java_ProxyChangeListener_getProperty(env, str.obj()); |
158 return result.is_null() ? | 158 return result.is_null() ? |
159 std::string() : ConvertJavaStringToUTF8(env, result.obj()); | 159 std::string() : ConvertJavaStringToUTF8(env, result.obj()); |
160 } | 160 } |
161 | 161 |
162 void CreateStaticProxyConfig(const std::string& host, int port, | 162 void CreateStaticProxyConfig(const std::string& host, |
163 int port, | |
164 const std::string& exclusion_list, | |
163 ProxyConfig* config) { | 165 ProxyConfig* config) { |
164 if (port != 0) { | 166 if (port != 0) { |
165 std::string rules = base::StringPrintf("%s:%d", host.c_str(), port); | 167 std::string rules = base::StringPrintf("%s:%d", host.c_str(), port); |
166 config->proxy_rules().ParseFromString(rules); | 168 config->proxy_rules().ParseFromString(rules); |
169 config->proxy_rules().bypass_rules.Clear(); | |
170 if (!exclusion_list.empty()) { | |
eroman
2014/07/25 21:11:15
This block is essentially equivalent to:
config->
sgurun-gerrit only
2014/07/26 00:57:09
Thanks. Actually this made me realize that there a
| |
171 base::StringTokenizer tokenizer(exclusion_list, ","); | |
172 while (tokenizer.GetNext()) { | |
173 std::string token = tokenizer.token(); | |
174 std::string pattern; | |
175 base::TrimWhitespaceASCII(token, base::TRIM_ALL, &pattern); | |
176 if (pattern.empty()) | |
177 continue; | |
178 VLOG(0) << "Add bypass rules:" << pattern.c_str(); | |
179 config->proxy_rules().bypass_rules.AddRuleFromString(pattern); | |
180 } | |
181 } | |
167 } else { | 182 } else { |
168 *config = ProxyConfig::CreateDirect(); | 183 *config = ProxyConfig::CreateDirect(); |
169 } | 184 } |
170 } | 185 } |
171 | 186 |
172 } // namespace | 187 } // namespace |
173 | 188 |
174 class ProxyConfigServiceAndroid::Delegate | 189 class ProxyConfigServiceAndroid::Delegate |
175 : public base::RefCountedThreadSafe<Delegate> { | 190 : public base::RefCountedThreadSafe<Delegate> { |
176 public: | 191 public: |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
241 DCHECK(OnJNIThread()); | 256 DCHECK(OnJNIThread()); |
242 ProxyConfig proxy_config; | 257 ProxyConfig proxy_config; |
243 GetLatestProxyConfigInternal(get_property_callback_, &proxy_config); | 258 GetLatestProxyConfigInternal(get_property_callback_, &proxy_config); |
244 network_task_runner_->PostTask( | 259 network_task_runner_->PostTask( |
245 FROM_HERE, | 260 FROM_HERE, |
246 base::Bind( | 261 base::Bind( |
247 &Delegate::SetNewConfigOnNetworkThread, this, proxy_config)); | 262 &Delegate::SetNewConfigOnNetworkThread, this, proxy_config)); |
248 } | 263 } |
249 | 264 |
250 // Called on the JNI thread. | 265 // Called on the JNI thread. |
251 void ProxySettingsChangedTo(const std::string& host, int port) { | 266 void ProxySettingsChangedTo(const std::string& host, int port, |
267 const std::string& exclusion_list) { | |
252 DCHECK(OnJNIThread()); | 268 DCHECK(OnJNIThread()); |
253 ProxyConfig proxy_config; | 269 ProxyConfig proxy_config; |
254 CreateStaticProxyConfig(host, port, &proxy_config); | 270 CreateStaticProxyConfig(host, port, exclusion_list, &proxy_config); |
255 network_task_runner_->PostTask( | 271 network_task_runner_->PostTask( |
256 FROM_HERE, | 272 FROM_HERE, |
257 base::Bind( | 273 base::Bind( |
258 &Delegate::SetNewConfigOnNetworkThread, this, proxy_config)); | 274 &Delegate::SetNewConfigOnNetworkThread, this, proxy_config)); |
259 } | 275 } |
260 | 276 |
261 private: | 277 private: |
262 friend class base::RefCountedThreadSafe<Delegate>; | 278 friend class base::RefCountedThreadSafe<Delegate>; |
263 | 279 |
264 class JNIDelegateImpl : public ProxyConfigServiceAndroid::JNIDelegate { | 280 class JNIDelegateImpl : public ProxyConfigServiceAndroid::JNIDelegate { |
265 public: | 281 public: |
266 explicit JNIDelegateImpl(Delegate* delegate) : delegate_(delegate) {} | 282 explicit JNIDelegateImpl(Delegate* delegate) : delegate_(delegate) {} |
267 | 283 |
268 // ProxyConfigServiceAndroid::JNIDelegate overrides. | 284 // ProxyConfigServiceAndroid::JNIDelegate overrides. |
269 virtual void ProxySettingsChangedTo(JNIEnv* env, jobject jself, | 285 virtual void ProxySettingsChangedTo(JNIEnv* env, jobject jself, |
270 jstring jhost, jint jport) OVERRIDE { | 286 jstring jhost, jint jport, |
287 jstring jexclusion_list) OVERRIDE { | |
271 std::string host = ConvertJavaStringToUTF8(env, jhost); | 288 std::string host = ConvertJavaStringToUTF8(env, jhost); |
272 delegate_->ProxySettingsChangedTo(host, jport); | 289 std::string exclusion_list = |
290 ConvertJavaStringToUTF8(env, jexclusion_list); | |
291 delegate_->ProxySettingsChangedTo(host, jport, exclusion_list); | |
273 } | 292 } |
274 | 293 |
275 virtual void ProxySettingsChanged(JNIEnv* env, jobject self) OVERRIDE { | 294 virtual void ProxySettingsChanged(JNIEnv* env, jobject self) OVERRIDE { |
276 delegate_->ProxySettingsChanged(); | 295 delegate_->ProxySettingsChanged(); |
277 } | 296 } |
278 | 297 |
279 private: | 298 private: |
280 Delegate* const delegate_; | 299 Delegate* const delegate_; |
281 }; | 300 }; |
282 | 301 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
357 network_task_runner, jni_task_runner, get_property_callback)) { | 376 network_task_runner, jni_task_runner, get_property_callback)) { |
358 delegate_->SetupJNI(); | 377 delegate_->SetupJNI(); |
359 delegate_->FetchInitialConfig(); | 378 delegate_->FetchInitialConfig(); |
360 } | 379 } |
361 | 380 |
362 void ProxyConfigServiceAndroid::ProxySettingsChanged() { | 381 void ProxyConfigServiceAndroid::ProxySettingsChanged() { |
363 delegate_->ProxySettingsChanged(); | 382 delegate_->ProxySettingsChanged(); |
364 } | 383 } |
365 | 384 |
366 } // namespace net | 385 } // namespace net |
OLD | NEW |