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

Side by Side Diff: extensions/browser/api/networking_config/networking_config_service.cc

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 #include <algorithm>
6
7 #include "base/lazy_instance.h"
8 #include "base/strings/string_util.h"
9 #include "extensions/browser/api/networking_config/networking_config_service.h"
10
11 namespace extensions {
12
13 namespace {
14
15 bool IsValidNonEmptyHexString(const std::string& input) {
16 size_t count = input.size();
17 if (count == 0 || (count % 2) != 0)
18 return false;
19 return std::all_of(input.begin(), input.end(), IsHexDigit<char>);
20 }
21
22 } // namespace
23
24 NetworkingConfigService::AuthenticationResult::AuthenticationResult()
25 : authentication_state(NetworkingConfigService::NOTRY) {
26 }
27
28 NetworkingConfigService::AuthenticationResult::AuthenticationResult(
29 ExtensionId extension_id,
30 std::string guid,
31 AuthenticationState authentication_state)
32 : extension_id(extension_id),
33 guid(guid),
34 authentication_state(authentication_state) {
35 }
36
37 NetworkingConfigService::NetworkingConfigService(
38 scoped_ptr<EventDelegate> event_delegate,
39 ExtensionRegistry* extension_registry)
40 : registry_observer_(this), event_delegate_(event_delegate.Pass()) {
41 registry_observer_.Add(extension_registry);
42 }
43
44 NetworkingConfigService::~NetworkingConfigService() {
45 }
46
47 void NetworkingConfigService::OnExtensionUnloaded(
48 content::BrowserContext* browser_context,
49 const Extension* extension,
50 UnloadedExtensionInfo::Reason reason) {
51 UnregisterExtension(extension->id());
52 }
53
54 std::string NetworkingConfigService::LookupExtensionIdForHexSsid(
55 std::string hex_ssid) const {
56 // Transform hex_ssid to uppercase.
57 transform(hex_ssid.begin(), hex_ssid.end(), hex_ssid.begin(), toupper);
58
59 const auto it = hex_ssid_to_extension_id_.find(hex_ssid);
60 if (it == hex_ssid_to_extension_id_.end())
61 return std::string();
62 return it->second;
63 }
64
65 bool NetworkingConfigService::IsRegisteredForCaptivePortalEvent(
66 std::string extension_id) const {
67 return event_delegate_->HasExtensionRegisteredForEvent(extension_id);
68 }
69
70 bool NetworkingConfigService::RegisterHexSsid(std::string hex_ssid,
71 const std::string& extension_id) {
72 if (!IsValidNonEmptyHexString(hex_ssid)) {
73 LOG(ERROR) << "\'" << hex_ssid << "\' is not a valid hex encoded string.";
74 return false;
75 }
76
77 // Transform hex_ssid to uppercase.
78 transform(hex_ssid.begin(), hex_ssid.end(), hex_ssid.begin(), toupper);
79
80 return hex_ssid_to_extension_id_.insert(make_pair(hex_ssid, extension_id))
81 .second;
82 }
83
84 void NetworkingConfigService::UnregisterExtension(
85 const std::string& extension_id) {
86 for (auto it = hex_ssid_to_extension_id_.begin();
87 it != hex_ssid_to_extension_id_.end();) {
88 if (it->second == extension_id)
89 hex_ssid_to_extension_id_.erase(it++);
90 else
91 ++it;
92 }
93 }
94
95 const NetworkingConfigService::AuthenticationResult&
96 NetworkingConfigService::GetAuthenticationResult() const {
97 return authentication_result_;
98 }
99
100 void NetworkingConfigService::ResetAuthenticationResult() {
101 authentication_result_ = AuthenticationResult();
102 }
103
104 void NetworkingConfigService::SetAuthenticationResult(
105 const AuthenticationResult& authentication_result) {
106 authentication_result_ = authentication_result;
107 }
108
109 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698