| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/network_dropdown.h" | 5 #include "chrome/browser/ui/webui/chromeos/login/network_dropdown.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "ash/system/chromeos/network/network_icon.h" |
| 10 #include "ash/system/chromeos/network/network_icon_animation.h" |
| 9 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 10 #include "base/values.h" | 12 #include "base/values.h" |
| 11 #include "chrome/browser/chromeos/login/ui/login_display_host.h" | 13 #include "chrome/browser/chromeos/login/ui/login_display_host.h" |
| 12 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" | 14 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" |
| 13 #include "chromeos/network/network_state_handler.h" | 15 #include "chromeos/network/network_state_handler.h" |
| 14 #include "content/public/browser/web_ui.h" | 16 #include "content/public/browser/web_ui.h" |
| 15 #include "ui/base/models/menu_model.h" | 17 #include "ui/base/models/menu_model.h" |
| 16 #include "ui/base/webui/web_ui_util.h" | 18 #include "ui/base/webui/web_ui_util.h" |
| 17 #include "ui/chromeos/network/network_icon.h" | |
| 18 #include "ui/chromeos/network/network_icon_animation.h" | |
| 19 #include "ui/gfx/font_list.h" | 19 #include "ui/gfx/font_list.h" |
| 20 #include "ui/gfx/image/image.h" | 20 #include "ui/gfx/image/image.h" |
| 21 #include "ui/gfx/image/image_skia.h" | 21 #include "ui/gfx/image/image_skia.h" |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 // Timeout between consecutive requests to network library for network | 25 // Timeout between consecutive requests to network library for network |
| 26 // scan. | 26 // scan. |
| 27 const int kNetworkScanIntervalSecs = 60; | 27 const int kNetworkScanIntervalSecs = 60; |
| 28 | 28 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 handler->RequestScan(); | 121 handler->RequestScan(); |
| 122 handler->AddObserver(this, FROM_HERE); | 122 handler->AddObserver(this, FROM_HERE); |
| 123 Refresh(); | 123 Refresh(); |
| 124 network_scan_timer_.Start( | 124 network_scan_timer_.Start( |
| 125 FROM_HERE, | 125 FROM_HERE, |
| 126 base::TimeDelta::FromSeconds(kNetworkScanIntervalSecs), | 126 base::TimeDelta::FromSeconds(kNetworkScanIntervalSecs), |
| 127 this, &NetworkDropdown::RequestNetworkScan); | 127 this, &NetworkDropdown::RequestNetworkScan); |
| 128 } | 128 } |
| 129 | 129 |
| 130 NetworkDropdown::~NetworkDropdown() { | 130 NetworkDropdown::~NetworkDropdown() { |
| 131 ui::network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); | 131 ash::network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); |
| 132 if (NetworkHandler::IsInitialized()) { | 132 if (NetworkHandler::IsInitialized()) { |
| 133 NetworkHandler::Get()->network_state_handler()->RemoveObserver( | 133 NetworkHandler::Get()->network_state_handler()->RemoveObserver( |
| 134 this, FROM_HERE); | 134 this, FROM_HERE); |
| 135 } | 135 } |
| 136 } | 136 } |
| 137 | 137 |
| 138 void NetworkDropdown::OnItemChosen(int id) { | 138 void NetworkDropdown::OnItemChosen(int id) { |
| 139 network_menu_->OnItemChosen(id); | 139 network_menu_->OnItemChosen(id); |
| 140 } | 140 } |
| 141 | 141 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 | 175 |
| 176 void NetworkDropdown::Refresh() { | 176 void NetworkDropdown::Refresh() { |
| 177 SetNetworkIconAndText(); | 177 SetNetworkIconAndText(); |
| 178 network_menu_->UpdateMenu(); | 178 network_menu_->UpdateMenu(); |
| 179 } | 179 } |
| 180 | 180 |
| 181 void NetworkDropdown::SetNetworkIconAndText() { | 181 void NetworkDropdown::SetNetworkIconAndText() { |
| 182 base::string16 text; | 182 base::string16 text; |
| 183 gfx::ImageSkia icon_image; | 183 gfx::ImageSkia icon_image; |
| 184 bool animating = false; | 184 bool animating = false; |
| 185 ui::network_icon::GetDefaultNetworkImageAndLabel( | 185 ash::network_icon::GetDefaultNetworkImageAndLabel( |
| 186 ui::network_icon::ICON_TYPE_LIST, &icon_image, &text, &animating); | 186 ash::network_icon::ICON_TYPE_LIST, &icon_image, &text, &animating); |
| 187 if (animating) { | 187 if (animating) { |
| 188 ui::network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); | 188 ash::network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); |
| 189 } else { | 189 } else { |
| 190 ui::network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); | 190 ash::network_icon::NetworkIconAnimation::GetInstance()-> |
| 191 RemoveObserver(this); |
| 191 } | 192 } |
| 192 SkBitmap icon_bitmap = icon_image.GetRepresentation( | 193 SkBitmap icon_bitmap = icon_image.GetRepresentation( |
| 193 web_ui_->GetDeviceScaleFactor()).sk_bitmap(); | 194 web_ui_->GetDeviceScaleFactor()).sk_bitmap(); |
| 194 std::string icon_str; | 195 std::string icon_str; |
| 195 if (!icon_image.isNull()) | 196 if (!icon_image.isNull()) |
| 196 icon_str = webui::GetBitmapDataUrl(icon_bitmap); | 197 icon_str = webui::GetBitmapDataUrl(icon_bitmap); |
| 197 base::StringValue title(text); | 198 base::StringValue title(text); |
| 198 base::StringValue icon(icon_str); | 199 base::StringValue icon(icon_str); |
| 199 web_ui_->CallJavascriptFunction("cr.ui.DropDown.updateNetworkTitle", | 200 web_ui_->CallJavascriptFunction("cr.ui.DropDown.updateNetworkTitle", |
| 200 title, icon); | 201 title, icon); |
| 201 } | 202 } |
| 202 | 203 |
| 203 void NetworkDropdown::RequestNetworkScan() { | 204 void NetworkDropdown::RequestNetworkScan() { |
| 204 NetworkHandler::Get()->network_state_handler()->RequestScan(); | 205 NetworkHandler::Get()->network_state_handler()->RequestScan(); |
| 205 Refresh(); | 206 Refresh(); |
| 206 } | 207 } |
| 207 | 208 |
| 208 } // namespace chromeos | 209 } // namespace chromeos |
| OLD | NEW |