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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 for (GCDDeviceMap::iterator i = known_devices_.begin(); | 147 for (GCDDeviceMap::iterator i = known_devices_.begin(); |
148 i != known_devices_.end(); | 148 i != known_devices_.end(); |
149 i++) { | 149 i++) { |
150 EventRouter::Get(browser_context_) | 150 EventRouter::Get(browser_context_) |
151 ->BroadcastEvent(MakeCloudDeviceStateChangedEvent(false, *i->second)); | 151 ->BroadcastEvent(MakeCloudDeviceStateChangedEvent(false, *i->second)); |
152 } | 152 } |
153 | 153 |
154 known_devices_.clear(); | 154 known_devices_.clear(); |
155 } | 155 } |
156 | 156 |
| 157 bool GcdPrivateAPI::QueryForDevices() { |
| 158 if (!privet_device_lister_) |
| 159 return false; |
| 160 |
| 161 privet_device_lister_->DiscoverNewDevices(true); |
| 162 |
| 163 return true; |
| 164 } |
| 165 |
157 // static | 166 // static |
158 void GcdPrivateAPI::SetGCDApiFlowFactoryForTests( | 167 void GcdPrivateAPI::SetGCDApiFlowFactoryForTests( |
159 GCDApiFlowFactoryForTests* factory) { | 168 GCDApiFlowFactoryForTests* factory) { |
160 g_gcd_api_flow_factory = factory; | 169 g_gcd_api_flow_factory = factory; |
161 } | 170 } |
162 | 171 |
163 GcdPrivateGetCloudDeviceListFunction::GcdPrivateGetCloudDeviceListFunction() { | 172 GcdPrivateGetCloudDeviceListFunction::GcdPrivateGetCloudDeviceListFunction() { |
164 } | 173 } |
165 GcdPrivateGetCloudDeviceListFunction::~GcdPrivateGetCloudDeviceListFunction() { | 174 GcdPrivateGetCloudDeviceListFunction::~GcdPrivateGetCloudDeviceListFunction() { |
166 } | 175 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 | 237 |
229 devices.push_back(device); | 238 devices.push_back(device); |
230 } | 239 } |
231 | 240 |
232 results_ = gcd_private::GetCloudDeviceList::Results::Create(devices); | 241 results_ = gcd_private::GetCloudDeviceList::Results::Create(devices); |
233 | 242 |
234 SendResponse(true); | 243 SendResponse(true); |
235 Release(); | 244 Release(); |
236 } | 245 } |
237 | 246 |
| 247 GcdPrivateQueryForNewLocalDevicesFunction:: |
| 248 GcdPrivateQueryForNewLocalDevicesFunction() { |
| 249 } |
| 250 |
| 251 GcdPrivateQueryForNewLocalDevicesFunction:: |
| 252 ~GcdPrivateQueryForNewLocalDevicesFunction() { |
| 253 } |
| 254 |
| 255 bool GcdPrivateQueryForNewLocalDevicesFunction::RunSync() { |
| 256 GcdPrivateAPI* gcd_api = |
| 257 BrowserContextKeyedAPIFactory<GcdPrivateAPI>::Get(GetProfile()); |
| 258 |
| 259 if (!gcd_api) |
| 260 return false; |
| 261 |
| 262 if (!gcd_api->QueryForDevices()) { |
| 263 error_ = "You must first subscribe to onDeviceStateChanged notifications"; |
| 264 return false; |
| 265 } |
| 266 |
| 267 return true; |
| 268 } |
| 269 |
238 GcdPrivateStartSetupFunction::GcdPrivateStartSetupFunction() { | 270 GcdPrivateStartSetupFunction::GcdPrivateStartSetupFunction() { |
239 } | 271 } |
240 | 272 |
241 GcdPrivateStartSetupFunction::~GcdPrivateStartSetupFunction() { | 273 GcdPrivateStartSetupFunction::~GcdPrivateStartSetupFunction() { |
242 } | 274 } |
243 | 275 |
244 bool GcdPrivateStartSetupFunction::RunAsync() { | 276 bool GcdPrivateStartSetupFunction::RunAsync() { |
245 return false; | 277 return false; |
246 } | 278 } |
247 | 279 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 } | 311 } |
280 | 312 |
281 GcdPrivateStopSetupFunction::~GcdPrivateStopSetupFunction() { | 313 GcdPrivateStopSetupFunction::~GcdPrivateStopSetupFunction() { |
282 } | 314 } |
283 | 315 |
284 bool GcdPrivateStopSetupFunction::RunAsync() { | 316 bool GcdPrivateStopSetupFunction::RunAsync() { |
285 return false; | 317 return false; |
286 } | 318 } |
287 | 319 |
288 } // namespace extensions | 320 } // namespace extensions |
OLD | NEW |