diff options
author | zelidrag@chromium.org <zelidrag@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-11 21:55:58 +0000 |
---|---|---|
committer | zelidrag@chromium.org <zelidrag@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-11 21:55:58 +0000 |
commit | 373badd8ec80d9ff5645cdeb18a7ad57f43e4b35 (patch) | |
tree | 6cf7db3be5832874ac44719825e21ea3ce3acf15 /net | |
parent | c5afccb09e2b865b20803d44e9fb1b7cb39ca123 (diff) | |
download | chromium_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
Diffstat (limited to 'net')
-rw-r--r-- | net/base/network_change_notifier.cc | 19 | ||||
-rw-r--r-- | net/base/network_change_notifier.h | 6 | ||||
-rw-r--r-- | net/base/network_change_notifier_factory.h | 25 | ||||
-rw-r--r-- | net/net.gyp | 1 |
4 files changed, 51 insertions, 0 deletions
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', |