Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(239)

Unified Diff: net/proxy/proxy_config_service_android.h

Issue 10206014: Upstream Android proxy config service. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address Ryan's comments Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/net.gyp ('k') | net/proxy/proxy_config_service_android.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..b7e351d151ffe24c75c1c4481fbb6a9284230fe4
--- /dev/null
+++ b/net/proxy/proxy_config_service_android.h
@@ -0,0 +1,109 @@
+// 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 "base/synchronization/lock.h"
+#include "net/base/net_export.h"
+#include "net/proxy/proxy_config.h"
+#include "net/proxy/proxy_config_service.h"
+
+namespace base {
+class SingleThreadTaskRunner;
+}
+
+namespace net {
+
+class NET_EXPORT ProxyConfigServiceAndroid : public ProxyConfigService {
+ public:
+ // Delegate abstracts access to the platform.
+ // Owned by ProxyConfigServiceAndroid.
+ class Delegate : public base::RefCountedThreadSafe<Delegate> {
+ public:
+ // 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;
+
+ protected:
+ friend class base::RefCountedThreadSafe<Delegate>;
+ virtual ~Delegate() {}
+ };
+
+ ProxyConfigServiceAndroid(base::SingleThreadTaskRunner* network_task_runner,
+ base::SingleThreadTaskRunner* jni_task_runner);
+
+ virtual ~ProxyConfigServiceAndroid();
+
+ // Register JNI bindings.
+ static bool Register(JNIEnv* env);
+
+ // ProxyConfigService:
+ // Observer-related operations must be called on the network thread.
+ virtual void AddObserver(Observer* observer) OVERRIDE;
+ virtual void RemoveObserver(Observer* observer) OVERRIDE;
+ 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;
+
+ // ObserverList does not subclass RefCountedThreadSafe therefore we have to
+ // wrap it into a class. WeakPtr can't be used unfortunately since it
+ // can't be constructed on a thread and later be dereferenced on another one
+ // (see weak_ptr.h for details).
+ class SharedObserverList;
+
+ // For tests; takes ownership of |delegate|.
+ ProxyConfigServiceAndroid(base::SingleThreadTaskRunner* network_task_runner,
+ base::SingleThreadTaskRunner* jni_task_runner,
+ Delegate* delegate);
+
+ // Called on network thread.
+ static void ProxySettingsChangedCallback(
+ const scoped_refptr<SharedObserverList>& observers,
+ const ProxyConfig& proxy_config);
+
+ bool OnNetworkThread() const;
+
+ // Use shared pointers so that we handle the case where
+ // ProxyConfigServiceAndroid gets deleted before the asynchronous callbacks
+ // run.
+ scoped_refptr<Delegate> delegate_;
+ scoped_refptr<SharedObserverList> observers_;
Ryan Sleevi 2012/05/22 18:26:19 I don't believe you need to protect this by forcin
Philippe 2012/05/25 16:20:10 Done.
+
+ // Task runner of the thread on which observers are notified whenever proxy
+ // settings change.
+ scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;
+ // Task runner of the thread on which JNI calls are performed.
+ scoped_refptr<base::SingleThreadTaskRunner> jni_task_runner_;
+
+ base::Lock lock_; // Protects the state below.
Ryan Sleevi 2012/05/22 18:26:19 This isn't needed
Philippe 2012/05/25 16:20:10 Done.
+ ProxyConfig latest_proxy_config_;
+
+ DISALLOW_COPY_AND_ASSIGN(ProxyConfigServiceAndroid);
+};
+
+} // namespace net
+
+#endif // NET_PROXY_PROXY_CONFIG_SERVICE_ANDROID_H_
« no previous file with comments | « net/net.gyp ('k') | net/proxy/proxy_config_service_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698