diff options
author | chocobo@chromium.org <chocobo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-01 17:54:36 +0000 |
---|---|---|
committer | chocobo@chromium.org <chocobo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-01 17:54:36 +0000 |
commit | 39216bee9402bb343519cdb4cd517dc5120531b4 (patch) | |
tree | 654b9f6087aef8f8c4b616201c496d16bb4af127 /chrome/browser/chromeos/network_message_observer.cc | |
parent | 6aa2cf2f5587562974b60eb0a4aa847942d67a49 (diff) | |
download | chromium_src-39216bee9402bb343519cdb4cd517dc5120531b4.zip chromium_src-39216bee9402bb343519cdb4cd517dc5120531b4.tar.gz chromium_src-39216bee9402bb343519cdb4cd517dc5120531b4.tar.bz2 |
Added notification for network message.
BUG=chromium-os:2556
TEST=manually connect to network with wrong password and see notification.
Review URL: http://codereview.chromium.org/2074017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@48641 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chromeos/network_message_observer.cc')
-rw-r--r-- | chrome/browser/chromeos/network_message_observer.cc | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/chrome/browser/chromeos/network_message_observer.cc b/chrome/browser/chromeos/network_message_observer.cc new file mode 100644 index 0000000..d722212 --- /dev/null +++ b/chrome/browser/chromeos/network_message_observer.cc @@ -0,0 +1,80 @@ +// Copyright (c) 2010 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/network_message_observer.h" + +#include "app/l10n_util.h" +#include "chrome/browser/chromeos/cros/cros_library.h" +#include "chrome/browser/chromeos/cros/network_library.h" +#include "grit/generated_resources.h" +#include "grit/theme_resources.h" + +namespace chromeos { + +NetworkMessageObserver::NetworkMessageObserver(Profile* profile) + : notification_(profile, "network_connection.chromeos", + IDR_NOTIFICATION_NETWORK_FAILED, + l10n_util::GetStringUTF16(IDS_NETWORK_CONNECTION_ERROR_TITLE)) { + // On startup, we may already have failed netorks. + // So marked these as known failed. + NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); + const WifiNetworkVector& wifi_networks = cros->wifi_networks(); + for (WifiNetworkVector::const_iterator it = wifi_networks.begin(); + it < wifi_networks.end(); it++) { + const WifiNetwork& wifi = *it; + if (wifi.failed()) + failed_networks_.insert(wifi.name()); + } + const CellularNetworkVector& cellular_networks = cros->cellular_networks(); + for (CellularNetworkVector::const_iterator it = cellular_networks.begin(); + it < cellular_networks.end(); it++) { + const CellularNetwork& cellular = *it; + if (cellular.failed()) + failed_networks_.insert(cellular.name()); + } +} + +NetworkMessageObserver::~NetworkMessageObserver() { + notification_.Hide(); +} + +void NetworkMessageObserver::NetworkChanged(NetworkLibrary* obj) { + std::set<std::string> failed; + std::string new_failed_network; + + // For each call to NetworkChanged, we expect at most 1 new failed network. + // So we just keep track of it if we find a newly failed network by comparing + // against or stored failed networks. And we only display notification if we + // find a newly failed network. + const WifiNetworkVector& wifi_networks = obj->wifi_networks(); + for (WifiNetworkVector::const_iterator it = wifi_networks.begin(); + it < wifi_networks.end(); it++) { + const WifiNetwork& wifi = *it; + if (wifi.failed()) { + failed.insert(wifi.name()); + if (failed_networks_.find(wifi.name()) + == failed_networks_.end()) + new_failed_network = wifi.name(); + } + } + const CellularNetworkVector& cellular_networks = obj->cellular_networks(); + for (CellularNetworkVector::const_iterator it = cellular_networks.begin(); + it < cellular_networks.end(); it++) { + const CellularNetwork& cellular = *it; + if (cellular.failed()) { + failed.insert(cellular.name()); + if (failed_networks_.find(cellular.name()) + == failed_networks_.end()) + new_failed_network = cellular.name(); + } + } + + failed_networks_ = failed; + if (!new_failed_network.empty()) + notification_.Show(l10n_util::GetStringFUTF16( + IDS_NETWORK_CONNECTION_ERROR_MESSAGE, + ASCIIToUTF16(new_failed_network)), true); +} + +} // namespace chromeos |