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 "base/time.h" |
9 #include "base/values.h" | 10 #include "base/values.h" |
10 #include "chrome/browser/chromeos/cros/cros_library.h" | 11 #include "chrome/browser/chromeos/cros/cros_library.h" |
11 #include "chrome/browser/chromeos/login/base_login_display_host.h" | 12 #include "chrome/browser/chromeos/login/base_login_display_host.h" |
12 #include "chrome/browser/chromeos/login/login_display_host.h" | 13 #include "chrome/browser/chromeos/login/login_display_host.h" |
13 #include "chrome/browser/ui/webui/web_ui_util.h" | 14 #include "chrome/browser/ui/webui/web_ui_util.h" |
14 #include "content/public/browser/web_ui.h" | 15 #include "content/public/browser/web_ui.h" |
15 #include "ui/base/models/menu_model.h" | 16 #include "ui/base/models/menu_model.h" |
16 #include "ui/gfx/font.h" | 17 #include "ui/gfx/font.h" |
17 #include "ui/gfx/image/image_skia.h" | 18 #include "ui/gfx/image/image_skia.h" |
18 | 19 |
| 20 namespace { |
| 21 |
| 22 // Timeout between consecutive requests to network library for network |
| 23 // scan. |
| 24 const int kNetworkScanIntervalSecs = 60; |
| 25 |
| 26 } // namespace |
| 27 |
19 namespace chromeos { | 28 namespace chromeos { |
20 | 29 |
21 // WebUI specific implementation of the NetworkMenu class. | 30 // WebUI specific implementation of the NetworkMenu class. |
22 class NetworkMenuWebUI : public NetworkMenu { | 31 class NetworkMenuWebUI : public NetworkMenu { |
23 public: | 32 public: |
24 NetworkMenuWebUI(NetworkMenu::Delegate* delegate, content::WebUI* web_ui); | 33 NetworkMenuWebUI(NetworkMenu::Delegate* delegate, content::WebUI* web_ui); |
25 | 34 |
26 // NetworkMenu override: | 35 // NetworkMenu override: |
27 virtual void UpdateMenu() OVERRIDE; | 36 virtual void UpdateMenu() OVERRIDE; |
28 | 37 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 NetworkDropdown::NetworkDropdown(content::WebUI* web_ui, | 109 NetworkDropdown::NetworkDropdown(content::WebUI* web_ui, |
101 bool oobe) | 110 bool oobe) |
102 : web_ui_(web_ui), | 111 : web_ui_(web_ui), |
103 oobe_(oobe) { | 112 oobe_(oobe) { |
104 network_menu_.reset(new NetworkMenuWebUI(this, web_ui)); | 113 network_menu_.reset(new NetworkMenuWebUI(this, web_ui)); |
105 network_icon_.reset( | 114 network_icon_.reset( |
106 new NetworkMenuIcon(this, NetworkMenuIcon::DROPDOWN_MODE)); | 115 new NetworkMenuIcon(this, NetworkMenuIcon::DROPDOWN_MODE)); |
107 CrosLibrary::Get()->GetNetworkLibrary()->AddNetworkManagerObserver(this); | 116 CrosLibrary::Get()->GetNetworkLibrary()->AddNetworkManagerObserver(this); |
108 CrosLibrary::Get()->GetNetworkLibrary()->RequestNetworkScan(); | 117 CrosLibrary::Get()->GetNetworkLibrary()->RequestNetworkScan(); |
109 Refresh(); | 118 Refresh(); |
| 119 network_scan_timer_.Start(FROM_HERE, |
| 120 base::TimeDelta::FromSeconds(kNetworkScanIntervalSecs), |
| 121 this, &NetworkDropdown::ForceNetworkScan); |
110 } | 122 } |
111 | 123 |
112 NetworkDropdown::~NetworkDropdown() { | 124 NetworkDropdown::~NetworkDropdown() { |
113 CrosLibrary::Get()->GetNetworkLibrary()->RemoveNetworkManagerObserver(this); | 125 CrosLibrary::Get()->GetNetworkLibrary()->RemoveNetworkManagerObserver(this); |
114 } | 126 } |
115 | 127 |
116 void NetworkDropdown::SetLastNetworkType(ConnectionType last_network_type) { | 128 void NetworkDropdown::SetLastNetworkType(ConnectionType last_network_type) { |
117 network_icon_->set_last_network_type(last_network_type); | 129 network_icon_->set_last_network_type(last_network_type); |
118 } | 130 } |
119 | 131 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 ui::GetScaleFactorFromScale(web_ui_->GetDeviceScale())).sk_bitmap(); | 165 ui::GetScaleFactorFromScale(web_ui_->GetDeviceScale())).sk_bitmap(); |
154 std::string icon_str = | 166 std::string icon_str = |
155 icon_image.empty() ? | 167 icon_image.empty() ? |
156 std::string() : web_ui_util::GetImageDataUrl(icon_bitmap); | 168 std::string() : web_ui_util::GetImageDataUrl(icon_bitmap); |
157 base::StringValue title(text); | 169 base::StringValue title(text); |
158 base::StringValue icon(icon_str); | 170 base::StringValue icon(icon_str); |
159 web_ui_->CallJavascriptFunction("cr.ui.DropDown.updateNetworkTitle", | 171 web_ui_->CallJavascriptFunction("cr.ui.DropDown.updateNetworkTitle", |
160 title, icon); | 172 title, icon); |
161 } | 173 } |
162 | 174 |
| 175 void NetworkDropdown::ForceNetworkScan() { |
| 176 CrosLibrary::Get()->GetNetworkLibrary()->RequestNetworkScan(); |
| 177 Refresh(); |
| 178 } |
| 179 |
163 } // namespace chromeos | 180 } // namespace chromeos |
OLD | NEW |