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
3 // found in the LICENSE file.
4 
5 // Defines the Chrome Extensions Proxy Settings API relevant classes to realize
6 // the API as specified in the extension API JSON.
7 
8 #ifndef CHROME_BROWSER_EXTENSIONS_API_PROXY_PROXY_API_H_
9 #define CHROME_BROWSER_EXTENSIONS_API_PROXY_PROXY_API_H_
10 
11 #include <string>
12 
13 #include "base/macros.h"
14 #include "base/memory/singleton.h"
15 #include "base/strings/string16.h"
16 #include "chrome/browser/extensions/api/preference/preference_api.h"
17 #include "components/proxy_config/proxy_prefs.h"
18 
19 namespace base {
20 class Value;
21 }
22 
23 namespace extensions {
24 class EventRouterForwarder;
25 
26 // Class to convert between the representation of proxy settings used
27 // in the Proxy Settings API and the representation used in the PrefStores.
28 // This plugs into the ExtensionPreferenceAPI to get and set proxy settings.
29 class ProxyPrefTransformer : public PrefTransformerInterface {
30  public:
31   ProxyPrefTransformer();
32   ~ProxyPrefTransformer() override;
33 
34   // Implementation of PrefTransformerInterface.
35   std::unique_ptr<base::Value> ExtensionToBrowserPref(
36       const base::Value* extension_pref,
37       std::string* error,
38       bool* bad_message) override;
39   std::unique_ptr<base::Value> BrowserToExtensionPref(
40       const base::Value* browser_pref) override;
41 
42  private:
43   DISALLOW_COPY_AND_ASSIGN(ProxyPrefTransformer);
44 };
45 
46 // This class observes proxy error events and routes them to the appropriate
47 // extensions listening to those events. All methods must be called on the IO
48 // thread unless otherwise specified.
49 class ProxyEventRouter {
50  public:
51   static ProxyEventRouter* GetInstance();
52 
53   void OnProxyError(EventRouterForwarder* event_router,
54                     void* profile,
55                     int error_code);
56 
57   void OnPACScriptError(EventRouterForwarder* event_router,
58                         void* profile,
59                         int line_number,
60                         const base::string16& error);
61 
62  private:
63   friend struct base::DefaultSingletonTraits<ProxyEventRouter>;
64 
65   ProxyEventRouter();
66   ~ProxyEventRouter();
67 
68   DISALLOW_COPY_AND_ASSIGN(ProxyEventRouter);
69 };
70 
71 }  // namespace extensions
72 
73 #endif  // CHROME_BROWSER_EXTENSIONS_API_PROXY_PROXY_API_H_
74