Chromium Code Reviews
|
| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/network_login_observer.h" | |
| 6 | |
| 7 #include "chrome/browser/browser_list.h" | |
| 8 #include "chrome/browser/browser_window.h" | |
| 9 #include "chrome/browser/chromeos/cros/cros_library.h" | |
| 10 #include "chrome/browser/chromeos/cros/network_library.h" | |
| 11 #include "chrome/browser/chromeos/login/background_view.h" | |
| 12 #include "chrome/browser/chromeos/login/login_utils.h" | |
| 13 #include "chrome/browser/chromeos/options/network_config_view.h" | |
| 14 #include "chrome/browser/ui/browser.h" | |
| 15 #include "chrome/browser/views/window.h" | |
| 16 #include "views/window/dialog_delegate.h" | |
| 17 #include "views/window/window.h" | |
| 18 | |
| 19 namespace chromeos { | |
| 20 | |
| 21 NetworkLoginObserver::NetworkLoginObserver(NetworkLibrary* netlib) { | |
| 22 OnNetworkManagerChanged(netlib); | |
| 23 initialized_ = true; | |
|
stevenjb
2011/01/11 20:53:52
nit: Rather than tracking an initiailized_ state,
Charlie Lee
2011/01/11 22:52:06
Done.
| |
| 24 netlib->AddNetworkManagerObserver(this); | |
| 25 } | |
| 26 | |
| 27 NetworkLoginObserver::~NetworkLoginObserver() { | |
| 28 CrosLibrary::Get()->GetNetworkLibrary()->RemoveNetworkManagerObserver(this); | |
| 29 STLDeleteValues(&wifi_networks_); | |
| 30 } | |
| 31 | |
| 32 void NetworkLoginObserver::CreateModalPopup(views::WindowDelegate* view) { | |
| 33 Browser* browser = BrowserList::GetLastActive(); | |
| 34 if (browser && browser->type() != Browser::TYPE_NORMAL) { | |
|
stevenjb
2011/01/11 20:53:52
FindBrowserWithType() searches in order of last ac
Charlie Lee
2011/01/11 22:52:06
FindBrowserWithType takes in a profile which we ge
stevenjb
2011/01/12 01:34:52
I forgot to add that we would need to use ProfileM
| |
| 35 browser = BrowserList::FindBrowserWithType(browser->profile(), | |
| 36 Browser::TYPE_NORMAL, | |
| 37 true); | |
| 38 } | |
| 39 if (browser) { | |
| 40 views::Window* window = browser::CreateViewsWindow( | |
| 41 browser->window()->GetNativeHandle(), gfx::Rect(), view); | |
| 42 window->SetIsAlwaysOnTop(true); | |
| 43 window->Show(); | |
| 44 return; | |
|
stevenjb
2011/01/11 20:53:52
nit: return statement is unnecessary.
Charlie Lee
2011/01/11 22:52:06
Done.
| |
| 45 } else { | |
| 46 // Browser not found, so we should be in login/oobe screen. | |
| 47 BackgroundView* background_view = LoginUtils::Get()->GetBackgroundView(); | |
| 48 if (background_view) { | |
| 49 background_view->CreateModalPopup(view); | |
| 50 } | |
| 51 } | |
| 52 } | |
| 53 | |
| 54 void NetworkLoginObserver::OnNetworkManagerChanged(NetworkLibrary* obj) { | |
| 55 const WifiNetworkVector& wifi_networks = obj->wifi_networks(); | |
| 56 | |
| 57 NetworkConfigView* view = NULL; | |
| 58 // Check to see if we have any newly failed wifi network. | |
| 59 for (WifiNetworkVector::const_iterator it = wifi_networks.begin(); | |
| 60 it < wifi_networks.end(); it++) { | |
| 61 const WifiNetwork* wifi = *it; | |
| 62 if (wifi->failed()) { | |
| 63 ServicePathWifiMap::iterator iter = | |
| 64 wifi_networks_.find(wifi->service_path()); | |
| 65 // If the network did not previously exist, then don't do anything. | |
| 66 // For example, if the user travels to a location and finds a service | |
| 67 // that has previously failed, we don't want to show an error. | |
| 68 if (iter == wifi_networks_.end()) | |
| 69 continue; | |
| 70 | |
| 71 const WifiNetwork* wifi_old = iter->second; | |
| 72 // If this network was in a failed state previously, then it's not new. | |
| 73 if (wifi_old->failed()) | |
| 74 continue; | |
| 75 | |
| 76 // Display login box again for bad_passphrase and bad_wepkey errors. | |
| 77 if (wifi->error() == ERROR_BAD_PASSPHRASE || | |
| 78 wifi->error() == ERROR_BAD_WEPKEY) { | |
| 79 // The NetworkConfigView will show the appropriate error message. | |
| 80 view = new NetworkConfigView(wifi); | |
| 81 // There should only be one wifi network that failed to connect. | |
| 82 // If for some reason, we have more than one failure, | |
| 83 // we only display the first one. So we break here. | |
| 84 break; | |
| 85 } | |
| 86 } | |
| 87 } | |
| 88 | |
| 89 // Refresh stored networks. | |
| 90 STLDeleteValues(&wifi_networks_); | |
| 91 wifi_networks_.clear(); | |
| 92 for (WifiNetworkVector::const_iterator it = wifi_networks.begin(); | |
| 93 it < wifi_networks.end(); it++) { | |
| 94 const WifiNetwork* wifi = *it; | |
| 95 wifi_networks_[wifi->service_path()] = new WifiNetwork(*wifi); | |
|
stevenjb
2011/01/11 20:53:52
We are doing a lot of unnecessary copying of WifiN
Charlie Lee
2011/01/11 22:52:06
Done.
| |
| 96 } | |
| 97 | |
| 98 // Show login box if necessary. | |
| 99 if (view && initialized_) | |
| 100 CreateModalPopup(view); | |
| 101 } | |
| 102 | |
| 103 } // namespace chromeos | |
| OLD | NEW |