summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzelidrag@chromium.org <zelidrag@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-11 21:55:58 +0000
committerzelidrag@chromium.org <zelidrag@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-11 21:55:58 +0000
commit373badd8ec80d9ff5645cdeb18a7ad57f43e4b35 (patch)
tree6cf7db3be5832874ac44719825e21ea3ce3acf15
parentc5afccb09e2b865b20803d44e9fb1b7cb39ca123 (diff)
downloadchromium_src-373badd8ec80d9ff5645cdeb18a7ad57f43e4b35.zip
chromium_src-373badd8ec80d9ff5645cdeb18a7ad57f43e4b35.tar.gz
chromium_src-373badd8ec80d9ff5645cdeb18a7ad57f43e4b35.tar.bz2
Fixed network connectivity checks specific to ChromeOS. Previously we were doing this check only for network specific changes and missing the initial connect event.
This change also include the fix for passing the initial connectivity state of the network for all platforms. BUG=chromium-os:17165,86538 TEST=Make sure "Your device is offline" page refreshes properly once connection is establishes on chromeos. Review URL: http://codereview.chromium.org/7285021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@92062 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/browser_main.cc15
-rw-r--r--chrome/browser/chromeos/net/cros_network_change_notifier_factory.cc14
-rw-r--r--chrome/browser/chromeos/net/cros_network_change_notifier_factory.h29
-rw-r--r--chrome/browser/chromeos/net/network_change_notifier_chromeos.cc52
-rw-r--r--chrome/browser/chromeos/net/network_change_notifier_chromeos.h2
-rw-r--r--chrome/browser/tab_contents/render_view_host_delegate_helper.cc3
-rw-r--r--chrome/chrome_browser.gypi2
-rw-r--r--content/common/view_messages.h1
-rw-r--r--net/base/network_change_notifier.cc19
-rw-r--r--net/base/network_change_notifier.h6
-rw-r--r--net/base/network_change_notifier_factory.h25
-rw-r--r--net/net.gyp1
-rw-r--r--webkit/glue/webpreferences.cc5
-rw-r--r--webkit/glue/webpreferences.h3
14 files changed, 147 insertions, 30 deletions
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc
index 67bd547..e5711cc 100644
--- a/chrome/browser/browser_main.cc
+++ b/chrome/browser/browser_main.cc
@@ -147,7 +147,7 @@
#include "chrome/browser/chromeos/login/screen_locker.h"
#include "chrome/browser/chromeos/login/user_manager.h"
#include "chrome/browser/chromeos/metrics_cros_settings_provider.h"
-#include "chrome/browser/chromeos/net/network_change_notifier_chromeos.h"
+#include "chrome/browser/chromeos/net/cros_network_change_notifier_factory.h"
#include "chrome/browser/chromeos/system_key_event_listener.h"
#include "chrome/browser/chromeos/xinput_hierarchy_changed_event_listener.h"
#include "chrome/browser/oom_priority_manager.h"
@@ -570,15 +570,7 @@ void BrowserMainParts::MainMessageLoopStart() {
InitializeMainThread();
-#if defined(OS_CHROMEOS)
- // TODO(zelidrag): We need to move cros library glue code outside of
- // chrome/browser directory to avoid check_deps issues and then migrate
- // NetworkChangeNotifierCros class to net/base where other OS implementations
- // live.
- network_change_notifier_.reset(new chromeos::NetworkChangeNotifierChromeos());
-#else
network_change_notifier_.reset(net::NetworkChangeNotifier::Create());
-#endif
PostMainMessageLoopStart();
Profiling::MainMessageLoopStarted();
@@ -1285,6 +1277,11 @@ int BrowserMain(const MainFunctionParams& parameters) {
// SetUseStubImpl doesn't do anything.
if (parameters.command_line_.HasSwitch(switches::kStubCros))
chromeos::CrosLibrary::Get()->GetTestApi()->SetUseStubImpl();
+
+ // Replace the default NetworkChangeNotifierFactory with ChromeOS specific
+ // implementation.
+ net::NetworkChangeNotifier::SetFactory(
+ new chromeos::CrosNetworkChangeNotifierFactory());
#endif
parts->MainMessageLoopStart();
diff --git a/chrome/browser/chromeos/net/cros_network_change_notifier_factory.cc b/chrome/browser/chromeos/net/cros_network_change_notifier_factory.cc
new file mode 100644
index 0000000..ad38c6c
--- /dev/null
+++ b/chrome/browser/chromeos/net/cros_network_change_notifier_factory.cc
@@ -0,0 +1,14 @@
+// Copyright (c) 2011 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 "chrome/browser/chromeos/net/cros_network_change_notifier_factory.h"
+
+#include "chrome/browser/chromeos/net/network_change_notifier_chromeos.h"
+
+namespace chromeos {
+
+net::NetworkChangeNotifier* CrosNetworkChangeNotifierFactory::CreateInstance() {
+ return new NetworkChangeNotifierChromeos();
+}
+
+} // namespace net
diff --git a/chrome/browser/chromeos/net/cros_network_change_notifier_factory.h b/chrome/browser/chromeos/net/cros_network_change_notifier_factory.h
new file mode 100644
index 0000000..73c7663
--- /dev/null
+++ b/chrome/browser/chromeos/net/cros_network_change_notifier_factory.h
@@ -0,0 +1,29 @@
+// Copyright (c) 2011 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 CHROME_BROWSER_CHROMEOS_NET_CROS_NETWORK_CHANGE_NOTIFIER_FACTORY_H_
+#define CHROME_BROWSER_CHROMEOS_NET_CROS_NETWORK_CHANGE_NOTIFIER_FACTORY_H_
+#pragma once
+
+#include "base/compiler_specific.h"
+#include "net/base/network_change_notifier_factory.h"
+
+namespace chromeos {
+
+class NetworkChangeNotifier;
+
+// CrosNetworkChangeNotifierFactory creates ChromeOS-specific specialization of
+// NetworkChangeNotifier.
+class CrosNetworkChangeNotifierFactory
+ : public net::NetworkChangeNotifierFactory {
+ public:
+ CrosNetworkChangeNotifierFactory() {}
+
+ // Overrides of net::NetworkChangeNotifierFactory.
+ virtual net::NetworkChangeNotifier* CreateInstance() OVERRIDE;
+};
+
+} // namespace net
+
+#endif // CHROME_BROWSER_CHROMEOS_NET_CROS_NETWORK_CHANGE_NOTIFIER_FACTORY_H_
diff --git a/chrome/browser/chromeos/net/network_change_notifier_chromeos.cc b/chrome/browser/chromeos/net/network_change_notifier_chromeos.cc
index b8c1dc9..5fffbf7 100644
--- a/chrome/browser/chromeos/net/network_change_notifier_chromeos.cc
+++ b/chrome/browser/chromeos/net/network_change_notifier_chromeos.cc
@@ -14,13 +14,16 @@ NetworkChangeNotifierChromeos::NetworkChangeNotifierChromeos()
: has_active_network_(false),
connection_state_(chromeos::STATE_UNKNOWN) {
- chromeos::NetworkLibrary* lib =
+ chromeos::NetworkLibrary* net =
chromeos::CrosLibrary::Get()->GetNetworkLibrary();
- lib->AddNetworkManagerObserver(this);
+ net->AddNetworkManagerObserver(this);
chromeos::PowerLibrary* power =
chromeos::CrosLibrary::Get()->GetPowerLibrary();
power->AddObserver(this);
+
+ connection_state_ = net->active_network() ?
+ net->active_network()->connection_state() : chromeos::STATE_UNKNOWN;
}
NetworkChangeNotifierChromeos::~NetworkChangeNotifierChromeos() {
@@ -55,6 +58,18 @@ bool NetworkChangeNotifierChromeos::IsCurrentlyOffline() const {
return connection_state_ != chromeos::STATE_ONLINE;
}
+void NetworkChangeNotifierChromeos::OnNetworkChanged(
+ chromeos::NetworkLibrary* cros,
+ const chromeos::Network* network) {
+ CHECK(network);
+
+ // Active network changed?
+ if (network->service_path() != service_path_)
+ UpdateNetworkState(cros);
+ else
+ UpdateConnectivityState(network);
+}
+
void NetworkChangeNotifierChromeos::UpdateNetworkState(
chromeos::NetworkLibrary* lib) {
const chromeos::Network* network = lib->active_network();
@@ -70,12 +85,17 @@ void NetworkChangeNotifierChromeos::UpdateNetworkState(
has_active_network_ = false;
service_path_.clear();
ip_address_.clear();
+ connection_state_ = chromeos::STATE_UNKNOWN;
} else {
has_active_network_ = true;
service_path_ = network->service_path();
ip_address_ = network->ip_address();
- lib->AddNetworkObserver(network->service_path(), this);
}
+ UpdateConnectivityState(network);
+ // If there is an active network, add observer to track its changes.
+ if (network)
+ lib->AddNetworkObserver(network->service_path(), this);
+
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
NewRunnableFunction(
@@ -83,36 +103,30 @@ void NetworkChangeNotifierChromeos::UpdateNetworkState(
}
}
-void NetworkChangeNotifierChromeos::OnNetworkChanged(
- chromeos::NetworkLibrary* cros,
- const chromeos::Network* network) {
- if (!network) {
- NOTREACHED();
- return;
- }
- // Active network changed?
- if (network->service_path() != service_path_) {
- UpdateNetworkState(cros);
- }
-
+void NetworkChangeNotifierChromeos::UpdateConnectivityState(
+ const chromeos::Network* network) {
// We don't care about all transitions of ConnectionState. OnlineStateChange
// notification should trigger if
// a) we were online and went offline
// b) we were offline and went online
// c) switched to/from captive portal
- chromeos::ConnectionState new_connection_state = network->connection_state();
+ chromeos::ConnectionState new_connection_state =
+ network ? network->connection_state() : chromeos::STATE_UNKNOWN;
+
bool is_online = (new_connection_state == chromeos::STATE_ONLINE);
bool was_online = (connection_state_ == chromeos::STATE_ONLINE);
bool is_portal = (new_connection_state == chromeos::STATE_PORTAL);
bool was_portal = (connection_state_ == chromeos::STATE_PORTAL);
-
- if (is_online != was_online || is_portal != was_portal) {
+ bool is_unknown = (new_connection_state == chromeos::STATE_UNKNOWN);
+ bool was_unknown = (connection_state_ == chromeos::STATE_UNKNOWN);
+ connection_state_ = new_connection_state;
+ if (is_online != was_online || is_portal != was_portal ||
+ is_unknown != was_unknown) {
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
NewRunnableFunction(
&NetworkChangeNotifierChromeos::NotifyObserversOfOnlineStateChange));
}
- connection_state_ = new_connection_state;
}
} // namespace net
diff --git a/chrome/browser/chromeos/net/network_change_notifier_chromeos.h b/chrome/browser/chromeos/net/network_change_notifier_chromeos.h
index 4fa94b9..b3ab865 100644
--- a/chrome/browser/chromeos/net/network_change_notifier_chromeos.h
+++ b/chrome/browser/chromeos/net/network_change_notifier_chromeos.h
@@ -40,6 +40,8 @@ class NetworkChangeNotifierChromeos
// Updates data members that keep the track the network stack state.
void UpdateNetworkState(chromeos::NetworkLibrary* cros);
+ // Updates network connectivity state.
+ void UpdateConnectivityState(const chromeos::Network* network);
// True if we previously had an active network around.
bool has_active_network_;
diff --git a/chrome/browser/tab_contents/render_view_host_delegate_helper.cc b/chrome/browser/tab_contents/render_view_host_delegate_helper.cc
index 3f23de0..e2e2bc3 100644
--- a/chrome/browser/tab_contents/render_view_host_delegate_helper.cc
+++ b/chrome/browser/tab_contents/render_view_host_delegate_helper.cc
@@ -33,6 +33,7 @@
#include "content/browser/tab_contents/tab_contents_view.h"
#include "content/browser/webui/web_ui.h"
#include "content/common/notification_service.h"
+#include "net/base/network_change_notifier.h"
RenderViewHostDelegateViewHelper::RenderViewHostDelegateViewHelper() {
registrar_.Add(this, content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
@@ -395,6 +396,8 @@ WebPreferences RenderViewHostDelegateHelper::GetWebkitPrefs(
web_prefs.javascript_enabled = true;
}
+ web_prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
+
return web_prefs;
}
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 75c5e1f..33a8cd1 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -635,6 +635,8 @@
'browser/chromeos/metrics_cros_settings_provider.h',
'browser/chromeos/native_dialog_window.cc',
'browser/chromeos/native_dialog_window.h',
+ 'browser/chromeos/net/cros_network_change_notifier_factory.cc',
+ 'browser/chromeos/net/cros_network_change_notifier_factory.h',
'browser/chromeos/net/network_change_notifier_chromeos.cc',
'browser/chromeos/net/network_change_notifier_chromeos.h',
'browser/chromeos/network_login_observer.cc',
diff --git a/content/common/view_messages.h b/content/common/view_messages.h
index 7c3ef4a..f7a1bcd 100644
--- a/content/common/view_messages.h
+++ b/content/common/view_messages.h
@@ -303,6 +303,7 @@ IPC_STRUCT_TRAITS_BEGIN(WebPreferences)
IPC_STRUCT_TRAITS_MEMBER(application_cache_enabled)
IPC_STRUCT_TRAITS_MEMBER(tabs_to_links)
IPC_STRUCT_TRAITS_MEMBER(hyperlink_auditing_enabled)
+ IPC_STRUCT_TRAITS_MEMBER(is_online)
IPC_STRUCT_TRAITS_MEMBER(user_style_sheet_enabled)
IPC_STRUCT_TRAITS_MEMBER(user_style_sheet_location)
IPC_STRUCT_TRAITS_MEMBER(author_and_user_styles_enabled)
diff --git a/net/base/network_change_notifier.cc b/net/base/network_change_notifier.cc
index 5fa0645..2eb59ad 100644
--- a/net/base/network_change_notifier.cc
+++ b/net/base/network_change_notifier.cc
@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "net/base/network_change_notifier.h"
+#include "net/base/network_change_notifier_factory.h"
#include "build/build_config.h"
#if defined(OS_WIN)
#include "net/base/network_change_notifier_win.h"
@@ -22,6 +23,9 @@ namespace {
// anyway.)
NetworkChangeNotifier* g_network_change_notifier = NULL;
+// Class factory singleton.
+NetworkChangeNotifierFactory* g_network_change_notifier_factory = NULL;
+
class MockNetworkChangeNotifier : public NetworkChangeNotifier {
public:
virtual bool IsCurrentlyOffline() const { return false; }
@@ -34,9 +38,24 @@ NetworkChangeNotifier::~NetworkChangeNotifier() {
g_network_change_notifier = NULL;
}
+// static
+void NetworkChangeNotifier::SetFactory(
+ NetworkChangeNotifierFactory* factory) {
+ CHECK(!g_network_change_notifier_factory);
+ g_network_change_notifier_factory = factory;
+}
+
+// static
NetworkChangeNotifier* NetworkChangeNotifier::Create() {
+ if (g_network_change_notifier_factory)
+ return g_network_change_notifier_factory->CreateInstance();
+
#if defined(OS_WIN)
return new NetworkChangeNotifierWin();
+#elif defined(OS_CHROMEOS)
+ // ChromeOS builds MUST use its own class factory.
+ CHECK(false);
+ return NULL;
#elif defined(OS_LINUX) || defined(OS_ANDROID)
return new NetworkChangeNotifierLinux();
#elif defined(OS_MACOSX)
diff --git a/net/base/network_change_notifier.h b/net/base/network_change_notifier.h
index 246346d..fe2a8f1 100644
--- a/net/base/network_change_notifier.h
+++ b/net/base/network_change_notifier.h
@@ -12,6 +12,8 @@
namespace net {
+class NetworkChangeNotifierFactory;
+
// NetworkChangeNotifier monitors the system for network changes, and notifies
// registered observers of those events. Observers may register on any thread,
// and will be called back on the thread from which they registered.
@@ -55,6 +57,10 @@ class NET_API NetworkChangeNotifier {
// cheap as this could be called (repeatedly) from the IO thread.
virtual bool IsCurrentlyOffline() const = 0;
+ // Replaces the default class factory instance of NetworkChangeNotifier class.
+ // The method will take over the ownership of |factory| object.
+ static void SetFactory(NetworkChangeNotifierFactory* factory);
+
// Creates the process-wide, platform-specific NetworkChangeNotifier. The
// caller owns the returned pointer. You may call this on any thread. You
// may also avoid creating this entirely (in which case nothing will be
diff --git a/net/base/network_change_notifier_factory.h b/net/base/network_change_notifier_factory.h
new file mode 100644
index 0000000..d4f3f8d
--- /dev/null
+++ b/net/base/network_change_notifier_factory.h
@@ -0,0 +1,25 @@
+// Copyright (c) 2011 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 NET_BASE_NETWORK_CHANGE_NOTIFIER_FACTORY_H_
+#define NET_BASE_NETWORK_CHANGE_NOTIFIER_FACTORY_H_
+#pragma once
+
+#include "net/base/net_api.h"
+
+namespace net {
+
+class NetworkChangeNotifier;
+// NetworkChangeNotifierFactory provides a mechanism for overriding the default
+// instance creation process of NetworkChangeNotifier.
+class NET_API NetworkChangeNotifierFactory {
+ public:
+ NetworkChangeNotifierFactory() {}
+ virtual ~NetworkChangeNotifierFactory() {}
+ virtual NetworkChangeNotifier* CreateInstance() = 0;
+};
+
+} // namespace net
+
+#endif // NET_BASE_NETWORK_CHANGE_NOTIFIER_FACTORY_H_
diff --git a/net/net.gyp b/net/net.gyp
index 996954a..40de019 100644
--- a/net/net.gyp
+++ b/net/net.gyp
@@ -152,6 +152,7 @@
'base/net_util_win.cc',
'base/network_change_notifier.cc',
'base/network_change_notifier.h',
+ 'base/network_change_notifier_factory.h',
'base/network_change_notifier_linux.cc',
'base/network_change_notifier_linux.h',
'base/network_change_notifier_mac.cc',
diff --git a/webkit/glue/webpreferences.cc b/webkit/glue/webpreferences.cc
index 362c212..dec3db6 100644
--- a/webkit/glue/webpreferences.cc
+++ b/webkit/glue/webpreferences.cc
@@ -6,6 +6,7 @@
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebNetworkStateNotifier.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebRuntimeFeatures.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebSettings.h"
@@ -14,6 +15,7 @@
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
#include "webkit/glue/webkit_glue.h"
+using WebKit::WebNetworkStateNotifier;
using WebKit::WebRuntimeFeatures;
using WebKit::WebSettings;
using WebKit::WebString;
@@ -56,6 +58,7 @@ WebPreferences::WebPreferences()
tabs_to_links(true),
caret_browsing_enabled(false),
hyperlink_auditing_enabled(true),
+ is_online(true),
user_style_sheet_enabled(false),
author_and_user_styles_enabled(true),
frame_flattening_enabled(false),
@@ -233,4 +236,6 @@ void WebPreferences::Apply(WebView* web_view) const {
settings->setAllowRunningOfInsecureContent(allow_running_insecure_content);
settings->setShouldPrintBackgrounds(should_print_backgrounds);
settings->setEnableScrollAnimator(enable_scroll_animator);
+
+ WebNetworkStateNotifier::setOnLine(is_online);
}
diff --git a/webkit/glue/webpreferences.h b/webkit/glue/webpreferences.h
index 78dc8f1..77414b8 100644
--- a/webkit/glue/webpreferences.h
+++ b/webkit/glue/webpreferences.h
@@ -63,7 +63,7 @@ struct WebPreferences {
bool tabs_to_links;
bool caret_browsing_enabled;
bool hyperlink_auditing_enabled;
-
+ bool is_online;
bool user_style_sheet_enabled;
GURL user_style_sheet_location;
bool author_and_user_styles_enabled;
@@ -92,7 +92,6 @@ struct WebPreferences {
bool allow_running_insecure_content;
bool should_print_backgrounds;
bool enable_scroll_animator;
-
// We try to keep the default values the same as the default values in
// chrome, except for the cases where it would require lots of extra work for
// the embedder to use the same default value.