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

Side by Side Diff: chrome/browser/ui/webui/chromeos/network_config_message_handler.cc

Issue 260083007: Replace chrome://network implementation with networkConfig API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/webui/chromeos/network_config_message_handler.h"
6
7 #include <string>
8
9 #include "base/bind.h"
10 #include "base/bind_helpers.h"
11 #include "base/values.h"
12 #include "chromeos/network/favorite_state.h"
13 #include "chromeos/network/network_state.h"
14 #include "chromeos/network/network_state_handler.h"
15 #include "chromeos/network/onc/onc_signature.h"
16 #include "chromeos/network/onc/onc_translator.h"
17 #include "chromeos/network/onc/onc_utils.h"
18 #include "chromeos/network/shill_property_util.h"
19 #include "components/onc/onc_constants.h"
20 #include "content/public/browser/web_ui.h"
21 #include "third_party/cros_system_api/dbus/service_constants.h"
22
23 namespace {
24
25 void CopyStringFromDictionary(const std::string& key,
26 const base::DictionaryValue& source,
27 base::DictionaryValue* dest) {
28 std::string string_value;
29 if (source.GetStringWithoutPathExpansion(key, &string_value))
30 dest->SetStringWithoutPathExpansion(key, string_value);
31 }
32
33 } // namespace
34
35 namespace chromeos {
36
37 NetworkConfigMessageHandler::NetworkConfigMessageHandler() {
38 }
39
40 NetworkConfigMessageHandler::~NetworkConfigMessageHandler() {
41 }
42
43 void NetworkConfigMessageHandler::RegisterMessages() {
44 web_ui()->RegisterMessageCallback(
45 "networkConfig.getVisibleNetworks",
46 base::Bind(&NetworkConfigMessageHandler::GetVisibleNetworks,
47 base::Unretained(this)));
48 web_ui()->RegisterMessageCallback(
49 "networkConfig.getFavoriteNetworks",
50 base::Bind(&NetworkConfigMessageHandler::GetFavoriteNetworks,
51 base::Unretained(this)));
52 }
53
54 void NetworkConfigMessageHandler::GetVisibleNetworks(
55 const base::ListValue* value) const {
michaelpg 2014/04/29 19:51:00 Can you add a comment explaining what value is exp
stevenjb 2014/05/01 01:45:14 Added to header.
56 std::string type;
57 value->GetString(0, &type);
58 NetworkTypePattern type_pattern = onc::NetworkTypePatternFromOncType(type);
michaelpg 2014/04/29 19:51:00 What sorcery is this?
stevenjb 2014/04/29 21:44:03 See NetworkTypePattern in shill_property_util.h
59 NetworkStateHandler::NetworkStateList network_states;
60 NetworkHandler::Get()->network_state_handler()->GetNetworkListByType(
61 type_pattern, &network_states);
62
63 base::ListValue network_properties_list;
64 for (NetworkStateHandler::NetworkStateList::iterator it =
65 network_states.begin();
66 it != network_states.end(); ++it) {
67 base::DictionaryValue shill_dictionary;
68 (*it)->GetStateProperties(&shill_dictionary);
69 scoped_ptr<base::DictionaryValue> onc_network_part =
70 chromeos::onc::TranslateShillServiceToONCPart(
71 shill_dictionary, &chromeos::onc::kNetworkWithStateSignature);
72 onc_network_part->SetStringWithoutPathExpansion(
73 ::onc::network_config::kServicePath, (*it)->path());
74 network_properties_list.Append(onc_network_part.release());
75 }
76 web_ui()->CallJavascriptFunction(
77 "networkConfig.getVisibleNetworksCallback", network_properties_list);
78 }
79
80 void NetworkConfigMessageHandler::GetFavoriteNetworks(
81 const base::ListValue* value) const {
michaelpg 2014/04/29 19:51:00 same as 55
stevenjb 2014/05/01 01:45:14 Done.
82 std::string type;
83 value->GetString(0, &type);
84 NetworkTypePattern type_pattern = onc::NetworkTypePatternFromOncType(type);
85 NetworkStateHandler::FavoriteStateList favorite_states;
86 NetworkHandler::Get()->network_state_handler()->GetFavoriteListByType(
87 type_pattern, &favorite_states);
88
89 base::ListValue favorite_properties_list;
90 for (NetworkStateHandler::FavoriteStateList::iterator it =
91 favorite_states.begin();
92 it != favorite_states.end(); ++it) {
93 base::DictionaryValue shill_dictionary;
94 (*it)->GetStateProperties(&shill_dictionary);
95 scoped_ptr<base::DictionaryValue> onc_network_part =
96 chromeos::onc::TranslateShillServiceToONCPart(
97 shill_dictionary, &chromeos::onc::kNetworkWithStateSignature);
98 onc_network_part->SetStringWithoutPathExpansion(
99 ::onc::network_config::kServicePath, (*it)->path());
100 // Copy untranslated (non ONC) values.
101 CopyStringFromDictionary(
102 shill::kProfileProperty, shill_dictionary, onc_network_part.get());
103 CopyStringFromDictionary(
104 NetworkUIData::kKeyONCSource, shill_dictionary, onc_network_part.get());
105 favorite_properties_list.Append(onc_network_part.release());
106 }
107 web_ui()->CallJavascriptFunction(
108 "networkConfig.getFavoriteNetworksCallback", favorite_properties_list);
109 }
110
111 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698