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 | 18 |
| 19 namespace { |
| 20 |
| 21 // Timeout between consecutive requests to network library for network |
| 22 // scan. |
| 23 const int kNetworkScanIntervalSecs = 60; |
| 24 |
| 25 } // namespace |
| 26 |
18 namespace chromeos { | 27 namespace chromeos { |
19 | 28 |
20 // WebUI specific implementation of the NetworkMenu class. | 29 // WebUI specific implementation of the NetworkMenu class. |
21 class NetworkMenuWebUI : public NetworkMenu { | 30 class NetworkMenuWebUI : public NetworkMenu { |
22 public: | 31 public: |
23 NetworkMenuWebUI(NetworkMenu::Delegate* delegate, content::WebUI* web_ui); | 32 NetworkMenuWebUI(NetworkMenu::Delegate* delegate, content::WebUI* web_ui); |
24 | 33 |
25 // NetworkMenu override: | 34 // NetworkMenu override: |
26 virtual void UpdateMenu() OVERRIDE; | 35 virtual void UpdateMenu() OVERRIDE; |
27 | 36 |
(...skipping 72 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 web_ui_->GetDeviceScale(), &icon_scale); | 171 web_ui_->GetDeviceScale(), &icon_scale); |
160 std::string icon_str = | 172 std::string icon_str = |
161 icon_image.empty() ? | 173 icon_image.empty() ? |
162 std::string() : web_ui_util::GetImageDataUrl(icon_bitmap); | 174 std::string() : web_ui_util::GetImageDataUrl(icon_bitmap); |
163 base::StringValue title(text); | 175 base::StringValue title(text); |
164 base::StringValue icon(icon_str); | 176 base::StringValue icon(icon_str); |
165 web_ui_->CallJavascriptFunction("cr.ui.DropDown.updateNetworkTitle", | 177 web_ui_->CallJavascriptFunction("cr.ui.DropDown.updateNetworkTitle", |
166 title, icon); | 178 title, icon); |
167 } | 179 } |
168 | 180 |
| 181 void NetworkDropdown::ForceNetworkScan() { |
| 182 CrosLibrary::Get()->GetNetworkLibrary()->RequestNetworkScan(); |
| 183 Refresh(); |
| 184 } |
| 185 |
169 } // namespace chromeos | 186 } // namespace chromeos |
OLD | NEW |