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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/net.gyp ('k') | net/proxy/proxy_config_service_android.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef NET_PROXY_PROXY_CONFIG_SERVICE_ANDROID_H_
6 #define NET_PROXY_PROXY_CONFIG_SERVICE_ANDROID_H_
7 #pragma once
8
9 #include <string>
10
11 #include "base/android/jni_android.h"
12 #include "base/basictypes.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/synchronization/lock.h"
15 #include "net/base/net_export.h"
16 #include "net/proxy/proxy_config.h"
17 #include "net/proxy/proxy_config_service.h"
18
19 namespace base {
20 class SingleThreadTaskRunner;
21 }
22
23 namespace net {
24
25 class NET_EXPORT ProxyConfigServiceAndroid : public ProxyConfigService {
26 public:
27 // Delegate abstracts access to the platform.
28 // Owned by ProxyConfigServiceAndroid.
29 class Delegate : public base::RefCountedThreadSafe<Delegate> {
30 public:
31 // Notifies the platform that the proxy config service started. The caller
32 // keeps ownership of |service|.
33 virtual void Start(ProxyConfigServiceAndroid* service) = 0;
34 virtual void Stop() = 0;
35
36 // Returns the value of the property identified by the provided key. If it
37 // was not found, an empty string is returned. Note that this interface
38 // does not let you distinguish an empty property from a non-existing
39 // property.
40 virtual std::string GetProperty(const std::string& property) = 0;
41
42 protected:
43 friend class base::RefCountedThreadSafe<Delegate>;
44 virtual ~Delegate() {}
45 };
46
47 ProxyConfigServiceAndroid(base::SingleThreadTaskRunner* network_task_runner,
48 base::SingleThreadTaskRunner* jni_task_runner);
49
50 virtual ~ProxyConfigServiceAndroid();
51
52 // Register JNI bindings.
53 static bool Register(JNIEnv* env);
54
55 // ProxyConfigService:
56 // Observer-related operations must be called on the network thread.
57 virtual void AddObserver(Observer* observer) OVERRIDE;
58 virtual void RemoveObserver(Observer* observer) OVERRIDE;
59 virtual ConfigAvailability GetLatestProxyConfig(ProxyConfig* config) OVERRIDE;
60
61 void ProxySettingsChangedInternal();
62
63 // Called from Java to signal that the proxy settings have changed.
64 void ProxySettingsChanged(JNIEnv*, jobject) {
65 ProxySettingsChangedInternal();
66 }
67
68 private:
69 friend class ProxyConfigServiceAndroidTest;
70
71 // ObserverList does not subclass RefCountedThreadSafe therefore we have to
72 // wrap it into a class. WeakPtr can't be used unfortunately since it
73 // can't be constructed on a thread and later be dereferenced on another one
74 // (see weak_ptr.h for details).
75 class SharedObserverList;
76
77 // For tests; takes ownership of |delegate|.
78 ProxyConfigServiceAndroid(base::SingleThreadTaskRunner* network_task_runner,
79 base::SingleThreadTaskRunner* jni_task_runner,
80 Delegate* delegate);
81
82 // Called on network thread.
83 static void ProxySettingsChangedCallback(
84 const scoped_refptr<SharedObserverList>& observers,
85 const ProxyConfig& proxy_config);
86
87 bool OnNetworkThread() const;
88
89 // Use shared pointers so that we handle the case where
90 // ProxyConfigServiceAndroid gets deleted before the asynchronous callbacks
91 // run.
92 scoped_refptr<Delegate> delegate_;
93 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.
94
95 // Task runner of the thread on which observers are notified whenever proxy
96 // settings change.
97 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;
98 // Task runner of the thread on which JNI calls are performed.
99 scoped_refptr<base::SingleThreadTaskRunner> jni_task_runner_;
100
101 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.
102 ProxyConfig latest_proxy_config_;
103
104 DISALLOW_COPY_AND_ASSIGN(ProxyConfigServiceAndroid);
105 };
106
107 } // namespace net
108
109 #endif // NET_PROXY_PROXY_CONFIG_SERVICE_ANDROID_H_
OLDNEW
« 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