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

Side by Side Diff: chrome/common/extensions/api/mdns/mdns_manifest_handler.cc

Issue 23437015: Initial chrome.mdns API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 3 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 (c) 2013 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 "chrome/common/extensions/api/mdns/mdns_manifest_handler.h"
6
7 #include "base/lazy_instance.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "base/values.h"
11 #include "chrome/common/extensions/extension_manifest_constants.h"
12 #include "extensions/common/error_utils.h"
13
14 namespace keys = extensions::manifest_keys;
15 namespace errors = extension_manifest_errors;
16
17 namespace extensions {
18
19 namespace {
20 // Whitelisted MDns service types.
21 const char kCastDeviceType[] = "_googlecast._tcp.local";
22 }
23
24 MDnsInfo::MDnsInfo() {}
25 MDnsInfo::~MDnsInfo() {}
26
27 static base::LazyInstance<MDnsInfo> g_empty_mdns_info =
28 LAZY_INSTANCE_INITIALIZER;
29
30 // static
31 const MDnsInfo& MDnsInfo::GetMDnsInfo(const Extension* extension) {
32 MDnsInfo* info = static_cast<MDnsInfo*>(
33 extension->GetManifestData(keys::kMDnsServiceTypes));
34 return info ? *info : g_empty_mdns_info.Get();
35 }
36
37 MDnsManifestHandler::MDnsManifestHandler() {}
38 MDnsManifestHandler::~MDnsManifestHandler() {}
39
40 bool MDnsManifestHandler::Parse(Extension* extension, string16* error) {
41 scoped_ptr<MDnsInfo> info(new MDnsInfo);
42 const base::ListValue* list = NULL;
43 if (!extension->manifest()->GetList(keys::kMDnsServiceTypes, &list)) {
44 *error = ASCIIToUTF16(errors::kInvalidMDnsServiceTypes);
45 return false;
46 }
47
48 for (size_t i = 0; i < list->GetSize(); ++i) {
49 std::string service_type;
50 if (!list->GetString(i, &service_type) ||
51 service_type != kCastDeviceType) {
52 *error = ASCIIToUTF16(errors::kInvalidMDnsServiceTypes);
53 return false;
54 }
55 info->service_types.push_back(service_type);
56 }
57
58 extension->SetManifestData(keys::kMDnsServiceTypes, info.release());
59 return true;
60 }
61
62 const std::vector<std::string> MDnsManifestHandler::Keys() const {
63 return SingleKey(keys::kMDnsServiceTypes);
64 }
65
66 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698