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

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: Fix Error handling 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/favorite_state.h"
14 #include "chromeos/network/managed_network_configuration_handler.h"
15 #include "chromeos/network/network_state.h"
16 #include "chromeos/network/network_state_handler.h"
17 #include "chromeos/network/network_util.h"
18 #include "chromeos/network/onc/onc_signature.h"
19 #include "chromeos/network/onc/onc_utils.h"
20 #include "chromeos/network/shill_property_util.h"
21 #include "components/onc/onc_constants.h"
22 #include "content/public/browser/web_ui.h"
23 #include "third_party/cros_system_api/dbus/service_constants.h"
24
25 namespace chromeos {
26
27 namespace {
28
29 bool GetServicePathFromGuid(const std::string& guid,
30 std::string* service_path) {
31 const FavoriteState* network =
32 NetworkHandler::Get()->network_state_handler()->GetFavoriteStateFromGuid(
33 guid);
34 if (!network)
35 return false;
36 *service_path = network->path();
37 return true;
38 }
39
40 } // namespace
41
42 NetworkConfigMessageHandler::NetworkConfigMessageHandler() {
43 }
44
45 NetworkConfigMessageHandler::~NetworkConfigMessageHandler() {
46 }
47
48 void NetworkConfigMessageHandler::RegisterMessages() {
49 web_ui()->RegisterMessageCallback(
50 "networkConfig.getNetworks",
51 base::Bind(&NetworkConfigMessageHandler::GetNetworks,
52 base::Unretained(this)));
53 web_ui()->RegisterMessageCallback(
54 "networkConfig.getProperties",
55 base::Bind(&NetworkConfigMessageHandler::GetProperties,
56 base::Unretained(this)));
57 }
58
59 void NetworkConfigMessageHandler::GetNetworks(
60 const base::ListValue* arg_list) const {
61 int callback_id;
62 const base::DictionaryValue* filter;
63 if (!arg_list->GetInteger(0, &callback_id) ||
64 !arg_list->GetDictionary(1, &filter)) {
65 NOTREACHED();
pneubeck (no reviews) 2014/05/22 16:24:20 at least return; but as the "rule" is to not handl
stevenjb 2014/05/23 21:50:59 This represents a (JS) coding error, so should cra
pneubeck (no reviews) 2014/05/24 13:38:53 IMO not acceptable. NOTREACHED will just succeed o
stevenjb 2014/05/27 15:58:35 'filter' should be initialized to NULL here so tha
66 }
67 std::string type = ::onc::network_type::kAllTypes;
68 bool visible_only = false;
69 bool configured_only = false;
70 int limit = 1000;
71 filter->GetString("type", &type);
72 filter->GetBoolean("visible", &visible_only);
73 filter->GetBoolean("configured", &configured_only);
74 filter->GetInteger("limit", &limit);
75
76 base::ListValue return_arg_list;
77 return_arg_list.AppendInteger(callback_id);
78
79 NetworkTypePattern pattern = onc::NetworkTypePatternFromOncType(type);
pneubeck (no reviews) 2014/05/22 16:24:20 nit: move to the other filter options above
stevenjb 2014/05/23 21:50:59 Done.
80 scoped_ptr<base::ListValue> network_properties_list =
81 chromeos::network_util::TranslateNetworkListToONC(
82 pattern, configured_only, visible_only, limit,
83 true /* debugging_properties */);
84
85 return_arg_list.Append(network_properties_list.release());
86
87 InvokeCallback(return_arg_list);
88 }
89
90 void NetworkConfigMessageHandler::GetProperties(
91 const base::ListValue* arg_list) const {
92 int callback_id;
93 std::string guid;
94 if (!arg_list->GetInteger(0, &callback_id) ||
xiyuan 2014/05/21 21:22:28 nit: I would just CHECK, i.e. CHECK(arg_list->GetI
stevenjb 2014/05/23 21:50:59 1) It's non-fatal but should never happen, so DCHE
95 !arg_list->GetString(1, &guid)) {
96 NOTREACHED();
97 }
98 std::string service_path;
99 if (!GetServicePathFromGuid(guid, &service_path)) {
100 scoped_ptr<base::DictionaryValue> error_data;
101 ErrorCallback(callback_id, "Error.InvalidNetworkGuid", error_data.Pass());
102 return;
103 }
104 NetworkHandler::Get()->managed_network_configuration_handler()->GetProperties(
105 service_path,
106 base::Bind(&NetworkConfigMessageHandler::GetPropertiesSuccess,
107 base::Unretained(this), callback_id),
xiyuan 2014/05/21 21:22:28 Are we sure this class would not go away when GetP
stevenjb 2014/05/23 21:50:59 Yes, yes we should. I must have copy/pasted this.
108 base::Bind(&NetworkConfigMessageHandler::ErrorCallback,
109 base::Unretained(this), callback_id));
110 }
111
112 void NetworkConfigMessageHandler::GetPropertiesSuccess(
113 int callback_id,
114 const std::string& service_path,
115 const base::DictionaryValue& dictionary) const {
116 base::ListValue return_arg_list;
117 return_arg_list.AppendInteger(callback_id);
118
119 base::DictionaryValue* network_properties = dictionary.DeepCopy();
120 network_properties->SetStringWithoutPathExpansion(
121 ::onc::network_config::kGUID, service_path);
122 return_arg_list.Append(network_properties);
123 InvokeCallback(return_arg_list);
124 }
125
126 void NetworkConfigMessageHandler::InvokeCallback(
127 const base::ListValue& arg_list) const {
128 web_ui()->CallJavascriptFunction(
129 "networkConfig.chromeCallbackSuccess", arg_list);
130 }
131
132 void NetworkConfigMessageHandler::ErrorCallback(
133 int callback_id,
134 const std::string& error_name,
135 scoped_ptr<base::DictionaryValue> error_data) const {
136 LOG(ERROR) << "NetworkConfigMessageHandler Error: " << error_name;
137 base::ListValue arg_list;
138 arg_list.AppendInteger(callback_id);
139 arg_list.AppendString(error_name);
140 web_ui()->CallJavascriptFunction(
141 "networkConfig.chromeCallbackError", arg_list);
142 }
143
144 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698