Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / ui / ash / networking_config_delegate_chromeos.cc
blobd99974a40e6e61fe1ac1996b84adf5bd83912fc0
1 // Copyright (c) 2012 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.
5 #include "chrome/browser/ui/ash/networking_config_delegate_chromeos.h"
7 #include <string>
9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/string_number_conversions.h"
11 #include "chrome/browser/profiles/profile_manager.h"
12 #include "chromeos/network/network_state.h"
13 #include "chromeos/network/network_state_handler.h"
14 #include "extensions/browser/api/networking_config/networking_config_service.h"
15 #include "extensions/browser/api/networking_config/networking_config_service_factory.h"
16 #include "extensions/browser/extension_registry.h"
17 #include "extensions/common/extension.h"
19 namespace chromeos {
21 NetworkingConfigDelegateChromeos::NetworkingConfigDelegateChromeos() {
24 NetworkingConfigDelegateChromeos::~NetworkingConfigDelegateChromeos() {
27 scoped_ptr<const ash::NetworkingConfigDelegate::ExtensionInfo>
28 NetworkingConfigDelegateChromeos::LookUpExtensionForNetwork(
29 const std::string& service_path) {
30 chromeos::NetworkStateHandler* handler =
31 chromeos::NetworkHandler::Get()->network_state_handler();
32 const chromeos::NetworkState* network_state =
33 handler->GetNetworkState(service_path);
34 if (!network_state)
35 return nullptr;
36 std::string hex_ssid = network_state->GetHexSsid();
37 Profile* profile = ProfileManager::GetActiveUserProfile();
38 extensions::NetworkingConfigService* networking_config_service =
39 extensions::NetworkingConfigServiceFactory::GetForBrowserContext(profile);
40 const std::string extension_id =
41 networking_config_service->LookupExtensionIdForHexSsid(hex_ssid);
42 if (extension_id.empty())
43 return nullptr;
44 std::string extension_name = LookUpExtensionName(profile, extension_id);
45 if (extension_name.empty())
46 return scoped_ptr<const ash::NetworkingConfigDelegate::ExtensionInfo>();
47 scoped_ptr<const ash::NetworkingConfigDelegate::ExtensionInfo> extension_info(
48 new const ash::NetworkingConfigDelegate::ExtensionInfo(extension_id,
49 extension_name));
50 return extension_info;
53 std::string NetworkingConfigDelegateChromeos::LookUpExtensionName(
54 content::BrowserContext* context,
55 std::string extension_id) const {
56 extensions::ExtensionRegistry* extension_registry =
57 extensions::ExtensionRegistry::Get(context);
58 DCHECK(extension_registry);
59 const extensions::Extension* extension = extension_registry->GetExtensionById(
60 extension_id, extensions::ExtensionRegistry::ENABLED);
61 if (extension == nullptr)
62 return std::string();
63 return extension->name();
66 } // namespace chromeos