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

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: Add proxy_test_cases.py Created 8 years, 8 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
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..d8259fa85e85b8e80440559c4aa3793cdb933518
--- /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 "base/android/scoped_java_ref.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/memory/ref_counted.h"
Ryan Sleevi 2012/04/24 18:20:04 nit: Make sure the headers are sorted
Philippe 2012/05/09 11:48:39 Done.
+#include "base/observer_list.h"
+#include "base/string_piece.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"
+
+#include <string>
Ryan Sleevi 2012/04/24 18:20:04 nit: C++ system headers should appear before any C
Philippe 2012/05/09 11:48:39 Done.
+
+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;
+ };
+
+ ProxyConfigServiceAndroid(); // Default
+ ProxyConfigServiceAndroid(Delegate* delegate); // For tests; takes ownership.
Ryan Sleevi 2012/04/24 18:20:04 nit: explicit ProxyConfigServiceAndroid(Delegate*
Philippe 2012/05/09 11:48:39 Done.
+ virtual ~ProxyConfigServiceAndroid();
+
+ // Register JNI bindings.
+ static bool Init(JNIEnv* env);
+
+ // ProxyConfigService:
+ virtual void AddObserver(Observer* observer) OVERRIDE;
+ virtual void RemoveObserver(Observer* observer) OVERRIDE;
+ virtual ConfigAvailability GetLatestProxyConfig(ProxyConfig* config) OVERRIDE;
+
+ // Called from the platform on any thread to signal that proxy settings have
+ // changed. AddObserver() must have been called at least once before.
Ryan Sleevi 2012/04/24 18:20:04 I must admit, I'm not sure your threading guarante
Philippe 2012/05/09 11:48:39 This method is actually called from the Java side
+ void ProxySettingsChanged();
+
+ // Called from Java to signal that the proxy settings have changed.
+ void ProxySettingsChanged(JNIEnv*, jobject) { ProxySettingsChanged(); }
+
+ private:
+ class NotifyTask;
+
+ void ProxySettingsChangedCallback();
+ void CancelNotifyTask();
+ void ClearNotifyTask();
+ bool OnObserverThread();
+ void AssignObserverThread();
+
+ // Accessed by the constructor, and from then on from the Observer thread.
+ scoped_ptr<Delegate> delegate_;
+ ObserverList<Observer> observers_;
+
+
Ryan Sleevi 2012/04/24 18:20:04 nit: Delete extra line
Philippe 2012/05/09 11:48:39 Done.
+ base::Lock notify_task_lock_;
+ NotifyTask* notify_task_; // Accessed from any thread, guarded by lock_.
Ryan Sleevi 2012/04/24 18:20:04 Using Locks, particularly for threading, is genera
Philippe 2012/05/09 11:48:39 NotifyTask was mainly used to handle the case wher
+
+ // The thread that this object lives on; set on first call to AddObserver().
+ // Notifications from the platform (ProxySettingsChanged) will be bounced
+ // over to this thread before calling back to the Observer. All other
+ // methods should be called on this thread.
Ryan Sleevi 2012/04/24 18:20:04 This behaviour strikes me as a little surprising,
Philippe 2012/05/09 11:48:39 The message loop proxy is now injected through the
+ scoped_refptr<base::MessageLoopProxy> observer_loop_;
+};
+
+} // namespace net
+
+#endif // NET_PROXY_PROXY_CONFIG_SERVICE_ANDROID_H_

Powered by Google App Engine
This is Rietveld 408576698