| Index: chrome/browser/extensions/api/networking_config/networking_config_service.cc
|
| diff --git a/chrome/browser/extensions/api/networking_config/networking_config_service.cc b/chrome/browser/extensions/api/networking_config/networking_config_service.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..c121b8e4ba91f5bb889fb294d1aadfdec3144a52
|
| --- /dev/null
|
| +++ b/chrome/browser/extensions/api/networking_config/networking_config_service.cc
|
| @@ -0,0 +1,100 @@
|
| +// 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.
|
| +
|
| +#include <algorithm>
|
| +
|
| +#include "base/lazy_instance.h"
|
| +#include "base/strings/string_util.h"
|
| +#include "chrome/browser/extensions/api/networking_config/networking_config_service.h"
|
| +
|
| +namespace extensions {
|
| +
|
| +namespace {
|
| +
|
| +bool IsValidNonEmptyHexString(const std::string& input) {
|
| + size_t count = input.size();
|
| + if (count == 0 || (count % 2) != 0)
|
| + return false;
|
| + return std::all_of(input.begin(), input.end(), IsHexDigit<char>);
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +NetworkingConfigService::AuthenticationResult::AuthenticationResult()
|
| + : authentication_state(NetworkingConfigService::NOTRY) {
|
| +}
|
| +
|
| +NetworkingConfigService::NetworkingConfigService(
|
| + scoped_ptr<EventDelegate> event_delegate,
|
| + ExtensionRegistry* extension_registry)
|
| + : registry_observer_(this), event_delegate_(event_delegate.Pass()) {
|
| + registry_observer_.Add(extension_registry);
|
| +}
|
| +
|
| +NetworkingConfigService::~NetworkingConfigService() {
|
| +}
|
| +
|
| +void NetworkingConfigService::OnExtensionUnloaded(
|
| + content::BrowserContext* browser_context,
|
| + const Extension* extension,
|
| + UnloadedExtensionInfo::Reason reason) {
|
| + UnregisterExtension(extension->id());
|
| +}
|
| +
|
| +std::string NetworkingConfigService::GetExtensionIdForHexSsid(
|
| + std::string hex_ssid) const {
|
| + // Transform hex_ssid to uppercase.
|
| + transform(hex_ssid.begin(), hex_ssid.end(), hex_ssid.begin(), toupper);
|
| +
|
| + const auto it = hex_ssid_to_extension_id_.find(hex_ssid);
|
| + if (it == hex_ssid_to_extension_id_.end())
|
| + return std::string();
|
| + return it->second;
|
| +}
|
| +
|
| +bool NetworkingConfigService::HasExtensionRegisteredForEvent(
|
| + std::string extension_id) const {
|
| + return event_delegate_->HasExtensionRegisteredForEvent(extension_id);
|
| +}
|
| +
|
| +bool NetworkingConfigService::RegisterHexSsid(std::string hex_ssid,
|
| + const std::string& extension_id) {
|
| + if (!IsValidNonEmptyHexString(hex_ssid)) {
|
| + LOG(ERROR) << "\'" << hex_ssid << "\' is not a valid hex encoded string.";
|
| + return false;
|
| + }
|
| +
|
| + // Transform hex_ssid to uppercase.
|
| + transform(hex_ssid.begin(), hex_ssid.end(), hex_ssid.begin(), toupper);
|
| +
|
| + return hex_ssid_to_extension_id_.insert(make_pair(hex_ssid, extension_id))
|
| + .second;
|
| +}
|
| +
|
| +void NetworkingConfigService::UnregisterExtension(
|
| + const std::string& extension_id) {
|
| + for (auto it = hex_ssid_to_extension_id_.begin();
|
| + it != hex_ssid_to_extension_id_.end();) {
|
| + if (it->second == extension_id)
|
| + hex_ssid_to_extension_id_.erase(it++);
|
| + else
|
| + ++it;
|
| + }
|
| +}
|
| +
|
| +const NetworkingConfigService::AuthenticationResult&
|
| +NetworkingConfigService::GetAuthenticationResult() const {
|
| + return authentication_result_;
|
| +}
|
| +
|
| +void NetworkingConfigService::ResetAuthenticationResult() {
|
| + authentication_result_ = AuthenticationResult();
|
| +}
|
| +
|
| +void NetworkingConfigService::SetAuthenticationResult(
|
| + const AuthenticationResult& authentication_result) {
|
| + authentication_result_ = authentication_result;
|
| +}
|
| +
|
| +} // namespace extensions
|
|
|