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

Side by Side Diff: chromeos/network/network_configuration_handler.cc

Issue 12211103: Adding a new ManagedNetworkConfigurationHandler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Gaurav's and Steven's comments. 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chromeos/network/network_configuration_handler.h" 5 #include "chromeos/network/network_configuration_handler.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chromeos/dbus/dbus_method_call_status.h" 15 #include "chromeos/dbus/dbus_method_call_status.h"
16 #include "chromeos/dbus/dbus_thread_manager.h" 16 #include "chromeos/dbus/dbus_thread_manager.h"
17 #include "chromeos/dbus/shill_manager_client.h" 17 #include "chromeos/dbus/shill_manager_client.h"
18 #include "chromeos/dbus/shill_service_client.h" 18 #include "chromeos/dbus/shill_service_client.h"
19 #include "dbus/object_path.h" 19 #include "dbus/object_path.h"
20 20
21 namespace chromeos { 21 namespace chromeos {
22 22
23 static NetworkConfigurationHandler* g_network_configuration_handler = NULL;
24
25 namespace { 23 namespace {
26 24
27 const char kLogModule[] = "NetworkConfigurationHandler"; 25 const char kLogModule[] = "NetworkConfigurationHandler";
28 26
27 NetworkConfigurationHandler* g_configuration_handler_instance = NULL;
28
29 // None of these error messages are user-facing: they should only appear in 29 // None of these error messages are user-facing: they should only appear in
30 // logs. 30 // logs.
31 const char kErrorsListTag[] = "errors"; 31 const char kErrorsListTag[] = "errors";
32 const char kClearPropertiesFailedError[] = "Error.ClearPropertiesFailed"; 32 const char kClearPropertiesFailedError[] = "Error.ClearPropertiesFailed";
33 const char kClearPropertiesFailedErrorMessage[] = "Clear properties failed"; 33 const char kClearPropertiesFailedErrorMessage[] = "Clear properties failed";
34 const char kDBusFailedError[] = "Error.DBusFailed"; 34 const char kDBusFailedError[] = "Error.DBusFailed";
35 const char kDBusFailedErrorMessage[] = "DBus call failed."; 35 const char kDBusFailedErrorMessage[] = "DBus call failed.";
36 36
37 void ClearPropertiesCallback( 37 void ClearPropertiesCallback(
38 const std::vector<std::string>& names, 38 const std::vector<std::string>& names,
(...skipping 14 matching lines...) Expand all
53 } 53 }
54 } 54 }
55 55
56 if (some_failed) { 56 if (some_failed) {
57 DCHECK(names.size() == result.GetSize()) 57 DCHECK(names.size() == result.GetSize())
58 << "Result wrong size from ClearProperties."; 58 << "Result wrong size from ClearProperties.";
59 scoped_ptr<base::DictionaryValue> error_data( 59 scoped_ptr<base::DictionaryValue> error_data(
60 network_handler::CreateErrorData(service_path, 60 network_handler::CreateErrorData(service_path,
61 kClearPropertiesFailedError, 61 kClearPropertiesFailedError,
62 kClearPropertiesFailedErrorMessage)); 62 kClearPropertiesFailedErrorMessage));
63 LOG(ERROR) << "ClearPropertiesCallback Failed for service path: " 63 LOG(ERROR) << "ClearPropertiesCallback failed for service path: "
64 << service_path; 64 << service_path;
65 error_data->Set("errors", result.DeepCopy()); 65 error_data->Set("errors", result.DeepCopy());
66 scoped_ptr<base::ListValue> name_list(new base::ListValue); 66 scoped_ptr<base::ListValue> name_list(new base::ListValue);
67 name_list->AppendStrings(names); 67 name_list->AppendStrings(names);
68 error_data->Set("names", name_list.release()); 68 error_data->Set("names", name_list.release());
69 error_callback.Run(kClearPropertiesFailedError, error_data.Pass()); 69 error_callback.Run(kClearPropertiesFailedError, error_data.Pass());
70 } else { 70 } else {
71 callback.Run(); 71 callback.Run();
72 } 72 }
73 } 73 }
74 74
75 // Used to translate the dbus dictionary callback into one that calls 75 // Used to translate the dbus dictionary callback into one that calls
76 // the error callback if we have a failure. 76 // the error callback if we have a failure.
77 void RunCallbackWithDictionaryValue( 77 void RunCallbackWithDictionaryValue(
78 const network_handler::DictionaryResultCallback& callback, 78 const network_handler::DictionaryResultCallback& callback,
79 const network_handler::ErrorCallback& error_callback, 79 const network_handler::ErrorCallback& error_callback,
80 const std::string& service_path, 80 const std::string& service_path,
81 DBusMethodCallStatus call_status, 81 DBusMethodCallStatus call_status,
82 const base::DictionaryValue& value) { 82 const base::DictionaryValue& value) {
83 if (call_status != DBUS_METHOD_CALL_SUCCESS) { 83 if (call_status != DBUS_METHOD_CALL_SUCCESS) {
84 scoped_ptr<base::DictionaryValue> error_data( 84 scoped_ptr<base::DictionaryValue> error_data(
85 network_handler::CreateErrorData(service_path, 85 network_handler::CreateErrorData(service_path,
86 kDBusFailedError, 86 kDBusFailedError,
87 kDBusFailedErrorMessage)); 87 kDBusFailedErrorMessage));
88 LOG(ERROR) << "CallbackWithDictionaryValue Failed for service path: " 88 LOG(ERROR) << "CallbackWithDictionaryValue failed for service path: "
89 << service_path; 89 << service_path;
90 error_callback.Run(kDBusFailedError, error_data.Pass()); 90 error_callback.Run(kDBusFailedError, error_data.Pass());
91 } else { 91 } else {
92 callback.Run(service_path, value); 92 callback.Run(service_path, value);
93 } 93 }
94 } 94 }
95 95
96 void RunCreateNetworkCallback( 96 void RunCreateNetworkCallback(
97 const network_handler::StringResultCallback& callback, 97 const network_handler::StringResultCallback& callback,
98 const dbus::ObjectPath& service_path) { 98 const dbus::ObjectPath& service_path) {
99 callback.Run(service_path.value()); 99 callback.Run(service_path.value());
100 } 100 }
101 101
102 void IgnoreObjectPathCallback(const base::Closure& callback, 102 void IgnoreObjectPathCallback(const base::Closure& callback,
103 const dbus::ObjectPath& object_path) { 103 const dbus::ObjectPath& object_path) {
104 callback.Run(); 104 callback.Run();
105 } 105 }
106 106
107 } // namespace 107 } // namespace
108 108
109 NetworkConfigurationHandler::NetworkConfigurationHandler() {
110 }
111
112 NetworkConfigurationHandler::~NetworkConfigurationHandler() {
113 }
114
115 // static 109 // static
116 void NetworkConfigurationHandler::Initialize() { 110 void NetworkConfigurationHandler::Initialize() {
117 CHECK(!g_network_configuration_handler); 111 CHECK(!g_configuration_handler_instance);
118 g_network_configuration_handler = new NetworkConfigurationHandler(); 112 g_configuration_handler_instance = new NetworkConfigurationHandler;
119 } 113 }
120 114
121 // static 115 // static
122 void NetworkConfigurationHandler::Shutdown() { 116 void NetworkConfigurationHandler::Shutdown() {
123 CHECK(g_network_configuration_handler); 117 CHECK(g_configuration_handler_instance);
124 delete g_network_configuration_handler; 118 delete g_configuration_handler_instance;
125 g_network_configuration_handler = NULL; 119 g_configuration_handler_instance = NULL;
126 } 120 }
127 121
128 // static 122 // static
129 NetworkConfigurationHandler* NetworkConfigurationHandler::Get() { 123 NetworkConfigurationHandler* NetworkConfigurationHandler::Get() {
130 CHECK(g_network_configuration_handler) 124 CHECK(g_configuration_handler_instance)
131 << "NetworkConfigurationHandler::Get() called before Initialize()"; 125 << "NetworkConfigurationHandler::Get() called before Initialize()";
132 return g_network_configuration_handler; 126 return g_configuration_handler_instance;
133 } 127 }
134 128
135 void NetworkConfigurationHandler::GetProperties( 129 void NetworkConfigurationHandler::GetProperties(
136 const std::string& service_path, 130 const std::string& service_path,
137 const network_handler::DictionaryResultCallback& callback, 131 const network_handler::DictionaryResultCallback& callback,
138 const network_handler::ErrorCallback& error_callback) const { 132 const network_handler::ErrorCallback& error_callback) const {
139 DBusThreadManager::Get()->GetShillServiceClient()->GetProperties( 133 DBusThreadManager::Get()->GetShillServiceClient()->GetProperties(
140 dbus::ObjectPath(service_path), 134 dbus::ObjectPath(service_path),
141 base::Bind(&RunCallbackWithDictionaryValue, 135 base::Bind(&RunCallbackWithDictionaryValue,
142 callback, 136 callback,
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 const std::string& service_path, 204 const std::string& service_path,
211 const base::Closure& callback, 205 const base::Closure& callback,
212 const network_handler::ErrorCallback& error_callback) const { 206 const network_handler::ErrorCallback& error_callback) const {
213 DBusThreadManager::Get()->GetShillServiceClient()->Remove( 207 DBusThreadManager::Get()->GetShillServiceClient()->Remove(
214 dbus::ObjectPath(service_path), 208 dbus::ObjectPath(service_path),
215 callback, 209 callback,
216 base::Bind(&network_handler::ShillErrorCallbackFunction, 210 base::Bind(&network_handler::ShillErrorCallbackFunction,
217 kLogModule, service_path, error_callback)); 211 kLogModule, service_path, error_callback));
218 } 212 }
219 213
214 NetworkConfigurationHandler::NetworkConfigurationHandler() {
215 }
216
217 NetworkConfigurationHandler::~NetworkConfigurationHandler() {
218 }
219
220 } // namespace chromeos 220 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/network/network_configuration_handler.h ('k') | chromeos/network/network_configuration_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698