summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/ash/networking_config_delegate_chromeos.cc
blob: d99974a40e6e61fe1ac1996b84adf5bd83912fc0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright (c) 2012 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 "chrome/browser/ui/ash/networking_config_delegate_chromeos.h"

#include <string>

#include "base/memory/scoped_ptr.h"
#include "base/strings/string_number_conversions.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chromeos/network/network_state.h"
#include "chromeos/network/network_state_handler.h"
#include "extensions/browser/api/networking_config/networking_config_service.h"
#include "extensions/browser/api/networking_config/networking_config_service_factory.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/common/extension.h"

namespace chromeos {

NetworkingConfigDelegateChromeos::NetworkingConfigDelegateChromeos() {
}

NetworkingConfigDelegateChromeos::~NetworkingConfigDelegateChromeos() {
}

scoped_ptr<const ash::NetworkingConfigDelegate::ExtensionInfo>
NetworkingConfigDelegateChromeos::LookUpExtensionForNetwork(
    const std::string& service_path) {
  chromeos::NetworkStateHandler* handler =
      chromeos::NetworkHandler::Get()->network_state_handler();
  const chromeos::NetworkState* network_state =
    handler->GetNetworkState(service_path);
  if (!network_state)
    return nullptr;
  std::string hex_ssid = network_state->GetHexSsid();
  Profile* profile = ProfileManager::GetActiveUserProfile();
  extensions::NetworkingConfigService* networking_config_service =
      extensions::NetworkingConfigServiceFactory::GetForBrowserContext(profile);
  const std::string extension_id =
      networking_config_service->LookupExtensionIdForHexSsid(hex_ssid);
  if (extension_id.empty())
    return nullptr;
  std::string extension_name = LookUpExtensionName(profile, extension_id);
  if (extension_name.empty())
    return scoped_ptr<const ash::NetworkingConfigDelegate::ExtensionInfo>();
  scoped_ptr<const ash::NetworkingConfigDelegate::ExtensionInfo> extension_info(
      new const ash::NetworkingConfigDelegate::ExtensionInfo(extension_id,
                                                             extension_name));
  return extension_info;
}

std::string NetworkingConfigDelegateChromeos::LookUpExtensionName(
    content::BrowserContext* context,
    std::string extension_id) const {
  extensions::ExtensionRegistry* extension_registry =
      extensions::ExtensionRegistry::Get(context);
  DCHECK(extension_registry);
  const extensions::Extension* extension = extension_registry->GetExtensionById(
      extension_id, extensions::ExtensionRegistry::ENABLED);
  if (extension == nullptr)
    return std::string();
  return extension->name();
}

}  // namespace chromeos