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..c225c8fada1d150e1a3a38e5a95f0a052a639a14 |
| --- /dev/null |
| +++ b/net/proxy/proxy_config_service_android.h |
| @@ -0,0 +1,95 @@ |
| +// 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/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: |
| + // Delegate abstracts access to the platform. |
| + // Owned by ProxyConfigServiceAndroid. |
| + class Delegate { |
| + public: |
| + virtual ~Delegate() {} |
| + |
| + // Notifies the platform that the proxy config service started. The caller |
| + // keeps ownership of |service|. |
| + virtual void Start(ProxyConfigServiceAndroid* service) = 0; |
| + virtual void Stop() = 0; |
| + |
| + // 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. |
| + virtual std::string GetProperty(const std::string& property) = 0; |
| + }; |
| + |
| + ProxyConfigServiceAndroid(base::SingleThreadTaskRunner* observer_runner); |
|
Ryan Sleevi
2012/05/19 01:26:31
explicit
Philippe
2012/05/22 15:23:05
Done. The constructor now takes two parameters.
|
| + virtual ~ProxyConfigServiceAndroid(); |
| + |
| + // Register JNI bindings. |
| + static bool Register(JNIEnv* env); |
| + |
| + // ProxyConfigService: |
| + // Observer-related operations must be called on the observer thread. |
| + virtual void AddObserver(Observer* observer) OVERRIDE; |
| + virtual void RemoveObserver(Observer* observer) OVERRIDE; |
| + |
|
Ryan Sleevi
2012/05/19 01:26:31
Delete this blank line, per http://www.chromium.or
Philippe
2012/05/22 15:23:05
Done.
|
| + virtual ConfigAvailability GetLatestProxyConfig(ProxyConfig* config) OVERRIDE; |
| + |
| + void ProxySettingsChangedInternal(); |
| + |
| + // Called from Java to signal that the proxy settings have changed. |
| + void ProxySettingsChanged(JNIEnv*, jobject) { |
| + ProxySettingsChangedInternal(); |
| + } |
| + |
| + private: |
| + friend class ProxyConfigServiceAndroidTest; |
| + |
| + // For tests; takes ownership of |delegate|. |
| + ProxyConfigServiceAndroid(base::SingleThreadTaskRunner* observer_runner, |
| + Delegate* delegate); |
| + |
| + // Structure holding the state used by both this class and the asynchronous |
| + // callback running on the observer thread. Instances of SharedState are |
| + // referenced through a shared pointer so that we handle the case where |
| + // ProxyConfigServiceAndroid gets deleted before the asynchronous callback |
| + // (using this state) runs. |
| + struct SharedState; |
|
Ryan Sleevi
2012/05/19 01:26:31
nit: Not always consistently, but there was a big
Philippe
2012/05/22 15:23:05
Thanks for the information.
|
| + |
| + // Called on observer thread. |
| + static void ProxySettingsChangedCallback( |
| + const scoped_refptr<SharedState>& callback_state); |
| + bool OnObserverThread() const; |
| + |
| + scoped_refptr<SharedState> shared_state_; |
| + |
| + // Task runner of the thread on which observers are notified whenever proxy |
| + // settings change. |
| + scoped_refptr<base::SingleThreadTaskRunner> observer_runner_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ProxyConfigServiceAndroid); |
| +}; |
| + |
| +} // namespace net |
| + |
| +#endif // NET_PROXY_PROXY_CONFIG_SERVICE_ANDROID_H_ |