Commit 072a5222 authored by derekjchow's avatar derekjchow Committed by Commit bot

[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}
parent 9b3bd4f8
...@@ -50,6 +50,7 @@ ...@@ -50,6 +50,7 @@
#include "net/android/network_change_notifier_factory_android.h" #include "net/android/network_change_notifier_factory_android.h"
#else #else
#include "chromecast/browser/media/cast_browser_cdm_factory.h" #include "chromecast/browser/media/cast_browser_cdm_factory.h"
#include "chromecast/net/network_change_notifier_factory_cast.h"
#endif #endif
#if defined(USE_AURA) #if defined(USE_AURA)
...@@ -227,6 +228,9 @@ void CastBrowserMainParts::PreMainMessageLoopStart() { ...@@ -227,6 +228,9 @@ void CastBrowserMainParts::PreMainMessageLoopStart() {
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
net::NetworkChangeNotifier::SetFactory( net::NetworkChangeNotifier::SetFactory(
new net::NetworkChangeNotifierFactoryAndroid()); new net::NetworkChangeNotifierFactoryAndroid());
#else
net::NetworkChangeNotifier::SetFactory(
new NetworkChangeNotifierFactoryCast());
#endif // defined(OS_ANDROID) #endif // defined(OS_ANDROID)
} }
......
...@@ -103,6 +103,16 @@ ...@@ -103,6 +103,16 @@
'net/connectivity_checker.h', 'net/connectivity_checker.h',
'net/net_switches.cc', 'net/net_switches.cc',
'net/net_switches.h', 'net/net_switches.h',
'net/net_util_cast.cc',
'net/net_util_cast.h',
],
'conditions': [
['OS!="android"', {
'sources': [
'net/network_change_notifier_factory_cast.cc',
'net/network_change_notifier_factory_cast.h',
],
}],
], ],
}, },
{ {
......
// 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
// 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_
// 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
// 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_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment