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

Side by Side Diff: ash/system/chromeos/network/tray_vpn.cc

Issue 14729017: Add NetworkHandler to own network handlers in src/chromeos/network (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 7 months 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 "ash/system/chromeos/network/tray_vpn.h" 5 #include "ash/system/chromeos/network/tray_vpn.h"
6 6
7 #include "ash/ash_switches.h" 7 #include "ash/ash_switches.h"
8 #include "ash/shell.h" 8 #include "ash/shell.h"
9 #include "ash/system/chromeos/network/network_icon_animation.h" 9 #include "ash/system/chromeos/network/network_icon_animation.h"
10 #include "ash/system/chromeos/network/network_list_detailed_view_base.h" 10 #include "ash/system/chromeos/network/network_list_detailed_view_base.h"
11 #include "ash/system/chromeos/network/network_state_list_detailed_view.h" 11 #include "ash/system/chromeos/network/network_state_list_detailed_view.h"
12 #include "ash/system/tray/system_tray.h" 12 #include "ash/system/tray/system_tray.h"
13 #include "ash/system/tray/system_tray_delegate.h" 13 #include "ash/system/tray/system_tray_delegate.h"
14 #include "ash/system/tray/system_tray_notifier.h" 14 #include "ash/system/tray/system_tray_notifier.h"
15 #include "ash/system/tray/tray_constants.h" 15 #include "ash/system/tray/tray_constants.h"
16 #include "ash/system/tray/tray_item_more.h" 16 #include "ash/system/tray/tray_item_more.h"
17 #include "ash/system/tray/tray_popup_label_button.h" 17 #include "ash/system/tray/tray_popup_label_button.h"
18 #include "base/command_line.h" 18 #include "base/command_line.h"
19 #include "chromeos/network/network_state.h" 19 #include "chromeos/network/network_state.h"
20 #include "chromeos/network/network_state_handler.h" 20 #include "chromeos/network/network_state_handler.h"
21 #include "grit/ash_strings.h" 21 #include "grit/ash_strings.h"
22 #include "third_party/cros_system_api/dbus/service_constants.h" 22 #include "third_party/cros_system_api/dbus/service_constants.h"
23 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
24 #include "ui/base/resource/resource_bundle.h" 24 #include "ui/base/resource/resource_bundle.h"
25 25
26 using chromeos::NetworkHandler;
26 using chromeos::NetworkState; 27 using chromeos::NetworkState;
27 using chromeos::NetworkStateHandler; 28 using chromeos::NetworkStateHandler;
28 29
29 namespace { 30 namespace {
30 31
31 bool UseNewNetworkHandlers() { 32 bool UseNewNetworkHandlers() {
32 return !CommandLine::ForCurrentProcess()->HasSwitch( 33 return !CommandLine::ForCurrentProcess()->HasSwitch(
33 ash::switches::kAshDisableNewNetworkStatusArea) && 34 ash::switches::kAshDisableNewNetworkStatusArea);
34 NetworkStateHandler::IsInitialized();
35 } 35 }
36 36
37 } 37 }
38 38
39 namespace ash { 39 namespace ash {
40 namespace internal { 40 namespace internal {
41 41
42 namespace tray { 42 namespace tray {
43 43
44 class VpnDefaultView : public TrayItemMore, 44 class VpnDefaultView : public TrayItemMore,
45 public network_icon::AnimationObserver { 45 public network_icon::AnimationObserver {
46 public: 46 public:
47 VpnDefaultView(SystemTrayItem* owner, bool show_more) 47 VpnDefaultView(SystemTrayItem* owner, bool show_more)
48 : TrayItemMore(owner, show_more) { 48 : TrayItemMore(owner, show_more) {
49 Update(); 49 Update();
50 } 50 }
51 51
52 virtual ~VpnDefaultView() { 52 virtual ~VpnDefaultView() {
53 if (UseNewNetworkHandlers()) 53 if (UseNewNetworkHandlers())
54 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); 54 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this);
55 } 55 }
56 56
57 static bool ShouldShow() { 57 static bool ShouldShow() {
58 // Do not show VPN line in uber tray bubble if VPN is not configured. 58 // Do not show VPN line in uber tray bubble if VPN is not configured.
59 if (UseNewNetworkHandlers()) { 59 if (UseNewNetworkHandlers()) {
60 NetworkStateHandler* handler = NetworkStateHandler::Get(); 60 NetworkStateHandler* handler =
61 NetworkHandler::Get()->network_state_handler();
61 const NetworkState* vpn = handler->FirstNetworkByType( 62 const NetworkState* vpn = handler->FirstNetworkByType(
62 flimflam::kTypeVPN); 63 flimflam::kTypeVPN);
63 return vpn != NULL; 64 return vpn != NULL;
64 } else { 65 } else {
65 std::vector<NetworkIconInfo> list; 66 std::vector<NetworkIconInfo> list;
66 Shell::GetInstance()->system_tray_delegate()->GetVirtualNetworks(&list); 67 Shell::GetInstance()->system_tray_delegate()->GetVirtualNetworks(&list);
67 return list.size() != 0; 68 return list.size() != 0;
68 } 69 }
69 } 70 }
70 71
(...skipping 22 matching lines...) Expand all
93 94
94 // network_icon::AnimationObserver 95 // network_icon::AnimationObserver
95 virtual void NetworkIconChanged() OVERRIDE { 96 virtual void NetworkIconChanged() OVERRIDE {
96 Update(); 97 Update();
97 } 98 }
98 99
99 private: 100 private:
100 void GetNetworkStateHandlerImageAndLabel(gfx::ImageSkia* image, 101 void GetNetworkStateHandlerImageAndLabel(gfx::ImageSkia* image,
101 base::string16* label, 102 base::string16* label,
102 bool* animating) { 103 bool* animating) {
103 NetworkStateHandler* handler = NetworkStateHandler::Get(); 104 NetworkStateHandler* handler =
105 NetworkHandler::Get()->network_state_handler();
104 const NetworkState* vpn = handler->FirstNetworkByType( 106 const NetworkState* vpn = handler->FirstNetworkByType(
105 flimflam::kTypeVPN); 107 flimflam::kTypeVPN);
106 if (!vpn || (vpn->connection_state() == flimflam::kStateIdle)) { 108 if (!vpn || (vpn->connection_state() == flimflam::kStateIdle)) {
107 *image = network_icon::GetImageForDisconnectedNetwork( 109 *image = network_icon::GetImageForDisconnectedNetwork(
108 network_icon::ICON_TYPE_DEFAULT_VIEW, flimflam::kTypeVPN); 110 network_icon::ICON_TYPE_DEFAULT_VIEW, flimflam::kTypeVPN);
109 if (label) { 111 if (label) {
110 *label = l10n_util::GetStringUTF16( 112 *label = l10n_util::GetStringUTF16(
111 IDS_ASH_STATUS_TRAY_VPN_DISCONNECTED); 113 IDS_ASH_STATUS_TRAY_VPN_DISCONNECTED);
112 } 114 }
113 *animating = false; 115 *animating = false;
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 } 334 }
333 } 335 }
334 336
335 void TrayVPN::NetworkServiceChanged(const chromeos::NetworkState* network) { 337 void TrayVPN::NetworkServiceChanged(const chromeos::NetworkState* network) {
336 if (detailed_) 338 if (detailed_)
337 detailed_->NetworkServiceChanged(network); 339 detailed_->NetworkServiceChanged(network);
338 } 340 }
339 341
340 } // namespace internal 342 } // namespace internal
341 } // namespace ash 343 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698