Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / chrome / browser / net / service_providers_win.cc
blob17b8469f9aedce1047869129652d99ef8c6df04d
1 // Copyright (c) 2011 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/net/service_providers_win.h"
7 #include <winsock2.h>
8 #include <Ws2spi.h>
10 #include "base/logging.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/values.h"
14 WinsockLayeredServiceProvider::WinsockLayeredServiceProvider() {
17 WinsockLayeredServiceProvider::~WinsockLayeredServiceProvider() {
20 void GetWinsockNamespaceProviders(
21 WinsockNamespaceProviderList* namespace_list) {
23 // Find out how just how much memory is needed. If we get the expected error,
24 // the memory needed is written to size.
25 DWORD size = 0;
26 if (WSAEnumNameSpaceProviders(&size, NULL) != SOCKET_ERROR ||
27 GetLastError() != WSAEFAULT) {
28 NOTREACHED();
29 return;
32 scoped_ptr<char[]> namespace_provider_bytes(new char[size]);
33 WSANAMESPACE_INFO* namespace_providers =
34 reinterpret_cast<WSANAMESPACE_INFO*>(namespace_provider_bytes.get());
36 int num_namespace_providers = WSAEnumNameSpaceProviders(&size,
37 namespace_providers);
38 if (num_namespace_providers == SOCKET_ERROR) {
39 NOTREACHED();
40 return;
43 for (int i = 0; i < num_namespace_providers; ++i) {
44 WinsockNamespaceProvider provider;
46 provider.name = namespace_providers[i].lpszIdentifier;
47 provider.active = TRUE == namespace_providers[i].fActive;
48 provider.version = namespace_providers[i].dwVersion;
49 provider.type = namespace_providers[i].dwNameSpace;
51 namespace_list->push_back(provider);
55 void GetWinsockLayeredServiceProviders(
56 WinsockLayeredServiceProviderList* service_list) {
57 // Find out how just how much memory is needed. If we get the expected error,
58 // the memory needed is written to size.
59 DWORD size = 0;
60 int error;
61 if (SOCKET_ERROR != WSCEnumProtocols(NULL, NULL, &size, &error) ||
62 error != WSAENOBUFS) {
63 NOTREACHED();
64 return;
67 scoped_ptr<char[]> service_provider_bytes(new char[size]);
68 WSAPROTOCOL_INFOW* service_providers =
69 reinterpret_cast<WSAPROTOCOL_INFOW*>(service_provider_bytes.get());
71 int num_service_providers = WSCEnumProtocols(NULL, service_providers, &size,
72 &error);
73 if (num_service_providers == SOCKET_ERROR) {
74 NOTREACHED();
75 return;
78 for (int i = 0; i < num_service_providers; ++i) {
79 WinsockLayeredServiceProvider service_provider;
81 service_provider.name = service_providers[i].szProtocol;
82 service_provider.version = service_providers[i].iVersion;
83 service_provider.socket_type = service_providers[i].iSocketType;
84 service_provider.socket_protocol = service_providers[i].iProtocol;
85 service_provider.chain_length = service_providers[i].ProtocolChain.ChainLen;
87 // TODO(mmenke): Add categories under Vista and later.
88 // http://msdn.microsoft.com/en-us/library/ms742239%28v=VS.85%29.aspx
90 wchar_t path[MAX_PATH];
91 int path_length = arraysize(path);
92 if (0 == WSCGetProviderPath(&service_providers[i].ProviderId, path,
93 &path_length, &error)) {
94 service_provider.path = path;
97 service_list->push_back(service_provider);
100 return;