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

Side by Side Diff: chrome/browser/extensions/api/networking_config/networking_config_service.h

Issue 880073002: Networking.config: Implementation of the NetworkingConfigService (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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
(Empty)
1 // Copyright 2015 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_EXTENSIONS_API_NETWORKING_CONFIG_NETWORKING_CONFIG_SERVIC E_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_NETWORKING_CONFIG_NETWORKING_CONFIG_SERVIC E_H_
7
8 #include <map>
9 #include <string>
10
11 #include "base/memory/scoped_ptr.h"
12 #include "base/scoped_observer.h"
13 #include "components/keyed_service/core/keyed_service.h"
14 #include "extensions/browser/event_router.h"
15 #include "extensions/browser/extension_registry.h"
16 #include "extensions/browser/extension_registry_observer.h"
17
18 namespace extensions {
19
20 class NetworkingConfigService : public ExtensionRegistryObserver,
21 public KeyedService {
22 public:
23 class EventDelegate {
24 public:
25 EventDelegate() {}
26 virtual ~EventDelegate() {}
27 virtual bool HasExtensionRegisteredForEvent(
28 const std::string& extension_id) const = 0;
29
30 private:
31 DISALLOW_COPY_AND_ASSIGN(EventDelegate);
32 };
33
34 // Indicates the authentication state of the portal.
35 enum AuthenticationState { NOTRY, TRYING, SUCCESS, REJECTED, FAILED };
36
37 // Provides information about the current authentication state of the portal.
38 struct AuthenticationResult {
39 AuthenticationResult();
40 ExtensionId extension_id;
41 std::string guid;
42 AuthenticationState authentication_state;
43
44 // |error_msg| is a translated string shown in the UI, describing why the
45 // captive portal authentication failed. On success |error_msg| is an empty
46 // string.
47 base::string16 error_msg;
48 };
49
50 // Note: |extension_registry| must outlive this class.
51 explicit NetworkingConfigService(scoped_ptr<EventDelegate> event_delegate,
52 ExtensionRegistry* extension_registry);
53 ~NetworkingConfigService() override;
54
55 // ExtensionRegistryObserver
56 void OnExtensionUnloaded(content::BrowserContext* browser_context,
57 const Extension* extension,
58 UnloadedExtensionInfo::Reason reason) override;
59
60 // Returns the extension id registered for |hex_ssid|. If no extension is
61 // registered for this |hex_ssid|, the function returns an empty string.
62 // |hex_ssid|: SSID in hex encoding.
63 std::string GetExtensionIdForHexSsid(std::string hex_ssid) const;
64
65 // Returns true if the extension with id |extension_id| registered for
66 // |onCaptivePortalDetected| events, otherwise false.
67 bool HasExtensionRegisteredForEvent(std::string extension_id) const;
68
69 // Registers |hex_ssid| as being handled by the extension with extension ID
70 // |extension_id|. Returns true on success and false if another extension
71 // already registered for |hex_ssid|.
72 // |hex_ssid|: SSID in hex encoding of the network to be registered.
73 // |extension_id|: extension ID of the extension handling captive portal
74 // authentication for this network.
75 bool RegisterHexSsid(std::string hex_ssid, const std::string& extension_id);
76
77 // Unregisters extension with the ID |extension_id| removing all associated
78 // HexSSIDs from the map.
79 // |extension_id|: ID identifying the extenion to be removed
80 void UnregisterExtension(const std::string& extensionId);
81
82 // Returns the current AuthenticationResult.
83 const AuthenticationResult& GetAuthenticationResult() const;
84
85 // Sets the authentication_state to NOTRY and clears all other fields.
86 void ResetAuthenticationResult();
87
88 // Sets the current AuthenticationResult.
89 void SetAuthenticationResult(
90 const AuthenticationResult& authentication_result);
91
92 private:
93 AuthenticationResult authentication_result_;
94
95 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
96 registry_observer_;
97
98 scoped_ptr<EventDelegate> event_delegate_;
99
100 // This map associates a given hex encoded SSID to an extension entry.
101 std::map<std::string, std::string> hex_ssid_to_extension_id_;
102 };
103
104 } // namespace extensions
105
106 #endif // CHROME_BROWSER_EXTENSIONS_API_NETWORKING_CONFIG_NETWORKING_CONFIG_SER VICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698