Chromium Code Reviews| Index: net/proxy/proxy_config_service_android.h |
| diff --git a/net/proxy/proxy_config_service_android.h b/net/proxy/proxy_config_service_android.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..250e0dda2086ce2f81a948dac02c6ce993498118 |
| --- /dev/null |
| +++ b/net/proxy/proxy_config_service_android.h |
| @@ -0,0 +1,86 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef NET_PROXY_PROXY_CONFIG_SERVICE_ANDROID_H_ |
| +#define NET_PROXY_PROXY_CONFIG_SERVICE_ANDROID_H_ |
| +#pragma once |
| + |
| +#include <string> |
| + |
| +#include "base/android/jni_android.h" |
| +#include "base/basictypes.h" |
| +#include "base/callback_forward.h" |
| +#include "base/compiler_specific.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "net/base/net_export.h" |
| +#include "net/proxy/proxy_config_service.h" |
| + |
| +namespace base { |
| +class SingleThreadTaskRunner; |
| +} |
| + |
| +namespace net { |
| + |
| +class ProxyConfig; |
| + |
| +class NET_EXPORT ProxyConfigServiceAndroid : public ProxyConfigService { |
| + public: |
| + class Delegate; |
| + |
| + // Callback that returns the value of the property identified by the provided |
| + // key. If it was not found, an empty string is returned. Note that this |
| + // interface does not let you distinguish an empty property from a |
| + // non-existing property. This callback is invoked on the JNI thread. |
| + typedef base::Callback<std::string (const std::string& property)> |
| + GetPropertyCallback; |
| + |
| + ProxyConfigServiceAndroid(base::SingleThreadTaskRunner* network_task_runner, |
| + base::SingleThreadTaskRunner* jni_task_runner); |
| + |
| + virtual ~ProxyConfigServiceAndroid(); |
| + |
| + // Register JNI bindings. |
| + static bool Register(JNIEnv* env); |
| + |
| + // ProxyConfigService: |
| + // Called only on the network thread. |
| + virtual void AddObserver(Observer* observer) OVERRIDE; |
| + virtual void RemoveObserver(Observer* observer) OVERRIDE; |
| + virtual ConfigAvailability GetLatestProxyConfig(ProxyConfig* config) OVERRIDE; |
| + |
| + // Separate class whose instance is owned by the Delegate class implemented in |
| + // the header. That lets us decouple ProxySettingsChanged() from |
| + // ProxyConfigServiceAndroid lifecycle without exposing the Delegate here in |
| + // the header. |
| + 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
|
| + public: |
| + JNICallback(Delegate* delegate) : delegate_(delegate) {} |
| + |
| + // Called from Java (on JNI thread) to signal that the proxy settings have |
| + // changed. |
| + void ProxySettingsChanged(JNIEnv*, jobject); |
| + |
| + private: |
| + Delegate* const delegate_; |
| + }; |
| + |
| + private: |
| + friend class ProxyConfigServiceAndroidTestBase; |
| + |
| + // For tests. |
| + ProxyConfigServiceAndroid(base::SingleThreadTaskRunner* network_task_runner, |
| + base::SingleThreadTaskRunner* jni_task_runner, |
| + GetPropertyCallback get_property_callback); |
| + |
| + // For tests. |
| + void ProxySettingsChanged(); |
| + |
| + scoped_refptr<Delegate> delegate_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ProxyConfigServiceAndroid); |
| +}; |
| + |
| +} // namespace net |
| + |
| +#endif // NET_PROXY_PROXY_CONFIG_SERVICE_ANDROID_H_ |