diff options
author | derekjchow <derekjchow@chromium.org> | 2015-05-12 11:15:34 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-05-12 18:15:51 +0000 |
commit | 072a522258abaa50bfe7abdeb1b4bf66ad931c67 (patch) | |
tree | 75b7f5075834d29319a40dae622ba3688bfe6a49 /chromecast/net | |
parent | 9b3bd4f87a34c3fb33a63ee123d580485fbe067a (diff) | |
download | chromium_src-072a522258abaa50bfe7abdeb1b4bf66ad931c67.zip chromium_src-072a522258abaa50bfe7abdeb1b4bf66ad931c67.tar.gz chromium_src-072a522258abaa50bfe7abdeb1b4bf66ad931c67.tar.bz2 |
[Chromecast] Reland "Ignore interfaces not used to connect to internet."
Add NetworkChangeNotifierFactoryCast to create instance of
NetworkChangeNotifierLinux that ignores interfaces that will not be
used to connect to internet.
BUG=469863
R=gunsch@chromium.org
Review URL: https://codereview.chromium.org/1138923002
Cr-Commit-Position: refs/heads/master@{#329445}
Diffstat (limited to 'chromecast/net')
-rw-r--r-- | chromecast/net/net_util_cast.cc | 33 | ||||
-rw-r--r-- | chromecast/net/net_util_cast.h | 20 | ||||
-rw-r--r-- | chromecast/net/network_change_notifier_factory_cast.cc | 20 | ||||
-rw-r--r-- | chromecast/net/network_change_notifier_factory_cast.h | 31 |
4 files changed, 104 insertions, 0 deletions
diff --git a/chromecast/net/net_util_cast.cc b/chromecast/net/net_util_cast.cc new file mode 100644 index 0000000..6e68831 --- /dev/null +++ b/chromecast/net/net_util_cast.cc @@ -0,0 +1,33 @@ +// Copyright 2015 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 "chromecast/net/net_util_cast.h" + +#include "base/command_line.h" +#include "base/strings/string_split.h" +#include "chromecast/base/cast_sys_info_util.h" +#include "chromecast/net/net_switches.h" +#include "chromecast/public/cast_sys_info.h" + +namespace chromecast { + +base::hash_set<std::string> GetIgnoredInterfaces() { + base::hash_set<std::string> ignored_interfaces; + scoped_ptr<CastSysInfo> sys_info = CreateSysInfo(); + if (!sys_info->GetApInterface().empty()) + ignored_interfaces.insert(sys_info->GetApInterface()); + + // Add interfaces from "netif-to-ignore" switch. + base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); + base::CommandLine::StringType netifs_to_ignore_str = + command_line->GetSwitchValueNative(switches::kNetifsToIgnore); + base::CommandLine::StringVector netifs_to_ignore_vector; + base::SplitString(netifs_to_ignore_str, ',', &netifs_to_ignore_vector); + for (const auto& netif : netifs_to_ignore_vector) + ignored_interfaces.insert(netif); + + return ignored_interfaces; +} + +} // namespace chromecast diff --git a/chromecast/net/net_util_cast.h b/chromecast/net/net_util_cast.h new file mode 100644 index 0000000..2ec95bb --- /dev/null +++ b/chromecast/net/net_util_cast.h @@ -0,0 +1,20 @@ +// Copyright 2015 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 CHROMECAST_NET_NET_UTIL_H_ +#define CHROMECAST_NET_NET_UTIL_H_ + +#include <string> + +#include "base/containers/hash_tables.h" + +namespace chromecast { + +// Gets the list of interfaces that should be ignored. The interfaces returned +// by this function will not be used to connect to the internet. +base::hash_set<std::string> GetIgnoredInterfaces(); + +} // namespace chromecast + +#endif // CHROMECAST_NET_NET_UTIL_CAST_H_ diff --git a/chromecast/net/network_change_notifier_factory_cast.cc b/chromecast/net/network_change_notifier_factory_cast.cc new file mode 100644 index 0000000..4c1cd60 --- /dev/null +++ b/chromecast/net/network_change_notifier_factory_cast.cc @@ -0,0 +1,20 @@ +// Copyright 2015 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 "chromecast/net/network_change_notifier_factory_cast.h" + +#include "chromecast/net/net_util_cast.h" +#include "net/base/network_change_notifier_linux.h" + +namespace chromecast { + +net::NetworkChangeNotifier* NetworkChangeNotifierFactoryCast::CreateInstance() { + // Caller assumes ownership. + return new net::NetworkChangeNotifierLinux(GetIgnoredInterfaces()); +} + +NetworkChangeNotifierFactoryCast::~NetworkChangeNotifierFactoryCast() { +} + +} // namespace chromecast diff --git a/chromecast/net/network_change_notifier_factory_cast.h b/chromecast/net/network_change_notifier_factory_cast.h new file mode 100644 index 0000000..058d5b9 --- /dev/null +++ b/chromecast/net/network_change_notifier_factory_cast.h @@ -0,0 +1,31 @@ +// Copyright 2015 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 CHROMECAST_NET_NETWORK_CHANGE_NOTIFIER_FACTORY_CAST_H_ +#define CHROMECAST_NET_NETWORK_CHANGE_NOTIFIER_FACTORY_CAST_H_ + +#include "base/compiler_specific.h" +#include "base/macros.h" +#include "net/base/network_change_notifier_factory.h" + +namespace chromecast { + +class NetworkChangeNotifierCast; + +class NetworkChangeNotifierFactoryCast + : public net::NetworkChangeNotifierFactory { + public: + NetworkChangeNotifierFactoryCast() {} + ~NetworkChangeNotifierFactoryCast() override; + + // net::NetworkChangeNotifierFactory implementation: + net::NetworkChangeNotifier* CreateInstance() override; + + private: + DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierFactoryCast); +}; + +} // namespace chromecast + +#endif // CHROMECAST_NET_NETWORK_CHANGE_NOTIFIER_FACTORY_CAST_H_ |