Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" | 5 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/hash_tables.h" | 10 #include "base/hash_tables.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 public: | 98 public: |
| 99 explicit NetworkStateInformer(WebUI* web_ui); | 99 explicit NetworkStateInformer(WebUI* web_ui); |
| 100 virtual ~NetworkStateInformer(); | 100 virtual ~NetworkStateInformer(); |
| 101 | 101 |
| 102 // Adds observer's callback to be called when network state has been changed. | 102 // Adds observer's callback to be called when network state has been changed. |
| 103 void AddObserver(const std::string& callback); | 103 void AddObserver(const std::string& callback); |
| 104 | 104 |
| 105 // Removes observer's callback. | 105 // Removes observer's callback. |
| 106 void RemoveObserver(const std::string& callback); | 106 void RemoveObserver(const std::string& callback); |
| 107 | 107 |
| 108 // Sends current network state, network name and reason using the callback. | 108 // Sends current network state, network name, reason and last network type |
| 109 // using the callback. | |
| 109 void SendState(const std::string& callback, const std::string& reason); | 110 void SendState(const std::string& callback, const std::string& reason); |
| 110 | 111 |
| 111 // NetworkLibrary::NetworkManagerObserver implementation: | 112 // NetworkLibrary::NetworkManagerObserver implementation: |
| 112 virtual void OnNetworkManagerChanged(chromeos::NetworkLibrary* cros) OVERRIDE; | 113 virtual void OnNetworkManagerChanged(chromeos::NetworkLibrary* cros) OVERRIDE; |
| 113 | 114 |
| 114 // content::NotificationObserver implementation. | 115 // content::NotificationObserver implementation. |
| 115 virtual void Observe(int type, | 116 virtual void Observe(int type, |
| 116 const content::NotificationSource& source, | 117 const content::NotificationSource& source, |
| 117 const content::NotificationDetails& details) OVERRIDE; | 118 const content::NotificationDetails& details) OVERRIDE; |
| 118 private: | 119 private: |
| 119 enum State {OFFLINE, ONLINE, CAPTIVE_PORTAL}; | 120 enum State {OFFLINE, ONLINE, CAPTIVE_PORTAL}; |
| 120 | 121 |
| 121 bool UpdateState(chromeos::NetworkLibrary* cros); | 122 bool UpdateState(chromeos::NetworkLibrary* cros); |
| 122 | 123 |
| 123 void SendStateToObservers(const std::string& reason); | 124 void SendStateToObservers(const std::string& reason); |
| 124 | 125 |
| 125 content::NotificationRegistrar registrar_; | 126 content::NotificationRegistrar registrar_; |
| 126 base::hash_set<std::string> observers_; | 127 base::hash_set<std::string> observers_; |
| 127 std::string active_network_; | 128 std::string active_network_; |
| 129 ConnectionType last_network_type_; | |
| 128 std::string network_name_; | 130 std::string network_name_; |
| 129 State state_; | 131 State state_; |
| 130 WebUI* web_ui_; | 132 WebUI* web_ui_; |
| 131 }; | 133 }; |
| 132 | 134 |
| 133 // NetworkStateInformer implementation ----------------------------------------- | 135 // NetworkStateInformer implementation ----------------------------------------- |
| 134 | 136 |
| 135 NetworkStateInformer::NetworkStateInformer(WebUI* web_ui) : web_ui_(web_ui) { | 137 NetworkStateInformer::NetworkStateInformer(WebUI* web_ui) |
| 138 : last_network_type_(TYPE_WIFI), web_ui_(web_ui) { | |
|
whywhat
2011/11/29 07:58:06
Initialize each member on its own line, please.
I'
altimofeev
2011/11/29 17:10:46
Done.
| |
| 136 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); | 139 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); |
| 137 UpdateState(cros); | 140 UpdateState(cros); |
| 138 cros->AddNetworkManagerObserver(this); | 141 cros->AddNetworkManagerObserver(this); |
| 139 registrar_.Add(this, | 142 registrar_.Add(this, |
| 140 chrome::NOTIFICATION_LOGIN_PROXY_CHANGED, | 143 chrome::NOTIFICATION_LOGIN_PROXY_CHANGED, |
| 141 content::NotificationService::AllSources()); | 144 content::NotificationService::AllSources()); |
| 142 } | 145 } |
| 143 | 146 |
| 144 NetworkStateInformer::~NetworkStateInformer() { | 147 NetworkStateInformer::~NetworkStateInformer() { |
| 145 CrosLibrary::Get()->GetNetworkLibrary()-> | 148 CrosLibrary::Get()->GetNetworkLibrary()-> |
| 146 RemoveNetworkManagerObserver(this); | 149 RemoveNetworkManagerObserver(this); |
| 147 } | 150 } |
| 148 | 151 |
| 149 void NetworkStateInformer::AddObserver(const std::string& callback) { | 152 void NetworkStateInformer::AddObserver(const std::string& callback) { |
| 150 observers_.insert(callback); | 153 observers_.insert(callback); |
| 151 } | 154 } |
| 152 | 155 |
| 153 void NetworkStateInformer::RemoveObserver(const std::string& callback) { | 156 void NetworkStateInformer::RemoveObserver(const std::string& callback) { |
| 154 observers_.erase(callback); | 157 observers_.erase(callback); |
| 155 } | 158 } |
| 156 | 159 |
| 157 void NetworkStateInformer::SendState(const std::string& callback, | 160 void NetworkStateInformer::SendState(const std::string& callback, |
| 158 const std::string& reason) { | 161 const std::string& reason) { |
| 159 base::FundamentalValue state_value(state_); | 162 base::FundamentalValue state_value(state_); |
| 160 base::StringValue network_value(network_name_); | 163 base::StringValue network_value(network_name_); |
| 161 base::StringValue reason_value(reason); | 164 base::StringValue reason_value(reason); |
| 162 web_ui_->CallJavascriptFunction(callback, state_value, | 165 base::FundamentalValue last_network_value(last_network_type_); |
| 163 network_value, reason_value); | 166 web_ui_->CallJavascriptFunction(callback, state_value, network_value, |
| 167 reason_value, last_network_value); | |
| 164 } | 168 } |
| 165 | 169 |
| 166 void NetworkStateInformer::OnNetworkManagerChanged(NetworkLibrary* cros) { | 170 void NetworkStateInformer::OnNetworkManagerChanged(NetworkLibrary* cros) { |
| 167 if (UpdateState(cros)) { | 171 if (UpdateState(cros)) { |
| 168 SendStateToObservers(kReasonNetworkChanged); | 172 SendStateToObservers(kReasonNetworkChanged); |
| 169 } | 173 } |
| 170 } | 174 } |
| 171 | 175 |
| 172 void NetworkStateInformer::Observe( | 176 void NetworkStateInformer::Observe( |
| 173 int type, | 177 int type, |
| 174 const content::NotificationSource& source, | 178 const content::NotificationSource& source, |
| 175 const content::NotificationDetails& details) { | 179 const content::NotificationDetails& details) { |
| 176 DCHECK(type == chrome::NOTIFICATION_LOGIN_PROXY_CHANGED); | 180 DCHECK(type == chrome::NOTIFICATION_LOGIN_PROXY_CHANGED); |
| 177 SendStateToObservers(kReasonProxyChanged); | 181 SendStateToObservers(kReasonProxyChanged); |
| 178 } | 182 } |
| 179 | 183 |
| 180 bool NetworkStateInformer::UpdateState(NetworkLibrary* cros) { | 184 bool NetworkStateInformer::UpdateState(NetworkLibrary* cros) { |
| 185 if (cros->active_network()) | |
| 186 last_network_type_ = cros->active_network()->type(); | |
| 187 | |
| 181 State new_state; | 188 State new_state; |
| 182 std::string new_active_network; | 189 std::string new_active_network; |
| 183 if (!cros->Connected()) { | 190 if (!cros->Connected()) { |
| 184 new_state = OFFLINE; | 191 new_state = OFFLINE; |
| 185 network_name_.clear(); | 192 network_name_.clear(); |
| 186 } else { | 193 } else { |
| 187 const Network* active_network = cros->active_network(); | 194 const Network* active_network = cros->active_network(); |
| 188 if (active_network) { | 195 if (active_network) { |
| 189 new_active_network = active_network->unique_id(); | 196 new_active_network = active_network->unique_id(); |
| 190 network_name_ = active_network->name(); | 197 network_name_ = active_network->name(); |
| (...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 731 | 738 |
| 732 cookie_remover_ = new BrowsingDataRemover( | 739 cookie_remover_ = new BrowsingDataRemover( |
| 733 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context()), | 740 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context()), |
| 734 BrowsingDataRemover::EVERYTHING, | 741 BrowsingDataRemover::EVERYTHING, |
| 735 base::Time()); | 742 base::Time()); |
| 736 cookie_remover_->AddObserver(this); | 743 cookie_remover_->AddObserver(this); |
| 737 cookie_remover_->Remove(BrowsingDataRemover::REMOVE_SITE_DATA); | 744 cookie_remover_->Remove(BrowsingDataRemover::REMOVE_SITE_DATA); |
| 738 } | 745 } |
| 739 | 746 |
| 740 } // namespace chromeos | 747 } // namespace chromeos |
| OLD | NEW |