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..54e9e0904a99e9f2f3509009f7b5c123d69b2315 |
| --- /dev/null |
| +++ b/net/proxy/proxy_config_service_android.h |
| @@ -0,0 +1,84 @@ |
| +// 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/scoped_java_ref.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/observer_list.h" |
| +#include "net/base/net_export.h" |
| +#include "net/proxy/proxy_config.h" |
| +#include "net/proxy/proxy_config_service.h" |
| + |
| +namespace base { |
| +class MessageLoopProxy; |
| +} |
| + |
| +namespace net { |
| + |
| +class NET_EXPORT ProxyConfigServiceAndroid : public ProxyConfigService { |
| + public: |
| + // Delegate abstracts access to the platform. |
| + // Owned by ProxyConfigServiceAndroid. |
| + class Delegate { |
| + public: |
| + virtual ~Delegate() {} |
| + virtual void Start(ProxyConfigServiceAndroid* service) = 0; |
| + virtual void Stop() = 0; |
| + virtual std::string GetProperty(const std::string& property) = 0; |
|
Ryan Sleevi
2012/05/07 17:12:20
nit: Document what these methods do.
For example,
Philippe
2012/05/09 11:48:40
Good points.
Currently, ProxyConfigServiceAndroid
|
| + }; |
| + |
| + ProxyConfigServiceAndroid( |
| + scoped_refptr<base::MessageLoopProxy> observer_loop); |
|
Ryan Sleevi
2012/05/07 17:12:20
Instead of using a MessageLoopProxy, I believe the
Philippe
2012/05/09 11:48:40
Thanks for the tip :) I used SingleThreadTaskRunne
Ryan Sleevi
2012/05/14 18:00:25
Just pass the naked pointer and store a scoped_ref
Philippe
2012/05/15 16:12:47
I see now. I guess that I was not used to having t
|
| + virtual ~ProxyConfigServiceAndroid(); |
| + |
| + // Register JNI bindings. |
| + static bool Init(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; |
| + |
| + virtual ConfigAvailability GetLatestProxyConfig(ProxyConfig* config) OVERRIDE; |
| + |
| + void ProxySettingsChanged(); |
| + |
| + // Called from Java to signal that the proxy settings have changed. |
| + void ProxySettingsChanged(JNIEnv*, jobject) { ProxySettingsChanged(); } |
| + |
| + private: |
| + friend class ProxyConfigServiceAndroidTest; |
| + |
| + // For tests; takes ownership of |delegate|. |
| + ProxyConfigServiceAndroid(scoped_refptr<base::MessageLoopProxy> observer_loop, |
| + 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; |
| + |
| + // Called on observer thread. |
| + static void ProxySettingsChangedCallback( |
| + scoped_refptr<SharedState> callback_state); |
| + bool OnObserverThread() const; |
| + |
| + const scoped_refptr<SharedState> shared_state_; |
|
Ryan Sleevi
2012/05/07 17:12:20
This means the scoped_refptr itself is const, but
Philippe
2012/05/09 11:48:40
It only prevents us from reassigning the pointer.
Ryan Sleevi
2012/05/14 18:00:25
But I mean, that's not really true. Once you const
Philippe
2012/05/15 16:12:47
I removed the const here and below since it might
|
| + |
| + // Message loop of the thread on which observers are notified whenever proxy |
| + // settings change. |
| + const scoped_refptr<base::MessageLoopProxy> observer_loop_; |
|
Ryan Sleevi
2012/05/07 17:12:20
Drop the const?
Philippe
2012/05/09 11:48:40
I would like to keep it for the same reason as abo
Ryan Sleevi
2012/05/14 18:00:25
I don't feel terribly strongly about this, but I s
Philippe
2012/05/15 16:12:47
Done.
|
| +}; |
| + |
| +} // namespace net |
| + |
| +#endif // NET_PROXY_PROXY_CONFIG_SERVICE_ANDROID_H_ |