OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/gcd_private/gcd_private_api.h" | 5 #include "chrome/browser/extensions/api/gcd_private/gcd_private_api.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "chrome/browser/local_discovery/cloud_device_list.h" | 9 #include "chrome/browser/local_discovery/cloud_device_list.h" |
10 #include "chrome/browser/local_discovery/cloud_print_printer_list.h" | 10 #include "chrome/browser/local_discovery/cloud_print_printer_list.h" |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 for (GCDDeviceMap::iterator i = known_devices_.begin(); | 161 for (GCDDeviceMap::iterator i = known_devices_.begin(); |
162 i != known_devices_.end(); | 162 i != known_devices_.end(); |
163 i++) { | 163 i++) { |
164 EventRouter::Get(browser_context_) | 164 EventRouter::Get(browser_context_) |
165 ->BroadcastEvent(MakeDeviceRemovedEvent(i->second->device_id)); | 165 ->BroadcastEvent(MakeDeviceRemovedEvent(i->second->device_id)); |
166 } | 166 } |
167 | 167 |
168 known_devices_.clear(); | 168 known_devices_.clear(); |
169 } | 169 } |
170 | 170 |
| 171 bool GcdPrivateAPI::QueryForDevices() { |
| 172 if (!privet_device_lister_) |
| 173 return false; |
| 174 |
| 175 privet_device_lister_->DiscoverNewDevices(true); |
| 176 |
| 177 return true; |
| 178 } |
| 179 |
171 // static | 180 // static |
172 void GcdPrivateAPI::SetGCDApiFlowFactoryForTests( | 181 void GcdPrivateAPI::SetGCDApiFlowFactoryForTests( |
173 GCDApiFlowFactoryForTests* factory) { | 182 GCDApiFlowFactoryForTests* factory) { |
174 g_gcd_api_flow_factory = factory; | 183 g_gcd_api_flow_factory = factory; |
175 } | 184 } |
176 | 185 |
177 GcdPrivateGetCloudDeviceListFunction::GcdPrivateGetCloudDeviceListFunction() { | 186 GcdPrivateGetCloudDeviceListFunction::GcdPrivateGetCloudDeviceListFunction() { |
178 } | 187 } |
| 188 |
179 GcdPrivateGetCloudDeviceListFunction::~GcdPrivateGetCloudDeviceListFunction() { | 189 GcdPrivateGetCloudDeviceListFunction::~GcdPrivateGetCloudDeviceListFunction() { |
180 } | 190 } |
181 | 191 |
182 bool GcdPrivateGetCloudDeviceListFunction::RunAsync() { | 192 bool GcdPrivateGetCloudDeviceListFunction::RunAsync() { |
183 requests_succeeded_ = 0; | 193 requests_succeeded_ = 0; |
184 requests_failed_ = 0; | 194 requests_failed_ = 0; |
185 | 195 |
186 printer_list_ = MakeGCDApiFlow(GetProfile()); | 196 printer_list_ = MakeGCDApiFlow(GetProfile()); |
187 device_list_ = MakeGCDApiFlow(GetProfile()); | 197 device_list_ = MakeGCDApiFlow(GetProfile()); |
188 | 198 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 | 261 |
252 GcdPrivateQueryForNewLocalDevicesFunction:: | 262 GcdPrivateQueryForNewLocalDevicesFunction:: |
253 GcdPrivateQueryForNewLocalDevicesFunction() { | 263 GcdPrivateQueryForNewLocalDevicesFunction() { |
254 } | 264 } |
255 | 265 |
256 GcdPrivateQueryForNewLocalDevicesFunction:: | 266 GcdPrivateQueryForNewLocalDevicesFunction:: |
257 ~GcdPrivateQueryForNewLocalDevicesFunction() { | 267 ~GcdPrivateQueryForNewLocalDevicesFunction() { |
258 } | 268 } |
259 | 269 |
260 bool GcdPrivateQueryForNewLocalDevicesFunction::RunSync() { | 270 bool GcdPrivateQueryForNewLocalDevicesFunction::RunSync() { |
261 return false; | 271 GcdPrivateAPI* gcd_api = |
| 272 BrowserContextKeyedAPIFactory<GcdPrivateAPI>::Get(GetProfile()); |
| 273 |
| 274 if (!gcd_api) |
| 275 return false; |
| 276 |
| 277 if (!gcd_api->QueryForDevices()) { |
| 278 error_ = |
| 279 "You must first subscribe to onDeviceStateChanged or onDeviceRemoved " |
| 280 "notifications"; |
| 281 return false; |
| 282 } |
| 283 |
| 284 return true; |
262 } | 285 } |
263 | 286 |
264 GcdPrivateStartSetupFunction::GcdPrivateStartSetupFunction() { | 287 GcdPrivateStartSetupFunction::GcdPrivateStartSetupFunction() { |
265 } | 288 } |
266 | 289 |
267 GcdPrivateStartSetupFunction::~GcdPrivateStartSetupFunction() { | 290 GcdPrivateStartSetupFunction::~GcdPrivateStartSetupFunction() { |
268 } | 291 } |
269 | 292 |
270 bool GcdPrivateStartSetupFunction::RunAsync() { | 293 bool GcdPrivateStartSetupFunction::RunAsync() { |
271 return false; | 294 return false; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 } | 380 } |
358 | 381 |
359 GcdPrivateGetCommandsListFunction::~GcdPrivateGetCommandsListFunction() { | 382 GcdPrivateGetCommandsListFunction::~GcdPrivateGetCommandsListFunction() { |
360 } | 383 } |
361 | 384 |
362 bool GcdPrivateGetCommandsListFunction::RunAsync() { | 385 bool GcdPrivateGetCommandsListFunction::RunAsync() { |
363 return false; | 386 return false; |
364 } | 387 } |
365 | 388 |
366 } // namespace extensions | 389 } // namespace extensions |
OLD | NEW |