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

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: Use callback id map, add getProperties 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/logging.h"
12 #include "base/values.h"
13 #include "chromeos/network/managed_network_configuration_handler.h"
14 #include "chromeos/network/network_state.h"
15 #include "chromeos/network/network_state_handler.h"
16 #include "chromeos/network/onc/onc_signature.h"
17 #include "chromeos/network/onc/onc_translator.h"
18 #include "chromeos/network/onc/onc_utils.h"
19 #include "chromeos/network/shill_property_util.h"
20 #include "components/onc/onc_constants.h"
21 #include "content/public/browser/web_ui.h"
22 #include "third_party/cros_system_api/dbus/service_constants.h"
23
24 namespace {
25
26 void CopyStringFromDictionary(const std::string& key,
pneubeck (no reviews) 2014/05/02 09:43:46 unused
stevenjb 2014/05/02 22:07:38 Done.
27 const base::DictionaryValue& source,
28 base::DictionaryValue* dest) {
29 std::string string_value;
30 if (source.GetStringWithoutPathExpansion(key, &string_value))
31 dest->SetStringWithoutPathExpansion(key, string_value);
32 }
33
34 } // namespace
35
36 namespace chromeos {
37
38 NetworkConfigMessageHandler::NetworkConfigMessageHandler() {
39 }
40
41 NetworkConfigMessageHandler::~NetworkConfigMessageHandler() {
42 }
43
44 void NetworkConfigMessageHandler::RegisterMessages() {
45 web_ui()->RegisterMessageCallback(
46 "networkConfig.getVisibleNetworks",
47 base::Bind(&NetworkConfigMessageHandler::GetVisibleNetworks,
48 base::Unretained(this)));
49 web_ui()->RegisterMessageCallback(
50 "networkConfig.getProperties",
51 base::Bind(&NetworkConfigMessageHandler::GetProperties,
52 base::Unretained(this)));
53 }
54
55 void NetworkConfigMessageHandler::GetVisibleNetworks(
56 const base::ListValue* arg_list) const {
57 int callback_id;
58 std::string type;
59 if (!arg_list->GetInteger(0, &callback_id) ||
60 !arg_list->GetString(1, &type)) {
61 NOTREACHED();
62 }
63 base::ListValue return_arg_list;
64 return_arg_list.AppendInteger(callback_id);
65
66 NetworkTypePattern type_pattern = onc::NetworkTypePatternFromOncType(type);
pneubeck (no reviews) 2014/05/02 09:43:46 re Arman's question whether this could be shared w
stevenjb 2014/05/02 22:07:38 Sure. Done.
67 NetworkStateHandler::NetworkStateList network_states;
68 NetworkHandler::Get()->network_state_handler()->GetNetworkListByType(
69 type_pattern, &network_states);
70
71 base::ListValue* network_state_list = new base::ListValue;
72 for (NetworkStateHandler::NetworkStateList::iterator it =
73 network_states.begin();
74 it != network_states.end(); ++it) {
75 base::DictionaryValue shill_dictionary;
76 (*it)->GetStateProperties(&shill_dictionary);
77 scoped_ptr<base::DictionaryValue> onc_network_part =
78 chromeos::onc::TranslateShillServiceToONCPart(
79 shill_dictionary, &chromeos::onc::kNetworkWithStateSignature);
80 onc_network_part->SetStringWithoutPathExpansion(
81 ::onc::network_config::kServicePath, (*it)->path());
82 network_state_list->Append(onc_network_part.release());
83 }
84 return_arg_list.Append(network_state_list);
85 InvokeCallback(return_arg_list);
86 }
87
88 void NetworkConfigMessageHandler::GetProperties(
89 const base::ListValue* arg_list) const {
90 int callback_id;
91 std::string guid;
92 if (!arg_list->GetInteger(0, &callback_id) ||
93 !arg_list->GetString(1, &guid)) {
94 NOTREACHED();
95 }
96 NetworkHandler::Get()->managed_network_configuration_handler()->GetProperties(
97 guid,
98 base::Bind(&NetworkConfigMessageHandler::GetPropertiesSuccess,
99 base::Unretained(this), callback_id),
100 base::Bind(&NetworkConfigMessageHandler::ErrorCallback,
101 base::Unretained(this), callback_id));
102 }
103
104 void NetworkConfigMessageHandler::GetPropertiesSuccess(
105 int callback_id,
106 const std::string& service_path,
107 const base::DictionaryValue& dictionary) const {
108 base::ListValue return_arg_list;
109 return_arg_list.AppendInteger(callback_id);
110
111 base::DictionaryValue* network_properties = dictionary.DeepCopy();
112 network_properties->SetStringWithoutPathExpansion(
113 ::onc::network_config::kGUID, service_path);
114 return_arg_list.Append(network_properties);
115 InvokeCallback(return_arg_list);
116 }
117
118 void NetworkConfigMessageHandler::InvokeCallback(
119 const base::ListValue& arg_list) const {
120 web_ui()->CallJavascriptFunction("networkConfig.chromeCallback", arg_list);
121 }
122
123 void NetworkConfigMessageHandler::ErrorCallback(
124 int callback_id,
125 const std::string& error_name,
126 scoped_ptr<base::DictionaryValue> error_data) const {
127 LOG(ERROR) << "NetworkConfigMessageHandler Error: " << error_name;
128 base::ListValue arg_list;
129 arg_list.AppendInteger(callback_id);
130 arg_list.AppendString(error_name);
131 web_ui()->CallJavascriptFunction("networkConfig.chromeError", arg_list);
132 }
133
134 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698