Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(497)

Side by Side Diff: chrome/browser/chromeos/status/network_menu.cc

Issue 105193002: Replace string16 with base::string16. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/chromeos/status/network_menu.h" 5 #include "chrome/browser/chromeos/status/network_menu.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/shell_delegate.h" 10 #include "ash/shell_delegate.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 } // namespace 69 } // namespace
70 70
71 class NetworkMenuModel : public ui::MenuModel { 71 class NetworkMenuModel : public ui::MenuModel {
72 public: 72 public:
73 struct MenuItem { 73 struct MenuItem {
74 MenuItem() 74 MenuItem()
75 : type(ui::MenuModel::TYPE_SEPARATOR), 75 : type(ui::MenuModel::TYPE_SEPARATOR),
76 sub_menu_model(NULL), 76 sub_menu_model(NULL),
77 flags(0) { 77 flags(0) {
78 } 78 }
79 MenuItem(ui::MenuModel::ItemType type, string16 label, gfx::ImageSkia icon, 79 MenuItem(ui::MenuModel::ItemType type, base::string16 label, gfx::ImageSkia icon,
80 const std::string& service_path, int flags) 80 const std::string& service_path, int flags)
81 : type(type), 81 : type(type),
82 label(label), 82 label(label),
83 icon(icon), 83 icon(icon),
84 service_path(service_path), 84 service_path(service_path),
85 sub_menu_model(NULL), 85 sub_menu_model(NULL),
86 flags(flags) { 86 flags(flags) {
87 } 87 }
88 MenuItem(ui::MenuModel::ItemType type, string16 label, gfx::ImageSkia icon, 88 MenuItem(ui::MenuModel::ItemType type, base::string16 label, gfx::ImageSkia icon,
89 NetworkMenuModel* sub_menu_model, int flags) 89 NetworkMenuModel* sub_menu_model, int flags)
90 : type(type), 90 : type(type),
91 label(label), 91 label(label),
92 icon(icon), 92 icon(icon),
93 sub_menu_model(sub_menu_model), 93 sub_menu_model(sub_menu_model),
94 flags(flags) { 94 flags(flags) {
95 } 95 }
96 96
97 ui::MenuModel::ItemType type; 97 ui::MenuModel::ItemType type;
98 string16 label; 98 base::string16 label;
99 gfx::ImageSkia icon; 99 gfx::ImageSkia icon;
100 std::string service_path; 100 std::string service_path;
101 NetworkMenuModel* sub_menu_model; // Weak ptr. 101 NetworkMenuModel* sub_menu_model; // Weak ptr.
102 int flags; 102 int flags;
103 }; 103 };
104 typedef std::vector<MenuItem> MenuItemVector; 104 typedef std::vector<MenuItem> MenuItemVector;
105 105
106 explicit NetworkMenuModel(const base::WeakPtr<NetworkMenu>& owner) 106 explicit NetworkMenuModel(const base::WeakPtr<NetworkMenu>& owner)
107 : owner_(owner) {} 107 : owner_(owner) {}
108 virtual ~NetworkMenuModel() {} 108 virtual ~NetworkMenuModel() {}
109 109
110 // Connect or reconnect to the network at |index|. 110 // Connect or reconnect to the network at |index|.
111 void ConnectToNetworkAt(int index); 111 void ConnectToNetworkAt(int index);
112 112
113 // Called by NetworkMenu::UpdateMenu to initialize menu items. 113 // Called by NetworkMenu::UpdateMenu to initialize menu items.
114 virtual void InitMenuItems(bool should_open_button_options) = 0; 114 virtual void InitMenuItems(bool should_open_button_options) = 0;
115 115
116 // Menu item field accessors. 116 // Menu item field accessors.
117 const MenuItemVector& menu_items() const { return menu_items_; } 117 const MenuItemVector& menu_items() const { return menu_items_; }
118 118
119 // ui::MenuModel implementation 119 // ui::MenuModel implementation
120 // GetCommandIdAt() must be implemented by subclasses. 120 // GetCommandIdAt() must be implemented by subclasses.
121 virtual bool HasIcons() const OVERRIDE; 121 virtual bool HasIcons() const OVERRIDE;
122 virtual int GetItemCount() const OVERRIDE; 122 virtual int GetItemCount() const OVERRIDE;
123 virtual ui::MenuModel::ItemType GetTypeAt(int index) const OVERRIDE; 123 virtual ui::MenuModel::ItemType GetTypeAt(int index) const OVERRIDE;
124 virtual ui::MenuSeparatorType GetSeparatorTypeAt(int index) const OVERRIDE; 124 virtual ui::MenuSeparatorType GetSeparatorTypeAt(int index) const OVERRIDE;
125 virtual string16 GetLabelAt(int index) const OVERRIDE; 125 virtual base::string16 GetLabelAt(int index) const OVERRIDE;
126 virtual bool IsItemDynamicAt(int index) const OVERRIDE; 126 virtual bool IsItemDynamicAt(int index) const OVERRIDE;
127 virtual const gfx::Font* GetLabelFontAt(int index) const OVERRIDE; 127 virtual const gfx::Font* GetLabelFontAt(int index) const OVERRIDE;
128 virtual bool GetAcceleratorAt(int index, 128 virtual bool GetAcceleratorAt(int index,
129 ui::Accelerator* accelerator) const OVERRIDE; 129 ui::Accelerator* accelerator) const OVERRIDE;
130 virtual bool IsItemCheckedAt(int index) const OVERRIDE; 130 virtual bool IsItemCheckedAt(int index) const OVERRIDE;
131 virtual int GetGroupIdAt(int index) const OVERRIDE; 131 virtual int GetGroupIdAt(int index) const OVERRIDE;
132 virtual bool GetIconAt(int index, gfx::Image* icon) OVERRIDE; 132 virtual bool GetIconAt(int index, gfx::Image* icon) OVERRIDE;
133 virtual ui::ButtonMenuItemModel* GetButtonMenuItemAt( 133 virtual ui::ButtonMenuItemModel* GetButtonMenuItemAt(
134 int index) const OVERRIDE; 134 int index) const OVERRIDE;
135 virtual bool IsEnabledAt(int index) const OVERRIDE; 135 virtual bool IsEnabledAt(int index) const OVERRIDE;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 virtual ~MainMenuModel() {} 194 virtual ~MainMenuModel() {}
195 195
196 // NetworkMenuModel implementation. 196 // NetworkMenuModel implementation.
197 virtual void InitMenuItems(bool should_open_button_options) OVERRIDE; 197 virtual void InitMenuItems(bool should_open_button_options) OVERRIDE;
198 198
199 // ui::MenuModel implementation 199 // ui::MenuModel implementation
200 virtual int GetCommandIdAt(int index) const OVERRIDE; 200 virtual int GetCommandIdAt(int index) const OVERRIDE;
201 201
202 private: 202 private:
203 void AddWirelessNetworkMenuItem(const NetworkState* wifi_network, int flag); 203 void AddWirelessNetworkMenuItem(const NetworkState* wifi_network, int flag);
204 void AddMessageItem(const string16& msg); 204 void AddMessageItem(const base::string16& msg);
205 205
206 scoped_ptr<MoreMenuModel> more_menu_model_; 206 scoped_ptr<MoreMenuModel> more_menu_model_;
207 207
208 DISALLOW_COPY_AND_ASSIGN(MainMenuModel); 208 DISALLOW_COPY_AND_ASSIGN(MainMenuModel);
209 }; 209 };
210 210
211 //////////////////////////////////////////////////////////////////////////////// 211 ////////////////////////////////////////////////////////////////////////////////
212 // NetworkMenuModel, public methods: 212 // NetworkMenuModel, public methods:
213 213
214 void NetworkMenuModel::ConnectToNetworkAt(int index) { 214 void NetworkMenuModel::ConnectToNetworkAt(int index) {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 ChooseMobileNetworkDialog::ShowDialog(native_window); 339 ChooseMobileNetworkDialog::ShowDialog(native_window);
340 else 340 else
341 NetworkConfigView::ShowForType(shill::kTypeWifi, native_window); 341 NetworkConfigView::ShowForType(shill::kTypeWifi, native_window);
342 } 342 }
343 343
344 //////////////////////////////////////////////////////////////////////////////// 344 ////////////////////////////////////////////////////////////////////////////////
345 // MainMenuModel 345 // MainMenuModel
346 346
347 void MainMenuModel::AddWirelessNetworkMenuItem(const NetworkState* network, 347 void MainMenuModel::AddWirelessNetworkMenuItem(const NetworkState* network,
348 int flag) { 348 int flag) {
349 string16 label; 349 base::string16 label;
350 // Ampersand is a valid character in an SSID, but menu2 uses it to mark 350 // Ampersand is a valid character in an SSID, but menu2 uses it to mark
351 // "mnemonics" for keyboard shortcuts. 351 // "mnemonics" for keyboard shortcuts.
352 std::string wifi_name = EscapeAmpersands(network->name()); 352 std::string wifi_name = EscapeAmpersands(network->name());
353 if (network->IsConnectingState()) { 353 if (network->IsConnectingState()) {
354 label = l10n_util::GetStringFUTF16( 354 label = l10n_util::GetStringFUTF16(
355 IDS_STATUSBAR_NETWORK_DEVICE_STATUS, 355 IDS_STATUSBAR_NETWORK_DEVICE_STATUS,
356 UTF8ToUTF16(wifi_name), 356 UTF8ToUTF16(wifi_name),
357 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_CONNECTING)); 357 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_CONNECTING));
358 } else { 358 } else {
359 label = UTF8ToUTF16(wifi_name); 359 label = UTF8ToUTF16(wifi_name);
360 } 360 }
361 361
362 // We do not have convenient access to whether or not it might be possible 362 // We do not have convenient access to whether or not it might be possible
363 // to connect to a wireless network (e.g. whether certs are required), so all 363 // to connect to a wireless network (e.g. whether certs are required), so all
364 // entries are enabled. 364 // entries are enabled.
365 365
366 if (ShouldHighlightNetwork(network)) 366 if (ShouldHighlightNetwork(network))
367 flag |= FLAG_ASSOCIATED; 367 flag |= FLAG_ASSOCIATED;
368 const gfx::ImageSkia icon = ash::network_icon::GetImageForNetwork( 368 const gfx::ImageSkia icon = ash::network_icon::GetImageForNetwork(
369 network, ash::network_icon::ICON_TYPE_LIST); 369 network, ash::network_icon::ICON_TYPE_LIST);
370 menu_items_.push_back( 370 menu_items_.push_back(
371 MenuItem(ui::MenuModel::TYPE_COMMAND, 371 MenuItem(ui::MenuModel::TYPE_COMMAND,
372 label, icon, network->path(), flag)); 372 label, icon, network->path(), flag));
373 } 373 }
374 374
375 void MainMenuModel::AddMessageItem(const string16& msg) { 375 void MainMenuModel::AddMessageItem(const base::string16& msg) {
376 menu_items_.push_back(MenuItem( 376 menu_items_.push_back(MenuItem(
377 ui::MenuModel::TYPE_COMMAND, msg, 377 ui::MenuModel::TYPE_COMMAND, msg,
378 gfx::ImageSkia(), std::string(), FLAG_DISABLED)); 378 gfx::ImageSkia(), std::string(), FLAG_DISABLED));
379 } 379 }
380 380
381 void MainMenuModel::InitMenuItems(bool should_open_button_options) { 381 void MainMenuModel::InitMenuItems(bool should_open_button_options) {
382 menu_items_.clear(); 382 menu_items_.clear();
383 383
384 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); 384 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
385 385
386 // Populate our MenuItems with the current list of networks. 386 // Populate our MenuItems with the current list of networks.
387 string16 label; 387 base::string16 label;
388 388
389 // Ethernet 389 // Ethernet
390 // Only display an ethernet icon if enabled, and an ethernet network exists. 390 // Only display an ethernet icon if enabled, and an ethernet network exists.
391 bool ethernet_enabled = 391 bool ethernet_enabled =
392 handler->IsTechnologyEnabled(NetworkTypePattern::Ethernet()); 392 handler->IsTechnologyEnabled(NetworkTypePattern::Ethernet());
393 const NetworkState* ethernet_network = 393 const NetworkState* ethernet_network =
394 handler->FirstNetworkByType(NetworkTypePattern::Ethernet()); 394 handler->FirstNetworkByType(NetworkTypePattern::Ethernet());
395 if (ethernet_enabled && ethernet_network) { 395 if (ethernet_enabled && ethernet_network) {
396 bool ethernet_connecting = ethernet_network->IsConnectingState(); 396 bool ethernet_connecting = ethernet_network->IsConnectingState();
397 if (ethernet_connecting) { 397 if (ethernet_connecting) {
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 return main_menu_model_.get(); 674 return main_menu_model_.get();
675 } 675 }
676 676
677 void NetworkMenu::UpdateMenu() { 677 void NetworkMenu::UpdateMenu() {
678 refreshing_menu_ = true; 678 refreshing_menu_ = true;
679 main_menu_model_->InitMenuItems(delegate_->ShouldOpenButtonOptions()); 679 main_menu_model_->InitMenuItems(delegate_->ShouldOpenButtonOptions());
680 refreshing_menu_ = false; 680 refreshing_menu_ = false;
681 } 681 }
682 682
683 } // namespace chromeos 683 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/status/data_promo_notification.cc ('k') | chrome/browser/chromeos/system/ash_system_tray_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698