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

Side by Side Diff: chrome/browser/extensions/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: 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 "chrome/browser/extensions/api/networking_config/networking_config_serv ice.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::NetworkingConfigService(
29 scoped_ptr<EventDelegate> event_delegate,
30 ExtensionRegistry* extension_registry)
31 : registry_observer_(this), event_delegate_(event_delegate.Pass()) {
32 registry_observer_.Add(extension_registry);
33 }
34
35 NetworkingConfigService::~NetworkingConfigService() {
36 }
37
38 void NetworkingConfigService::OnExtensionUnloaded(
39 content::BrowserContext* browser_context,
40 const Extension* extension,
41 UnloadedExtensionInfo::Reason reason) {
42 UnregisterExtension(extension->id());
43 }
44
45 std::string NetworkingConfigService::GetExtensionIdForHexSsid(
46 std::string hex_ssid) const {
47 // Transform hex_ssid to uppercase.
48 transform(hex_ssid.begin(), hex_ssid.end(), hex_ssid.begin(), toupper);
49
50 const auto it = hex_ssid_to_extension_id_.find(hex_ssid);
51 if (it == hex_ssid_to_extension_id_.end())
52 return std::string();
53 return it->second;
54 }
55
56 bool NetworkingConfigService::HasExtensionRegisteredForEvent(
57 std::string extension_id) const {
58 return event_delegate_->HasExtensionRegisteredForEvent(extension_id);
59 }
60
61 bool NetworkingConfigService::RegisterHexSsid(std::string hex_ssid,
62 const std::string& extension_id) {
63 if (!IsValidNonEmptyHexString(hex_ssid)) {
64 LOG(ERROR) << "\'" << hex_ssid << "\' is not a valid hex encoded string.";
65 return false;
66 }
67
68 // Transform hex_ssid to uppercase.
69 transform(hex_ssid.begin(), hex_ssid.end(), hex_ssid.begin(), toupper);
70
71 return hex_ssid_to_extension_id_.insert(make_pair(hex_ssid, extension_id))
72 .second;
73 }
74
75 void NetworkingConfigService::UnregisterExtension(
76 const std::string& extension_id) {
77 for (auto it = hex_ssid_to_extension_id_.begin();
78 it != hex_ssid_to_extension_id_.end();) {
79 if (it->second == extension_id)
80 hex_ssid_to_extension_id_.erase(it++);
81 else
82 ++it;
83 }
84 }
85
86 const NetworkingConfigService::AuthenticationResult&
87 NetworkingConfigService::GetAuthenticationResult() const {
88 return authentication_result_;
89 }
90
91 void NetworkingConfigService::ResetAuthenticationResult() {
92 authentication_result_ = AuthenticationResult();
93 }
94
95 void NetworkingConfigService::SetAuthenticationResult(
96 const AuthenticationResult& authentication_result) {
97 authentication_result_ = authentication_result;
98 }
99
100 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698