blob: 3ddbaebe78e9ead4b3e73567bbb7a74c784f587e [file] [log] [blame]
// 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.
#include <string>
#include "base/android/jni_android.h"
#include "base/basictypes.h"
#include "base/callback_forward.h"
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "net/base/net_export.h"
#include "net/proxy/proxy_config_service.h"
namespace base {
class SequencedTaskRunner;
namespace net {
class ProxyConfig;
class NET_EXPORT ProxyConfigServiceAndroid : public ProxyConfigService {
// Callback that 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. This callback is invoked on the JNI thread.
typedef base::Callback<std::string (const std::string& property)>
// Separate class whose instance is owned by the Delegate class implemented in
// the .cc file.
class JNIDelegate {
virtual ~JNIDelegate() {}
// Called from Java (on JNI thread) to signal that the proxy settings have
// changed.
virtual void ProxySettingsChanged(JNIEnv*, jobject) = 0;
ProxyConfigServiceAndroid(base::SequencedTaskRunner* network_task_runner,
base::SequencedTaskRunner* jni_task_runner);
virtual ~ProxyConfigServiceAndroid();
// Register JNI bindings.
static bool Register(JNIEnv* env);
// ProxyConfigService:
// Called only on the network thread.
virtual void AddObserver(Observer* observer) OVERRIDE;
virtual void RemoveObserver(Observer* observer) OVERRIDE;
virtual ConfigAvailability GetLatestProxyConfig(ProxyConfig* config) OVERRIDE;
friend class ProxyConfigServiceAndroidTestBase;
class Delegate;
// For tests.
ProxyConfigServiceAndroid(base::SequencedTaskRunner* network_task_runner,
base::SequencedTaskRunner* jni_task_runner,
GetPropertyCallback get_property_callback);
// For tests.
void ProxySettingsChanged();
scoped_refptr<Delegate> delegate_;
} // namespace net