| 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 <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "ash/common/system/chromeos/network/network_icon.h" |
| 12 #include "ash/common/system/chromeos/network/network_icon_animation.h" |
| 11 #include "base/macros.h" | 13 #include "base/macros.h" |
| 12 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 13 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 16 #include "base/values.h" | 18 #include "base/values.h" |
| 17 #include "chrome/browser/chromeos/login/ui/login_display_host.h" | 19 #include "chrome/browser/chromeos/login/ui/login_display_host.h" |
| 18 #include "chromeos/network/network_state_handler.h" | 20 #include "chromeos/network/network_state_handler.h" |
| 19 #include "content/public/browser/web_ui.h" | 21 #include "content/public/browser/web_ui.h" |
| 20 #include "ui/base/models/menu_model.h" | 22 #include "ui/base/models/menu_model.h" |
| 21 #include "ui/base/webui/web_ui_util.h" | 23 #include "ui/base/webui/web_ui_util.h" |
| 22 #include "ui/chromeos/network/network_icon.h" | |
| 23 #include "ui/chromeos/network/network_icon_animation.h" | |
| 24 #include "ui/gfx/font_list.h" | 24 #include "ui/gfx/font_list.h" |
| 25 #include "ui/gfx/image/image.h" | 25 #include "ui/gfx/image/image.h" |
| 26 #include "ui/gfx/image/image_skia.h" | 26 #include "ui/gfx/image/image_skia.h" |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 // Timeout between consecutive requests to network library for network | 30 // Timeout between consecutive requests to network library for network |
| 31 // scan. | 31 // scan. |
| 32 const int kNetworkScanIntervalSecs = 60; | 32 const int kNetworkScanIntervalSecs = 60; |
| 33 | 33 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 handler->RequestScan(); | 131 handler->RequestScan(); |
| 132 handler->AddObserver(this, FROM_HERE); | 132 handler->AddObserver(this, FROM_HERE); |
| 133 Refresh(); | 133 Refresh(); |
| 134 network_scan_timer_.Start( | 134 network_scan_timer_.Start( |
| 135 FROM_HERE, | 135 FROM_HERE, |
| 136 base::TimeDelta::FromSeconds(kNetworkScanIntervalSecs), | 136 base::TimeDelta::FromSeconds(kNetworkScanIntervalSecs), |
| 137 this, &NetworkDropdown::RequestNetworkScan); | 137 this, &NetworkDropdown::RequestNetworkScan); |
| 138 } | 138 } |
| 139 | 139 |
| 140 NetworkDropdown::~NetworkDropdown() { | 140 NetworkDropdown::~NetworkDropdown() { |
| 141 ui::network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); | 141 ash::network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); |
| 142 if (NetworkHandler::IsInitialized()) { | 142 if (NetworkHandler::IsInitialized()) { |
| 143 NetworkHandler::Get()->network_state_handler()->RemoveObserver( | 143 NetworkHandler::Get()->network_state_handler()->RemoveObserver( |
| 144 this, FROM_HERE); | 144 this, FROM_HERE); |
| 145 } | 145 } |
| 146 } | 146 } |
| 147 | 147 |
| 148 void NetworkDropdown::OnItemChosen(int id) { | 148 void NetworkDropdown::OnItemChosen(int id) { |
| 149 network_menu_->OnItemChosen(id); | 149 network_menu_->OnItemChosen(id); |
| 150 } | 150 } |
| 151 | 151 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 | 184 |
| 185 void NetworkDropdown::Refresh() { | 185 void NetworkDropdown::Refresh() { |
| 186 SetNetworkIconAndText(); | 186 SetNetworkIconAndText(); |
| 187 network_menu_->UpdateMenu(); | 187 network_menu_->UpdateMenu(); |
| 188 } | 188 } |
| 189 | 189 |
| 190 void NetworkDropdown::SetNetworkIconAndText() { | 190 void NetworkDropdown::SetNetworkIconAndText() { |
| 191 base::string16 text; | 191 base::string16 text; |
| 192 gfx::ImageSkia icon_image; | 192 gfx::ImageSkia icon_image; |
| 193 bool animating = false; | 193 bool animating = false; |
| 194 ui::network_icon::GetDefaultNetworkImageAndLabel( | 194 ash::network_icon::GetDefaultNetworkImageAndLabel( |
| 195 ui::network_icon::ICON_TYPE_LIST, &icon_image, &text, &animating); | 195 ash::network_icon::ICON_TYPE_LIST, &icon_image, &text, &animating); |
| 196 if (animating) { | 196 if (animating) { |
| 197 ui::network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); | 197 ash::network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); |
| 198 } else { | 198 } else { |
| 199 ui::network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); | 199 ash::network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver( |
| 200 this); |
| 200 } | 201 } |
| 201 SkBitmap icon_bitmap = icon_image.GetRepresentation( | 202 SkBitmap icon_bitmap = icon_image.GetRepresentation( |
| 202 web_ui_->GetDeviceScaleFactor()).sk_bitmap(); | 203 web_ui_->GetDeviceScaleFactor()).sk_bitmap(); |
| 203 std::string icon_str; | 204 std::string icon_str; |
| 204 if (!icon_image.isNull()) | 205 if (!icon_image.isNull()) |
| 205 icon_str = webui::GetBitmapDataUrl(icon_bitmap); | 206 icon_str = webui::GetBitmapDataUrl(icon_bitmap); |
| 206 base::StringValue title(text); | 207 base::StringValue title(text); |
| 207 base::StringValue icon(icon_str); | 208 base::StringValue icon(icon_str); |
| 208 web_ui_->CallJavascriptFunctionUnsafe("cr.ui.DropDown.updateNetworkTitle", | 209 web_ui_->CallJavascriptFunctionUnsafe("cr.ui.DropDown.updateNetworkTitle", |
| 209 title, icon); | 210 title, icon); |
| 210 } | 211 } |
| 211 | 212 |
| 212 void NetworkDropdown::RequestNetworkScan() { | 213 void NetworkDropdown::RequestNetworkScan() { |
| 213 NetworkHandler::Get()->network_state_handler()->RequestScan(); | 214 NetworkHandler::Get()->network_state_handler()->RequestScan(); |
| 214 Refresh(); | 215 Refresh(); |
| 215 } | 216 } |
| 216 | 217 |
| 217 } // namespace chromeos | 218 } // namespace chromeos |
| OLD | NEW |