1// Copyright 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#ifndef CHROME_BROWSER_CHROMEOS_UI_PROXY_CONFIG_SERVICE_H_
6#define CHROME_BROWSER_CHROMEOS_UI_PROXY_CONFIG_SERVICE_H_
7
8#include <string>
9
10#include "base/basictypes.h"
11#include "chrome/browser/chromeos/ui_proxy_config.h"
12
13class PrefService;
14
15namespace chromeos {
16
17class NetworkState;
18
19// This class is only accessed from the UI via Profile::GetProxyConfigTracker to
20// allow the user to read and modify the proxy configuration via
21// GetProxyConfig and SetProxyConfig.
22//
23// Before reading/setting a proxy config, a network has to be selected using
24// either SetCurrentNetwork (any remembered network) or
25// MakeActiveNetworkCurrent.
26class UIProxyConfigService {
27 public:
28  UIProxyConfigService();
29  ~UIProxyConfigService();
30
31  // After this call, proxy settings are read from |profile_prefs| and
32  // |local_state_prefs|. In case of usage for the sign-in screen,
33  // |profile_prefs| must be NULL because sign-in screen should depend only on
34  // shared settings.
35  void SetPrefs(PrefService* profile_prefs, PrefService* local_state_prefs);
36
37  // Called by UI to set the network with service path |current_network| to be
38  // displayed or edited.  Subsequent Set*/Get* methods will use this
39  // network, until this method is called again.
40  void SetCurrentNetwork(const std::string& current_network);
41
42  void UpdateFromPrefs();
43
44  // Called from UI to retrieve the stored proxy configuration, which is either
45  // the last proxy config of the current network or the one last set by
46  // SetProxyConfig.
47  void GetProxyConfig(UIProxyConfig* config) const;
48
49  // Called from UI to update proxy configuration for different modes. Stores
50  // and persists |config| to shill for the current network.
51  void SetProxyConfig(const UIProxyConfig& config);
52
53 private:
54  // Determines effective proxy config based on prefs from config tracker,
55  // |network| and if user is using shared proxies.  The effective config is
56  // stored in |current_ui_config_| but not activated on network stack, and
57  // hence, not picked up by observers.
58  void DetermineEffectiveConfig(const NetworkState& network);
59
60  // Service path of network whose proxy configuration is being displayed or
61  // edited via UI.
62  std::string current_ui_network_;
63
64  // Proxy configuration of |current_ui_network_|.
65  UIProxyConfig current_ui_config_;
66
67  bool signin_screen_;
68
69  // Not owned.
70  PrefService* profile_prefs_;
71
72  // Not owned.
73  PrefService* local_state_prefs_;
74
75  DISALLOW_COPY_AND_ASSIGN(UIProxyConfigService);
76};
77
78}  // namespace chromeos
79
80#endif  // CHROME_BROWSER_CHROMEOS_UI_PROXY_CONFIG_SERVICE_H_
81