OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/extensions/networking_private_event_router.h" | 5 #include "chrome/browser/chromeos/extensions/networking_private_event_router.h" |
6 | 6 |
7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
9 #include "chrome/browser/chromeos/extensions/networking_private_api.h" | 9 #include "chrome/browser/chromeos/extensions/networking_private_api.h" |
10 #include "chrome/browser/extensions/event_names.h" | 10 #include "chrome/browser/extensions/event_names.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 | 50 |
51 void NetworkingPrivateEventRouter::Shutdown() { | 51 void NetworkingPrivateEventRouter::Shutdown() { |
52 // Unregister with the event router. We first check and see if there *is* an | 52 // Unregister with the event router. We first check and see if there *is* an |
53 // event router, because some unit tests try to shutdown all profile services, | 53 // event router, because some unit tests try to shutdown all profile services, |
54 // but didn't initialize the event router first. | 54 // but didn't initialize the event router first. |
55 EventRouter* event_router = ExtensionSystem::Get(profile_)->event_router(); | 55 EventRouter* event_router = ExtensionSystem::Get(profile_)->event_router(); |
56 if (event_router) | 56 if (event_router) |
57 event_router->UnregisterObserver(this); | 57 event_router->UnregisterObserver(this); |
58 | 58 |
59 if (listening_) | 59 if (listening_) |
60 NetworkStateHandler::Get()->RemoveObserver(this); | 60 NetworkHandler::Get()->network_state_handler()->RemoveObserver(this); |
61 listening_ = false; | 61 listening_ = false; |
62 } | 62 } |
63 | 63 |
64 void NetworkingPrivateEventRouter::OnListenerAdded( | 64 void NetworkingPrivateEventRouter::OnListenerAdded( |
65 const extensions::EventListenerInfo& details) { | 65 const extensions::EventListenerInfo& details) { |
66 // Start listening to events from the network state handler. | 66 // Start listening to events from the network state handler. |
67 StartOrStopListeningForNetworkChanges(); | 67 StartOrStopListeningForNetworkChanges(); |
68 } | 68 } |
69 | 69 |
70 void NetworkingPrivateEventRouter::OnListenerRemoved( | 70 void NetworkingPrivateEventRouter::OnListenerRemoved( |
71 const extensions::EventListenerInfo& details) { | 71 const extensions::EventListenerInfo& details) { |
72 // Stop listening to events from the network state handler if there are no | 72 // Stop listening to events from the network state handler if there are no |
73 // more listeners. | 73 // more listeners. |
74 StartOrStopListeningForNetworkChanges(); | 74 StartOrStopListeningForNetworkChanges(); |
75 } | 75 } |
76 | 76 |
77 void NetworkingPrivateEventRouter::StartOrStopListeningForNetworkChanges() { | 77 void NetworkingPrivateEventRouter::StartOrStopListeningForNetworkChanges() { |
78 EventRouter* event_router = ExtensionSystem::Get(profile_)->event_router(); | 78 EventRouter* event_router = ExtensionSystem::Get(profile_)->event_router(); |
79 bool should_listen = event_router->HasEventListener(kOnNetworksChanged) || | 79 bool should_listen = event_router->HasEventListener(kOnNetworksChanged) || |
80 event_router->HasEventListener(kOnNetworkListChanged); | 80 event_router->HasEventListener(kOnNetworkListChanged); |
81 | 81 |
82 if (should_listen) { | 82 if (should_listen) { |
83 if (!listening_) | 83 if (!listening_) |
84 NetworkStateHandler::Get()->AddObserver(this); | 84 NetworkHandler::Get()->network_state_handler()->AddObserver(this); |
85 } else { | 85 } else { |
86 if (listening_) | 86 if (listening_) |
87 NetworkStateHandler::Get()->RemoveObserver(this); | 87 NetworkHandler::Get()->network_state_handler()->RemoveObserver(this); |
88 } | 88 } |
89 listening_ = should_listen; | 89 listening_ = should_listen; |
90 } | 90 } |
91 | 91 |
92 void NetworkingPrivateEventRouter::NetworkListChanged() { | 92 void NetworkingPrivateEventRouter::NetworkListChanged() { |
93 EventRouter* event_router = ExtensionSystem::Get(profile_)->event_router(); | 93 EventRouter* event_router = ExtensionSystem::Get(profile_)->event_router(); |
94 NetworkStateList networks; | 94 NetworkStateList networks; |
95 NetworkStateHandler::Get()->GetNetworkList(&networks); | 95 NetworkHandler::Get()->network_state_handler()->GetNetworkList(&networks); |
96 if (!event_router->HasEventListener(kOnNetworkListChanged)) | 96 if (!event_router->HasEventListener(kOnNetworkListChanged)) |
97 return; | 97 return; |
98 | 98 |
99 std::vector<std::string> changes; | 99 std::vector<std::string> changes; |
100 for (NetworkStateList::const_iterator iter = networks.begin(); | 100 for (NetworkStateList::const_iterator iter = networks.begin(); |
101 iter != networks.end(); ++iter) { | 101 iter != networks.end(); ++iter) { |
102 // TODO(gspencer): Currently the "GUID" is actually the service path. Fix | 102 // TODO(gspencer): Currently the "GUID" is actually the service path. Fix |
103 // this to be the real GUID once we're using | 103 // this to be the real GUID once we're using |
104 // ManagedNetworkConfigurationManager. | 104 // ManagedNetworkConfigurationManager. |
105 changes.push_back((*iter)->path()); | 105 changes.push_back((*iter)->path()); |
(...skipping 12 matching lines...) Expand all Loading... |
118 return; | 118 return; |
119 | 119 |
120 scoped_ptr<base::ListValue> args(api::OnNetworksChanged::Create( | 120 scoped_ptr<base::ListValue> args(api::OnNetworksChanged::Create( |
121 std::vector<std::string>(1, network->path()))); | 121 std::vector<std::string>(1, network->path()))); |
122 scoped_ptr<extensions::Event> extension_event( | 122 scoped_ptr<extensions::Event> extension_event( |
123 new extensions::Event(kOnNetworksChanged, args.Pass())); | 123 new extensions::Event(kOnNetworksChanged, args.Pass())); |
124 event_router->BroadcastEvent(extension_event.Pass()); | 124 event_router->BroadcastEvent(extension_event.Pass()); |
125 } | 125 } |
126 | 126 |
127 } // namespace chromeos | 127 } // namespace chromeos |
OLD | NEW |