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

Side by Side Diff: extensions/browser/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: adressed comments by kalman, stevenjb and asvitkine 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 EXTENSIONS_BROWSER_API_NETWORKING_CONFIG_NETWORKING_CONFIG_SERVICE_H_
6 #define EXTENSIONS_BROWSER_API_NETWORKING_CONFIG_NETWORKING_CONFIG_SERVICE_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 // This class provides the session-scoped storage backing the networking config
21 // extension API. Currently only the parts relevant for captive portal handling
22 // are implemented.
23 class NetworkingConfigService : public ExtensionRegistryObserver,
24 public KeyedService {
25 public:
26 class EventDelegate {
27 public:
28 EventDelegate() {}
29 virtual ~EventDelegate() {}
30 virtual bool HasExtensionRegisteredForEvent(
31 const std::string& extension_id) const = 0;
32
33 private:
34 DISALLOW_COPY_AND_ASSIGN(EventDelegate);
35 };
36
37 // Indicates the authentication state of the portal.
38 enum AuthenticationState { NOTRY, TRYING, SUCCESS, REJECTED, FAILED };
39
40 // Provides information about the current authentication state of the portal.
41 struct AuthenticationResult {
42 AuthenticationResult();
43 AuthenticationResult(ExtensionId extension_id,
44 std::string guid,
45 AuthenticationState authentication_state);
46 ExtensionId extension_id;
47 std::string guid;
48 AuthenticationState authentication_state;
49 };
50
51 // Note: |extension_registry| must outlive this class.
52 NetworkingConfigService(scoped_ptr<EventDelegate> event_delegate,
53 ExtensionRegistry* extension_registry);
54 ~NetworkingConfigService() override;
55
56 // ExtensionRegistryObserver
57 void OnExtensionUnloaded(content::BrowserContext* browser_context,
58 const Extension* extension,
59 UnloadedExtensionInfo::Reason reason) override;
60
61 // Returns the extension id registered for |hex_ssid|. If no extension is
62 // registered for this |hex_ssid|, the function returns an empty string.
63 // |hex_ssid|: SSID in hex encoding.
64 std::string LookupExtensionIdForHexSsid(std::string hex_ssid) const;
65
66 // Returns true if the extension with id |extension_id| registered for
67 // |onCaptivePortalDetected| events, otherwise false.
68 bool IsRegisteredForCaptivePortalEvent(std::string extension_id) const;
69
70 // Registers |hex_ssid| as being handled by the extension with extension ID
71 // |extension_id|. Returns true on success and false if another extension
72 // already registered for |hex_ssid|.
73 // |hex_ssid|: SSID in hex encoding of the network to be registered.
74 // |extension_id|: Extension ID of the extension handling the network
75 // configuration for this network.
76 bool RegisterHexSsid(std::string hex_ssid, const std::string& extension_id);
77
78 // Unregisters extension with the ID |extension_id| removing all associated
79 // HexSSIDs from the map.
80 // |extension_id|: ID identifying the extenion to be removed
81 void UnregisterExtension(const std::string& extensionId);
82
83 // Returns the current AuthenticationResult.
84 const AuthenticationResult& GetAuthenticationResult() const;
85
86 // Sets the authentication_state to NOTRY and clears all other fields.
87 void ResetAuthenticationResult();
88
89 // Sets the current AuthenticationResult.
90 void SetAuthenticationResult(
91 const AuthenticationResult& authentication_result);
92
93 private:
94 AuthenticationResult authentication_result_;
95
96 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
97 registry_observer_;
98
99 scoped_ptr<EventDelegate> event_delegate_;
100
101 // This map associates a given hex encoded SSID to an extension entry.
102 std::map<std::string, std::string> hex_ssid_to_extension_id_;
103 };
104
105 } // namespace extensions
106
107 #endif // EXTENSIONS_BROWSER_API_NETWORKING_CONFIG_NETWORKING_CONFIG_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698