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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 NetworkDropdown::NetworkDropdown(content::WebUI* web_ui, | 105 NetworkDropdown::NetworkDropdown(content::WebUI* web_ui, |
97 bool oobe) | 106 bool oobe) |
98 : web_ui_(web_ui), | 107 : web_ui_(web_ui), |
99 oobe_(oobe) { | 108 oobe_(oobe) { |
100 network_menu_.reset(new NetworkMenuWebUI(this, web_ui)); | 109 network_menu_.reset(new NetworkMenuWebUI(this, web_ui)); |
101 network_icon_.reset( | 110 network_icon_.reset( |
102 new NetworkMenuIcon(this, NetworkMenuIcon::DROPDOWN_MODE)); | 111 new NetworkMenuIcon(this, NetworkMenuIcon::DROPDOWN_MODE)); |
103 CrosLibrary::Get()->GetNetworkLibrary()->AddNetworkManagerObserver(this); | 112 CrosLibrary::Get()->GetNetworkLibrary()->AddNetworkManagerObserver(this); |
104 CrosLibrary::Get()->GetNetworkLibrary()->RequestNetworkScan(); | 113 CrosLibrary::Get()->GetNetworkLibrary()->RequestNetworkScan(); |
105 Refresh(); | 114 Refresh(); |
| 115 network_scan_timer_.Start(FROM_HERE, |
| 116 base::TimeDelta::FromSeconds(kNetworkScanIntervalSecs), |
| 117 this, &NetworkDropdown::ForceNetworkScan); |
106 } | 118 } |
107 | 119 |
108 NetworkDropdown::~NetworkDropdown() { | 120 NetworkDropdown::~NetworkDropdown() { |
109 CrosLibrary::Get()->GetNetworkLibrary()->RemoveNetworkManagerObserver(this); | 121 CrosLibrary::Get()->GetNetworkLibrary()->RemoveNetworkManagerObserver(this); |
110 } | 122 } |
111 | 123 |
112 void NetworkDropdown::SetLastNetworkType(ConnectionType last_network_type) { | 124 void NetworkDropdown::SetLastNetworkType(ConnectionType last_network_type) { |
113 network_icon_->set_last_network_type(last_network_type); | 125 network_icon_->set_last_network_type(last_network_type); |
114 } | 126 } |
115 | 127 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 const SkBitmap icon_bitmap = network_icon_->GetIconAndText(&text); | 164 const SkBitmap icon_bitmap = network_icon_->GetIconAndText(&text); |
153 std::string icon_str = | 165 std::string icon_str = |
154 icon_bitmap.empty() ? | 166 icon_bitmap.empty() ? |
155 std::string() : web_ui_util::GetImageDataUrl(icon_bitmap); | 167 std::string() : web_ui_util::GetImageDataUrl(icon_bitmap); |
156 base::StringValue title(text); | 168 base::StringValue title(text); |
157 base::StringValue icon(icon_str); | 169 base::StringValue icon(icon_str); |
158 web_ui_->CallJavascriptFunction("cr.ui.DropDown.updateNetworkTitle", | 170 web_ui_->CallJavascriptFunction("cr.ui.DropDown.updateNetworkTitle", |
159 title, icon); | 171 title, icon); |
160 } | 172 } |
161 | 173 |
| 174 void NetworkDropdown::ForceNetworkScan() { |
| 175 CrosLibrary::Get()->GetNetworkLibrary()->RequestNetworkScan(); |
| 176 Refresh(); |
| 177 } |
| 178 |
162 } // namespace chromeos | 179 } // namespace chromeos |
OLD | NEW |