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

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
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/scoped_java_ref.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/observer_list.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 MessageLoopProxy;
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 {
30 public:
31 virtual ~Delegate() {}
32 virtual void Start(ProxyConfigServiceAndroid* service) = 0;
33 virtual void Stop() = 0;
34 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
35 };
36
37 ProxyConfigServiceAndroid(
38 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
39 virtual ~ProxyConfigServiceAndroid();
40
41 // Register JNI bindings.
42 static bool Init(JNIEnv* env);
43
44 // ProxyConfigService:
45 // Observer-related operations must be called on the observer thread.
46 virtual void AddObserver(Observer* observer) OVERRIDE;
47 virtual void RemoveObserver(Observer* observer) OVERRIDE;
48
49 virtual ConfigAvailability GetLatestProxyConfig(ProxyConfig* config) OVERRIDE;
50
51 void ProxySettingsChanged();
52
53 // Called from Java to signal that the proxy settings have changed.
54 void ProxySettingsChanged(JNIEnv*, jobject) { ProxySettingsChanged(); }
55
56 private:
57 friend class ProxyConfigServiceAndroidTest;
58
59 // For tests; takes ownership of |delegate|.
60 ProxyConfigServiceAndroid(scoped_refptr<base::MessageLoopProxy> observer_loop,
61 Delegate* delegate);
62
63 // Structure holding the state used by both this class and the asynchronous
64 // callback running on the observer thread. Instances of SharedState are
65 // referenced through a shared pointer so that we handle the case where
66 // ProxyConfigServiceAndroid gets deleted before the asynchronous callback
67 // (using this state) runs.
68 struct SharedState;
69
70 // Called on observer thread.
71 static void ProxySettingsChangedCallback(
72 scoped_refptr<SharedState> callback_state);
73 bool OnObserverThread() const;
74
75 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
76
77 // Message loop of the thread on which observers are notified whenever proxy
78 // settings change.
79 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.
80 };
81
82 } // namespace net
83
84 #endif // NET_PROXY_PROXY_CONFIG_SERVICE_ANDROID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698