| 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 | |
| 166 // static | 157 // static |
| 167 void GcdPrivateAPI::SetGCDApiFlowFactoryForTests( | 158 void GcdPrivateAPI::SetGCDApiFlowFactoryForTests( |
| 168 GCDApiFlowFactoryForTests* factory) { | 159 GCDApiFlowFactoryForTests* factory) { |
| 169 g_gcd_api_flow_factory = factory; | 160 g_gcd_api_flow_factory = factory; |
| 170 } | 161 } |
| 171 | 162 |
| 172 GcdPrivateGetCloudDeviceListFunction::GcdPrivateGetCloudDeviceListFunction() { | 163 GcdPrivateGetCloudDeviceListFunction::GcdPrivateGetCloudDeviceListFunction() { |
| 173 } | 164 } |
| 174 GcdPrivateGetCloudDeviceListFunction::~GcdPrivateGetCloudDeviceListFunction() { | 165 GcdPrivateGetCloudDeviceListFunction::~GcdPrivateGetCloudDeviceListFunction() { |
| 175 } | 166 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 | 228 |
| 238 devices.push_back(device); | 229 devices.push_back(device); |
| 239 } | 230 } |
| 240 | 231 |
| 241 results_ = gcd_private::GetCloudDeviceList::Results::Create(devices); | 232 results_ = gcd_private::GetCloudDeviceList::Results::Create(devices); |
| 242 | 233 |
| 243 SendResponse(true); | 234 SendResponse(true); |
| 244 Release(); | 235 Release(); |
| 245 } | 236 } |
| 246 | 237 |
| 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 | |
| 270 GcdPrivateStartSetupFunction::GcdPrivateStartSetupFunction() { | 238 GcdPrivateStartSetupFunction::GcdPrivateStartSetupFunction() { |
| 271 } | 239 } |
| 272 | 240 |
| 273 GcdPrivateStartSetupFunction::~GcdPrivateStartSetupFunction() { | 241 GcdPrivateStartSetupFunction::~GcdPrivateStartSetupFunction() { |
| 274 } | 242 } |
| 275 | 243 |
| 276 bool GcdPrivateStartSetupFunction::RunAsync() { | 244 bool GcdPrivateStartSetupFunction::RunAsync() { |
| 277 return false; | 245 return false; |
| 278 } | 246 } |
| 279 | 247 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 } | 279 } |
| 312 | 280 |
| 313 GcdPrivateStopSetupFunction::~GcdPrivateStopSetupFunction() { | 281 GcdPrivateStopSetupFunction::~GcdPrivateStopSetupFunction() { |
| 314 } | 282 } |
| 315 | 283 |
| 316 bool GcdPrivateStopSetupFunction::RunAsync() { | 284 bool GcdPrivateStopSetupFunction::RunAsync() { |
| 317 return false; | 285 return false; |
| 318 } | 286 } |
| 319 | 287 |
| 320 } // namespace extensions | 288 } // namespace extensions |
| OLD | NEW |