Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef NET_PROXY_PROXY_CONFIG_SERVICE_ANDROID_H_ | |
| 6 #define NET_PROXY_PROXY_CONFIG_SERVICE_ANDROID_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/android/jni_android.h" | |
| 12 #include "base/basictypes.h" | |
| 13 #include "base/callback_forward.h" | |
| 14 #include "base/compiler_specific.h" | |
| 15 #include "base/memory/ref_counted.h" | |
| 16 #include "net/base/net_export.h" | |
| 17 #include "net/proxy/proxy_config_service.h" | |
| 18 | |
| 19 namespace base { | |
| 20 class SingleThreadTaskRunner; | |
| 21 } | |
| 22 | |
| 23 namespace net { | |
| 24 | |
| 25 class ProxyConfig; | |
| 26 | |
| 27 class NET_EXPORT ProxyConfigServiceAndroid : public ProxyConfigService { | |
| 28 public: | |
| 29 class Delegate; | |
| 30 | |
| 31 // Callback that returns the value of the property identified by the provided | |
| 32 // key. If it was not found, an empty string is returned. Note that this | |
| 33 // interface does not let you distinguish an empty property from a | |
| 34 // non-existing property. This callback is invoked on the JNI thread. | |
| 35 typedef base::Callback<std::string (const std::string& property)> | |
| 36 GetPropertyCallback; | |
| 37 | |
| 38 ProxyConfigServiceAndroid(base::SingleThreadTaskRunner* network_task_runner, | |
| 39 base::SingleThreadTaskRunner* jni_task_runner); | |
| 40 | |
| 41 virtual ~ProxyConfigServiceAndroid(); | |
| 42 | |
| 43 // Register JNI bindings. | |
| 44 static bool Register(JNIEnv* env); | |
| 45 | |
| 46 // ProxyConfigService: | |
| 47 // Called only on the network thread. | |
| 48 virtual void AddObserver(Observer* observer) OVERRIDE; | |
| 49 virtual void RemoveObserver(Observer* observer) OVERRIDE; | |
| 50 virtual ConfigAvailability GetLatestProxyConfig(ProxyConfig* config) OVERRIDE; | |
| 51 | |
| 52 // Separate class whose instance is owned by the Delegate class implemented in | |
| 53 // the header. That lets us decouple ProxySettingsChanged() from | |
| 54 // ProxyConfigServiceAndroid lifecycle without exposing the Delegate here in | |
| 55 // the header. | |
| 56 class JNICallback { | |
|
Ryan Sleevi
2012/06/01 18:10:58
nit: Rather than explain this from the perspective
Philippe
2012/06/04 10:02:37
Done. Good point. I made the implementation class
| |
| 57 public: | |
| 58 JNICallback(Delegate* delegate) : delegate_(delegate) {} | |
| 59 | |
| 60 // Called from Java (on JNI thread) to signal that the proxy settings have | |
| 61 // changed. | |
| 62 void ProxySettingsChanged(JNIEnv*, jobject); | |
| 63 | |
| 64 private: | |
| 65 Delegate* const delegate_; | |
| 66 }; | |
| 67 | |
| 68 private: | |
| 69 friend class ProxyConfigServiceAndroidTestBase; | |
| 70 | |
| 71 // For tests. | |
| 72 ProxyConfigServiceAndroid(base::SingleThreadTaskRunner* network_task_runner, | |
| 73 base::SingleThreadTaskRunner* jni_task_runner, | |
| 74 GetPropertyCallback get_property_callback); | |
| 75 | |
| 76 // For tests. | |
| 77 void ProxySettingsChanged(); | |
| 78 | |
| 79 scoped_refptr<Delegate> delegate_; | |
| 80 | |
| 81 DISALLOW_COPY_AND_ASSIGN(ProxyConfigServiceAndroid); | |
| 82 }; | |
| 83 | |
| 84 } // namespace net | |
| 85 | |
| 86 #endif // NET_PROXY_PROXY_CONFIG_SERVICE_ANDROID_H_ | |
| OLD | NEW |