| Index: chrome/browser/extensions/api/networking_config/networking_config_service.h
|
| diff --git a/chrome/browser/extensions/api/networking_config/networking_config_service.h b/chrome/browser/extensions/api/networking_config/networking_config_service.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..58d72948b55d03ffbee924f2d3dcfa37c6a0d6de
|
| --- /dev/null
|
| +++ b/chrome/browser/extensions/api/networking_config/networking_config_service.h
|
| @@ -0,0 +1,106 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#ifndef CHROME_BROWSER_EXTENSIONS_API_NETWORKING_CONFIG_NETWORKING_CONFIG_SERVICE_H_
|
| +#define CHROME_BROWSER_EXTENSIONS_API_NETWORKING_CONFIG_NETWORKING_CONFIG_SERVICE_H_
|
| +
|
| +#include <map>
|
| +#include <string>
|
| +
|
| +#include "base/memory/scoped_ptr.h"
|
| +#include "base/scoped_observer.h"
|
| +#include "components/keyed_service/core/keyed_service.h"
|
| +#include "extensions/browser/event_router.h"
|
| +#include "extensions/browser/extension_registry.h"
|
| +#include "extensions/browser/extension_registry_observer.h"
|
| +
|
| +namespace extensions {
|
| +
|
| +class NetworkingConfigService : public ExtensionRegistryObserver,
|
| + public KeyedService {
|
| + public:
|
| + class EventDelegate {
|
| + public:
|
| + EventDelegate() {}
|
| + virtual ~EventDelegate() {}
|
| + virtual bool HasExtensionRegisteredForEvent(
|
| + const std::string& extension_id) const = 0;
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(EventDelegate);
|
| + };
|
| +
|
| + // Indicates the authentication state of the portal.
|
| + enum AuthenticationState { NOTRY, TRYING, SUCCESS, REJECTED, FAILED };
|
| +
|
| + // Provides information about the current authentication state of the portal.
|
| + struct AuthenticationResult {
|
| + AuthenticationResult();
|
| + ExtensionId extension_id;
|
| + std::string guid;
|
| + AuthenticationState authentication_state;
|
| +
|
| + // |error_msg| is a translated string shown in the UI, describing why the
|
| + // captive portal authentication failed. On success |error_msg| is an empty
|
| + // string.
|
| + base::string16 error_msg;
|
| + };
|
| +
|
| + // Note: |extension_registry| must outlive this class.
|
| + explicit NetworkingConfigService(scoped_ptr<EventDelegate> event_delegate,
|
| + ExtensionRegistry* extension_registry);
|
| + ~NetworkingConfigService() override;
|
| +
|
| + // ExtensionRegistryObserver
|
| + void OnExtensionUnloaded(content::BrowserContext* browser_context,
|
| + const Extension* extension,
|
| + UnloadedExtensionInfo::Reason reason) override;
|
| +
|
| + // Returns the extension id registered for |hex_ssid|. If no extension is
|
| + // registered for this |hex_ssid|, the function returns an empty string.
|
| + // |hex_ssid|: SSID in hex encoding.
|
| + std::string GetExtensionIdForHexSsid(std::string hex_ssid) const;
|
| +
|
| + // Returns true if the extension with id |extension_id| registered for
|
| + // |onCaptivePortalDetected| events, otherwise false.
|
| + bool HasExtensionRegisteredForEvent(std::string extension_id) const;
|
| +
|
| + // Registers |hex_ssid| as being handled by the extension with extension ID
|
| + // |extension_id|. Returns true on success and false if another extension
|
| + // already registered for |hex_ssid|.
|
| + // |hex_ssid|: SSID in hex encoding of the network to be registered.
|
| + // |extension_id|: extension ID of the extension handling captive portal
|
| + // authentication for this network.
|
| + bool RegisterHexSsid(std::string hex_ssid, const std::string& extension_id);
|
| +
|
| + // Unregisters extension with the ID |extension_id| removing all associated
|
| + // HexSSIDs from the map.
|
| + // |extension_id|: ID identifying the extenion to be removed
|
| + void UnregisterExtension(const std::string& extensionId);
|
| +
|
| + // Returns the current AuthenticationResult.
|
| + const AuthenticationResult& GetAuthenticationResult() const;
|
| +
|
| + // Sets the authentication_state to NOTRY and clears all other fields.
|
| + void ResetAuthenticationResult();
|
| +
|
| + // Sets the current AuthenticationResult.
|
| + void SetAuthenticationResult(
|
| + const AuthenticationResult& authentication_result);
|
| +
|
| + private:
|
| + AuthenticationResult authentication_result_;
|
| +
|
| + ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
|
| + registry_observer_;
|
| +
|
| + scoped_ptr<EventDelegate> event_delegate_;
|
| +
|
| + // This map associates a given hex encoded SSID to an extension entry.
|
| + std::map<std::string, std::string> hex_ssid_to_extension_id_;
|
| +};
|
| +
|
| +} // namespace extensions
|
| +
|
| +#endif // CHROME_BROWSER_EXTENSIONS_API_NETWORKING_CONFIG_NETWORKING_CONFIG_SERVICE_H_
|
|
|