diff options
author | craigdh@google.com <craigdh@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-20 18:44:11 +0000 |
---|---|---|
committer | craigdh@google.com <craigdh@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-20 18:44:11 +0000 |
commit | f717d1c16299c239d17c3e535e00bfa2d3fd6440 (patch) | |
tree | 266055c580c9e17d45e1594685fd64ee220d5a4e /chrome/browser/automation/automation_provider_observers_chromeos.cc | |
parent | 3768122148fcc0183f8d76efc0fd743096c50767 (diff) | |
download | chromium_src-f717d1c16299c239d17c3e535e00bfa2d3fd6440.zip chromium_src-f717d1c16299c239d17c3e535e00bfa2d3fd6440.tar.gz chromium_src-f717d1c16299c239d17c3e535e00bfa2d3fd6440.tar.bz2 |
Added automation hooks for private networks.
BUG=chromium-os:16586
TEST=
Review URL: http://codereview.chromium.org/7144011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@89702 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/automation/automation_provider_observers_chromeos.cc')
-rw-r--r-- | chrome/browser/automation/automation_provider_observers_chromeos.cc | 91 |
1 files changed, 79 insertions, 12 deletions
diff --git a/chrome/browser/automation/automation_provider_observers_chromeos.cc b/chrome/browser/automation/automation_provider_observers_chromeos.cc index 9e2efbb..0d166da 100644 --- a/chrome/browser/automation/automation_provider_observers_chromeos.cc +++ b/chrome/browser/automation/automation_provider_observers_chromeos.cc @@ -133,7 +133,7 @@ void ScreenUnlockObserver::OnLoginFailure(const chromeos::LoginFailure& error) { NetworkScanObserver::NetworkScanObserver(AutomationProvider* automation, IPC::Message* reply_message) - : automation_(automation), reply_message_(reply_message) { + : automation_(automation->AsWeakPtr()), reply_message_(reply_message) { NetworkLibrary* network_library = CrosLibrary::Get()->GetNetworkLibrary(); network_library->AddNetworkManagerObserver(this); } @@ -147,13 +147,16 @@ void NetworkScanObserver::OnNetworkManagerChanged(NetworkLibrary* obj) { if (obj->wifi_scanning()) return; - AutomationJSONReply(automation_, reply_message_).SendSuccess(NULL); + if (automation_) { + AutomationJSONReply(automation_, + reply_message_.release()).SendSuccess(NULL); + } delete this; } NetworkConnectObserver::NetworkConnectObserver(AutomationProvider* automation, IPC::Message* reply_message) - : automation_(automation), reply_message_(reply_message) { + : automation_(automation->AsWeakPtr()), reply_message_(reply_message) { NetworkLibrary* network_library = CrosLibrary::Get()->GetNetworkLibrary(); network_library->AddNetworkManagerObserver(this); } @@ -168,22 +171,28 @@ void NetworkConnectObserver::OnNetworkManagerChanged(NetworkLibrary* obj) { if (!wifi) { // The network was not found, and we assume it no longer exists. // This could be because the SSID is invalid, or the network went away. - scoped_ptr<DictionaryValue> return_value(new DictionaryValue); - return_value->SetString("error_string", "Network not found."); - AutomationJSONReply(automation_, reply_message_) - .SendSuccess(return_value.get()); + if (automation_) { + scoped_ptr<DictionaryValue> return_value(new DictionaryValue); + return_value->SetString("error_string", "Network not found."); + AutomationJSONReply(automation_, reply_message_.release()) + .SendSuccess(return_value.get()); + } delete this; return; } if (wifi->failed()) { - scoped_ptr<DictionaryValue> return_value(new DictionaryValue); - return_value->SetString("error_string", wifi->GetErrorString()); - AutomationJSONReply(automation_, reply_message_) - .SendSuccess(return_value.get()); + if (automation_) { + scoped_ptr<DictionaryValue> return_value(new DictionaryValue); + return_value->SetString("error_string", wifi->GetErrorString()); + AutomationJSONReply(automation_, reply_message_.release()) + .SendSuccess(return_value.get()); + } delete this; } else if (wifi->connected()) { - AutomationJSONReply(automation_, reply_message_).SendSuccess(NULL); + if (automation_) + AutomationJSONReply(automation_, + reply_message_.release()).SendSuccess(NULL); delete this; } @@ -202,6 +211,64 @@ const chromeos::WifiNetwork* ServicePathConnectObserver::GetWifiNetwork( return network_library->FindWifiNetworkByPath(service_path_); } +VirtualConnectObserver::VirtualConnectObserver(AutomationProvider* automation, + IPC::Message* reply_message, + const std::string& service_name) + : automation_(automation->AsWeakPtr()), + reply_message_(reply_message), + service_name_(service_name) { + NetworkLibrary* network_library = CrosLibrary::Get()->GetNetworkLibrary(); + network_library->AddNetworkManagerObserver(this); +} + +VirtualConnectObserver::~VirtualConnectObserver() { + NetworkLibrary* network_library = CrosLibrary::Get()->GetNetworkLibrary(); + network_library->RemoveNetworkManagerObserver(this); +} + +void VirtualConnectObserver::OnNetworkManagerChanged(NetworkLibrary* cros) { + const chromeos::VirtualNetwork* virt = GetVirtualNetwork(cros); + if (!virt) { + // The network hasn't been added to the NetworkLibrary's list yet, + // just continue waiting for more network events. + return; + } + + if (virt->failed()) { + if (automation_) { + scoped_ptr<DictionaryValue> return_value(new DictionaryValue); + return_value->SetString("error_string", virt->GetErrorString()); + AutomationJSONReply(automation_, reply_message_.release()) + .SendSuccess(return_value.get()); + } + delete this; + } else if (virt->connected()) { + if (automation_) + AutomationJSONReply(automation_, + reply_message_.release()).SendSuccess(NULL); + delete this; + } + // The network is in the NetworkLibrary's list, but there's no failure or + // success condition, so just continue waiting for more network events. +} + +chromeos::VirtualNetwork* VirtualConnectObserver::GetVirtualNetwork( + const chromeos::NetworkLibrary* cros) { + chromeos::VirtualNetwork* virt = NULL; + const chromeos::VirtualNetworkVector& virtual_networks = + cros->virtual_networks(); + + for (chromeos::VirtualNetworkVector::const_iterator iter = + virtual_networks.begin(); iter != virtual_networks.end(); ++iter) { + chromeos::VirtualNetwork* v = *iter; + if (v->name() == service_name_) { + virt = v; + break; + } + } + return virt; +} + SSIDConnectObserver::SSIDConnectObserver( AutomationProvider* automation, IPC::Message* reply_message, const std::string& ssid) |