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

Side by Side Diff: chrome/browser/chromeos/net/proxy_config_handler.cc

Issue 16398005: Extract common per-network proxy configuration functions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nit. Created 7 years, 6 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 (c) 2013 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/chromeos/net/proxy_config_handler.h"
6
7 #include "base/bind.h"
8 #include "base/json/json_writer.h"
9 #include "base/logging.h"
10 #include "base/values.h"
11 #include "chrome/browser/prefs/proxy_config_dictionary.h"
12 #include "chromeos/dbus/dbus_thread_manager.h"
13 #include "chromeos/dbus/shill_service_client.h"
14 #include "chromeos/network/network_handler_callbacks.h"
15 #include "chromeos/network/network_state.h"
16 #include "chromeos/network/network_state_handler.h"
17 #include "dbus/object_path.h"
18 #include "third_party/cros_system_api/dbus/service_constants.h"
19
20 namespace chromeos {
21
22 namespace {
23
24 void LogError(const std::string& network,
25 const std::string& error_name,
26 const std::string& error_message) {
27 network_handler::ShillErrorCallbackFunction(
28 network,
29 network_handler::ErrorCallback(),
30 "Could not clear or set ProxyConfig",
31 error_message);
32 }
33
34 } // namespace
35
36 namespace proxy_config {
37
38 scoped_ptr<ProxyConfigDictionary> GetProxyConfigForNetwork(
39 const NetworkState& network) {
40 const base::DictionaryValue& value = network.proxy_config();
41 if (value.empty())
42 return scoped_ptr<ProxyConfigDictionary>();
43 return make_scoped_ptr(new ProxyConfigDictionary(&value));
44 }
45
46 void SetProxyConfigForNetwork(const ProxyConfigDictionary& proxy_config,
47 const NetworkState& network) {
48 chromeos::ShillServiceClient* shill_service_client =
49 DBusThreadManager::Get()->GetShillServiceClient();
50
51 ProxyPrefs::ProxyMode mode;
52 if (!proxy_config.GetMode(&mode) || mode == ProxyPrefs::MODE_DIRECT) {
53 // TODO(pneubeck): Consider removing this legacy code. Return empty string
54 // for direct mode for portal check to work correctly.
55 shill_service_client->ClearProperty(
56 dbus::ObjectPath(network.path()),
57 flimflam::kProxyConfigProperty,
58 base::Bind(&base::DoNothing),
59 base::Bind(&LogError, network.path()));
60 } else {
61 std::string proxy_config_str;
62 base::JSONWriter::Write(&proxy_config.GetDictionary(), &proxy_config_str);
63 shill_service_client->SetProperty(
64 dbus::ObjectPath(network.path()),
65 flimflam::kProxyConfigProperty,
66 base::StringValue(proxy_config_str),
67 base::Bind(&base::DoNothing),
68 base::Bind(&LogError, network.path()));
69 }
70
71 if (NetworkHandler::IsInitialized()) {
72 NetworkHandler::Get()->network_state_handler()->
73 RequestUpdateForNetwork(network.path());
74 }
75 }
76
77 } // namespace proxy_config
78
79 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/net/proxy_config_handler.h ('k') | chrome/browser/chromeos/proxy_config_service_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698