Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / extensions / common / api / sockets / sockets_manifest_data.cc
blobb68964c87cf64eb9716125e6d5e3e129f42304cc
1 // Copyright 2014 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 "extensions/common/api/sockets/sockets_manifest_data.h"
7 #include "extensions/common/api/sockets/sockets_manifest_permission.h"
8 #include "extensions/common/manifest_constants.h"
10 namespace extensions {
12 SocketsManifestData::SocketsManifestData(
13 scoped_ptr<SocketsManifestPermission> permission)
14 : permission_(permission.Pass()) {
15 DCHECK(permission_);
18 SocketsManifestData::~SocketsManifestData() {}
20 // static
21 SocketsManifestData* SocketsManifestData::Get(const Extension* extension) {
22 return static_cast<SocketsManifestData*>(
23 extension->GetManifestData(manifest_keys::kSockets));
26 // static
27 bool SocketsManifestData::CheckRequest(
28 const Extension* extension,
29 const content::SocketPermissionRequest& request) {
30 const SocketsManifestData* data = SocketsManifestData::Get(extension);
31 if (data)
32 return data->permission()->CheckRequest(extension, request);
34 return false;
37 // static
38 scoped_ptr<SocketsManifestData> SocketsManifestData::FromValue(
39 const base::Value& value,
40 base::string16* error) {
41 scoped_ptr<SocketsManifestPermission> permission =
42 SocketsManifestPermission::FromValue(value, error);
43 if (!permission)
44 return scoped_ptr<SocketsManifestData>();
46 return scoped_ptr<SocketsManifestData>(
47 new SocketsManifestData(permission.Pass())).Pass();
50 } // namespace extensions