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

Side by Side Diff: chrome/browser/extensions/api/mdns/mdns_api.cc

Issue 1825913002: [Extensions] Convert APIs to use movable types [7] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Steven's Created 4 years, 8 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/api/mdns/mdns_api.h" 5 #include "chrome/browser/extensions/api/mdns/mdns_api.h"
6 6
7 #include <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 ++i_prev; 137 ++i_prev;
138 } 138 }
139 } 139 }
140 prev_service_counts_.swap(current_service_counts); 140 prev_service_counts_.swap(current_service_counts);
141 } 141 }
142 142
143 void MDnsAPI::OnDnsSdEvent(const std::string& service_type, 143 void MDnsAPI::OnDnsSdEvent(const std::string& service_type,
144 const DnsSdRegistry::DnsSdServiceList& services) { 144 const DnsSdRegistry::DnsSdServiceList& services) {
145 DCHECK(thread_checker_.CalledOnValidThread()); 145 DCHECK(thread_checker_.CalledOnValidThread());
146 146
147 std::vector<linked_ptr<mdns::MDnsService> > args; 147 std::vector<mdns::MDnsService> args;
148 for (DnsSdRegistry::DnsSdServiceList::const_iterator it = services.begin(); 148 for (const DnsSdService& service : services) {
149 it != services.end(); ++it) {
150 if (static_cast<int>(args.size()) == 149 if (static_cast<int>(args.size()) ==
151 api::mdns::MAX_SERVICE_INSTANCES_PER_EVENT) { 150 api::mdns::MAX_SERVICE_INSTANCES_PER_EVENT) {
152 // TODO(reddaly): This is not the most meaningful way of notifying the 151 // TODO(reddaly): This is not the most meaningful way of notifying the
153 // application that something bad happened. It will go to the user's 152 // application that something bad happened. It will go to the user's
154 // console (which most users don't look at)and the developer will be none 153 // console (which most users don't look at)and the developer will be none
155 // the wiser. Instead, changing the event to pass the number of 154 // the wiser. Instead, changing the event to pass the number of
156 // discovered instances would allow the caller to know when the list is 155 // discovered instances would allow the caller to know when the list is
157 // truncated and tell the user something meaningful in the extension/app. 156 // truncated and tell the user something meaningful in the extension/app.
158 WriteToConsole(service_type, 157 WriteToConsole(service_type,
159 content::CONSOLE_MESSAGE_LEVEL_WARNING, 158 content::CONSOLE_MESSAGE_LEVEL_WARNING,
160 base::StringPrintf( 159 base::StringPrintf(
161 "Truncating number of service instances in " 160 "Truncating number of service instances in "
162 "onServiceList to maximum allowed: %d", 161 "onServiceList to maximum allowed: %d",
163 api::mdns::MAX_SERVICE_INSTANCES_PER_EVENT)); 162 api::mdns::MAX_SERVICE_INSTANCES_PER_EVENT));
164 break; 163 break;
165 } 164 }
166 linked_ptr<mdns::MDnsService> mdns_service = 165 mdns::MDnsService mdns_service;
167 make_linked_ptr(new mdns::MDnsService); 166 mdns_service.service_name = service.service_name;
168 mdns_service->service_name = (*it).service_name; 167 mdns_service.service_host_port = service.service_host_port;
169 mdns_service->service_host_port = (*it).service_host_port; 168 mdns_service.ip_address = service.ip_address;
170 mdns_service->ip_address = (*it).ip_address; 169 mdns_service.service_data = service.service_data;
171 mdns_service->service_data = (*it).service_data; 170 args.push_back(std::move(mdns_service));
172 args.push_back(mdns_service);
173 } 171 }
174 172
175 scoped_ptr<base::ListValue> results = mdns::OnServiceList::Create(args); 173 scoped_ptr<base::ListValue> results = mdns::OnServiceList::Create(args);
176 scoped_ptr<Event> event(new Event(events::MDNS_ON_SERVICE_LIST, 174 scoped_ptr<Event> event(new Event(events::MDNS_ON_SERVICE_LIST,
177 mdns::OnServiceList::kEventName, 175 mdns::OnServiceList::kEventName,
178 std::move(results))); 176 std::move(results)));
179 event->restrict_to_browser_context = browser_context_; 177 event->restrict_to_browser_context = browser_context_;
180 event->filter_info.SetServiceType(service_type); 178 event->filter_info.SetServiceType(service_type);
181 179
182 // TODO(justinlin): To avoid having listeners without filters getting all 180 // TODO(justinlin): To avoid having listeners without filters getting all
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 AsyncApiFunction::ResponseAction MdnsForceDiscoveryFunction::Run() { 266 AsyncApiFunction::ResponseAction MdnsForceDiscoveryFunction::Run() {
269 MDnsAPI* api = MDnsAPI::Get(browser_context()); 267 MDnsAPI* api = MDnsAPI::Get(browser_context());
270 if (!api) { 268 if (!api) {
271 return RespondNow(Error("Unknown error.")); 269 return RespondNow(Error("Unknown error."));
272 } 270 }
273 api->ForceDiscovery(); 271 api->ForceDiscovery();
274 return RespondNow(NoArguments()); 272 return RespondNow(NoArguments());
275 } 273 }
276 274
277 } // namespace extensions 275 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698