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

Side by Side Diff: chrome/browser/chromeos/extensions/networking_private_event_router.cc

Issue 12390017: Separating ONC<->Shill translation from the ONC signature. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed browser tests. Created 7 years, 9 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) 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 11 matching lines...) Expand all
22 #include "third_party/cros_system_api/dbus/service_constants.h" 22 #include "third_party/cros_system_api/dbus/service_constants.h"
23 23
24 using extensions::event_names::kOnNetworkListChanged; 24 using extensions::event_names::kOnNetworkListChanged;
25 using extensions::event_names::kOnNetworksChanged; 25 using extensions::event_names::kOnNetworksChanged;
26 using extensions::EventRouter; 26 using extensions::EventRouter;
27 using extensions::ExtensionSystem; 27 using extensions::ExtensionSystem;
28 namespace api = extensions::api::networking_private; 28 namespace api = extensions::api::networking_private;
29 29
30 namespace chromeos { 30 namespace chromeos {
31 31
32 namespace {
33
34 // Translates the current connection state of the network into the ONC
35 // equivalent.
36 std::string GetConnectionState(const NetworkState* state) {
37 if (state->IsConnectedState())
38 return onc::connection_state::kConnected;
39 else if (state->IsConnectingState())
40 return onc::connection_state::kConnecting;
41 else
42 return onc::connection_state::kNotConnected;
43 }
44
45 // Translate from the Shill network type to the ONC network type.
46 std::string GetConnectionType(const std::string& shill_type) {
47 base::DictionaryValue shill_type_dict;
48 shill_type_dict.SetStringWithoutPathExpansion(flimflam::kTypeProperty,
49 shill_type);
50 scoped_ptr<base::DictionaryValue> onc_type_dict =
51 onc::TranslateShillServiceToONCPart(
52 shill_type_dict,
53 &onc::kNetworkConfigurationSignature);
54 std::string onc_type;
55 if (onc_type_dict->GetString(onc::network_config::kType, &onc_type))
56 return onc_type;
57 return std::string();
58 }
59
60 } // namespace
61
62 NetworkingPrivateEventRouter::NetworkingPrivateEventRouter(Profile* profile) 32 NetworkingPrivateEventRouter::NetworkingPrivateEventRouter(Profile* profile)
63 : profile_(profile), listening_(false) { 33 : profile_(profile), listening_(false) {
64 // Register with the event router so we know when renderers are listening to 34 // Register with the event router so we know when renderers are listening to
65 // our events. We first check and see if there *is* an event router, because 35 // our events. We first check and see if there *is* an event router, because
66 // some unit tests try to create all profile services, but don't initialize 36 // some unit tests try to create all profile services, but don't initialize
67 // the event router first. 37 // the event router first.
68 EventRouter* event_router = ExtensionSystem::Get(profile_)->event_router(); 38 EventRouter* event_router = ExtensionSystem::Get(profile_)->event_router();
69 if (event_router) { 39 if (event_router) {
70 event_router->RegisterObserver( 40 event_router->RegisterObserver(
71 this, extensions::event_names::kOnNetworksChanged); 41 this, extensions::event_names::kOnNetworksChanged);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 return; 118 return;
149 119
150 scoped_ptr<base::ListValue> args(api::OnNetworksChanged::Create( 120 scoped_ptr<base::ListValue> args(api::OnNetworksChanged::Create(
151 std::vector<std::string>(1, network->path()))); 121 std::vector<std::string>(1, network->path())));
152 scoped_ptr<extensions::Event> extension_event( 122 scoped_ptr<extensions::Event> extension_event(
153 new extensions::Event(kOnNetworksChanged, args.Pass())); 123 new extensions::Event(kOnNetworksChanged, args.Pass()));
154 event_router->BroadcastEvent(extension_event.Pass()); 124 event_router->BroadcastEvent(extension_event.Pass());
155 } 125 }
156 126
157 } // namespace chromeos 127 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/extensions/networking_private_api.cc ('k') | chrome/test/data/extensions/api_test/networking/test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698