Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "extensions/browser/api/printer_provider/printer_provider_api.h" | 5 #include "extensions/browser/api/printer_provider/printer_provider_api.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/i18n/rtl.h" | 13 #include "base/i18n/rtl.h" |
| 14 #include "base/json/json_string_value_serializer.h" | 14 #include "base/json/json_string_value_serializer.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/ref_counted_memory.h" | 16 #include "base/memory/ref_counted_memory.h" |
| 17 #include "base/scoped_observer.h" | 17 #include "base/scoped_observer.h" |
| 18 #include "base/strings/string16.h" | 18 #include "base/strings/string16.h" |
| 19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 20 #include "base/values.h" | 20 #include "base/values.h" |
| 21 #include "device/core/device_client.h" | |
| 22 #include "device/usb/usb_device.h" | |
| 23 #include "device/usb/usb_service.h" | |
| 24 #include "extensions/browser/api/device_permissions_manager.h" | |
| 21 #include "extensions/browser/api/printer_provider/printer_provider_print_job.h" | 25 #include "extensions/browser/api/printer_provider/printer_provider_print_job.h" |
| 22 #include "extensions/browser/api/printer_provider_internal/printer_provider_inte rnal_api.h" | 26 #include "extensions/browser/api/printer_provider_internal/printer_provider_inte rnal_api.h" |
| 23 #include "extensions/browser/api/printer_provider_internal/printer_provider_inte rnal_api_observer.h" | 27 #include "extensions/browser/api/printer_provider_internal/printer_provider_inte rnal_api_observer.h" |
| 24 #include "extensions/browser/event_router.h" | 28 #include "extensions/browser/event_router.h" |
| 25 #include "extensions/browser/extension_registry.h" | 29 #include "extensions/browser/extension_registry.h" |
| 26 #include "extensions/browser/extension_registry_observer.h" | 30 #include "extensions/browser/extension_registry_observer.h" |
| 27 #include "extensions/common/api/printer_provider.h" | 31 #include "extensions/common/api/printer_provider.h" |
| 28 #include "extensions/common/api/printer_provider_internal.h" | 32 #include "extensions/common/api/printer_provider_internal.h" |
| 33 #include "extensions/common/api/usb.h" | |
| 29 #include "extensions/common/extension.h" | 34 #include "extensions/common/extension.h" |
| 30 | 35 |
| 36 using device::UsbDevice; | |
| 37 using device::UsbService; | |
| 38 | |
| 31 namespace extensions { | 39 namespace extensions { |
| 32 | 40 |
| 33 namespace { | 41 namespace { |
| 34 | 42 |
| 35 // The separator between extension id and the extension's internal printer id | 43 // The separator between extension id and the extension's internal printer id |
| 36 // used when generating a printer id unique across extensions. | 44 // used when generating a printer id unique across extensions. |
| 37 const char kPrinterIdSeparator = ':'; | 45 const char kPrinterIdSeparator = ':'; |
| 38 | 46 |
| 39 // Given an extension ID and an ID of a printer reported by the extension, it | 47 // Given an extension ID and an ID of a printer reported by the extension, it |
| 40 // generates a ID for the printer unique across extensions (assuming that the | 48 // generates a ID for the printer unique across extensions (assuming that the |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 // values reported by the extension. | 115 // values reported by the extension. |
| 108 bool CompleteForExtension(const std::string& extension_id, | 116 bool CompleteForExtension(const std::string& extension_id, |
| 109 int request_id, | 117 int request_id, |
| 110 const base::ListValue& result); | 118 const base::ListValue& result); |
| 111 | 119 |
| 112 // Runs callbacks for the extension for all requests that are waiting for a | 120 // Runs callbacks for the extension for all requests that are waiting for a |
| 113 // response from the extension with the provided extension id. Callbacks are | 121 // response from the extension with the provided extension id. Callbacks are |
| 114 // called as if the extension reported empty set of printers. | 122 // called as if the extension reported empty set of printers. |
| 115 void FailAllForExtension(const std::string& extension_id); | 123 void FailAllForExtension(const std::string& extension_id); |
| 116 | 124 |
| 117 // Adds an extension id to the list of the extensions that need to respond | 125 // Adds an extension id to the list of the extensions that need to respond to |
| 118 // to the event. | 126 // the event. |
| 119 bool AddSource(int request_id, const std::string& extension_id); | 127 bool AddSource(int request_id, const std::string& extension_id); |
| 120 | 128 |
| 121 private: | 129 private: |
| 122 int last_request_id_; | 130 int last_request_id_; |
| 123 std::map<int, GetPrintersRequest> pending_requests_; | 131 std::map<int, GetPrintersRequest> pending_requests_; |
| 124 | 132 |
| 125 DISALLOW_COPY_AND_ASSIGN(PendingGetPrintersRequests); | 133 DISALLOW_COPY_AND_ASSIGN(PendingGetPrintersRequests); |
| 126 }; | 134 }; |
| 127 | 135 |
| 128 // Keeps track of pending chrome.printerProvider.onGetCapabilityRequested | 136 // Keeps track of pending chrome.printerProvider.onGetCapabilityRequested |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 142 | 150 |
| 143 // Runs all pending callbacks with empty capability value and clears the | 151 // Runs all pending callbacks with empty capability value and clears the |
| 144 // set of pending requests. | 152 // set of pending requests. |
| 145 void FailAll(); | 153 void FailAll(); |
| 146 | 154 |
| 147 private: | 155 private: |
| 148 int last_request_id_; | 156 int last_request_id_; |
| 149 std::map<int, PrinterProviderAPI::GetCapabilityCallback> pending_requests_; | 157 std::map<int, PrinterProviderAPI::GetCapabilityCallback> pending_requests_; |
| 150 }; | 158 }; |
| 151 | 159 |
| 152 // Keeps track of pending chrome.printerProvider.ontPrintRequested requests | 160 // Keeps track of pending chrome.printerProvider.onPrintRequested requests |
| 153 // for an extension. | 161 // for an extension. |
| 154 class PendingPrintRequests { | 162 class PendingPrintRequests { |
| 155 public: | 163 public: |
| 156 PendingPrintRequests(); | 164 PendingPrintRequests(); |
| 157 ~PendingPrintRequests(); | 165 ~PendingPrintRequests(); |
| 158 | 166 |
| 159 // Adds a new request to the set. Only information needed is the callback | 167 // Adds a new request to the set. Only information needed is the callback |
| 160 // associated with the request. Returns the id assigned to the request. | 168 // associated with the request. Returns the id assigned to the request. |
| 161 int Add(const PrinterProviderPrintJob& job, | 169 int Add(const PrinterProviderPrintJob& job, |
| 162 const PrinterProviderAPI::PrintCallback& callback); | 170 const PrinterProviderAPI::PrintCallback& callback); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 175 private: | 183 private: |
| 176 struct PrintRequest { | 184 struct PrintRequest { |
| 177 PrinterProviderAPI::PrintCallback callback; | 185 PrinterProviderAPI::PrintCallback callback; |
| 178 PrinterProviderPrintJob job; | 186 PrinterProviderPrintJob job; |
| 179 }; | 187 }; |
| 180 | 188 |
| 181 int last_request_id_; | 189 int last_request_id_; |
| 182 std::map<int, PrintRequest> pending_requests_; | 190 std::map<int, PrintRequest> pending_requests_; |
| 183 }; | 191 }; |
| 184 | 192 |
| 193 // Keeps track of pending chrome.printerProvider.onUsbAccessGranted requests | |
| 194 // for an extension. | |
| 195 class PendingUsbPrinterInfoRequests { | |
| 196 public: | |
| 197 PendingUsbPrinterInfoRequests(); | |
| 198 ~PendingUsbPrinterInfoRequests(); | |
| 199 | |
| 200 // Adds a new request to the set. Only information needed is the callback | |
| 201 // associated with the request. Returns the id assigned to the request. | |
| 202 int Add(const PrinterProviderAPI::UsbAccessGrantedCallback& callback); | |
| 203 | |
| 204 // Completes the request with the provided request id. It runs the request | |
| 205 // callback and removes the request from the set. | |
| 206 void Complete(int request_id, | |
| 207 const core_api::printer_provider::PrinterInfo* printer_info); | |
| 208 | |
| 209 // Runs all pending callbacks with empty capability value and clears the | |
| 210 // set of pending requests. | |
| 211 void FailAll(); | |
| 212 | |
| 213 private: | |
| 214 int last_request_id_ = 0; | |
| 215 std::map<int, PrinterProviderAPI::UsbAccessGrantedCallback> pending_requests_; | |
| 216 }; | |
| 217 | |
| 185 // Implements chrome.printerProvider API events. | 218 // Implements chrome.printerProvider API events. |
| 186 class PrinterProviderAPIImpl : public PrinterProviderAPI, | 219 class PrinterProviderAPIImpl : public PrinterProviderAPI, |
| 187 public PrinterProviderInternalAPIObserver, | 220 public PrinterProviderInternalAPIObserver, |
| 188 public ExtensionRegistryObserver { | 221 public ExtensionRegistryObserver { |
| 189 public: | 222 public: |
| 190 explicit PrinterProviderAPIImpl(content::BrowserContext* browser_context); | 223 explicit PrinterProviderAPIImpl(content::BrowserContext* browser_context); |
| 191 ~PrinterProviderAPIImpl() override; | 224 ~PrinterProviderAPIImpl() override; |
| 192 | 225 |
| 193 private: | 226 private: |
| 194 // PrinterProviderAPI implementation: | 227 // PrinterProviderAPI implementation: |
| 195 void DispatchGetPrintersRequested( | 228 void DispatchGetPrintersRequested( |
| 196 const PrinterProviderAPI::GetPrintersCallback& callback) override; | 229 const PrinterProviderAPI::GetPrintersCallback& callback) override; |
| 197 void DispatchGetCapabilityRequested( | 230 void DispatchGetCapabilityRequested( |
| 198 const std::string& printer_id, | 231 const std::string& printer_id, |
| 199 const PrinterProviderAPI::GetCapabilityCallback& callback) override; | 232 const PrinterProviderAPI::GetCapabilityCallback& callback) override; |
| 200 void DispatchPrintRequested( | 233 void DispatchPrintRequested( |
| 201 const PrinterProviderPrintJob& job, | 234 const PrinterProviderPrintJob& job, |
| 202 const PrinterProviderAPI::PrintCallback& callback) override; | 235 const PrinterProviderAPI::PrintCallback& callback) override; |
| 203 const PrinterProviderPrintJob* GetPrintJob(const Extension* extension, | 236 const PrinterProviderPrintJob* GetPrintJob(const Extension* extension, |
| 204 int request_id) const override; | 237 int request_id) const override; |
| 238 void DispatchGrantUsbPrinterAccess( | |
| 239 const std::string& extension_id, | |
| 240 int device_id, | |
| 241 const PrinterProviderAPI::UsbAccessGrantedCallback& callback) override; | |
| 205 | 242 |
| 206 // PrinterProviderInternalAPIObserver implementation: | 243 // PrinterProviderInternalAPIObserver implementation: |
| 207 void OnGetPrintersResult( | 244 void OnGetPrintersResult( |
| 208 const Extension* extension, | 245 const Extension* extension, |
| 209 int request_id, | 246 int request_id, |
| 210 const PrinterProviderInternalAPIObserver::PrinterInfoVector& result) | 247 const PrinterProviderInternalAPIObserver::PrinterInfoVector& result) |
| 211 override; | 248 override; |
| 212 void OnGetCapabilityResult(const Extension* extension, | 249 void OnGetCapabilityResult(const Extension* extension, |
| 213 int request_id, | 250 int request_id, |
| 214 const base::DictionaryValue& result) override; | 251 const base::DictionaryValue& result) override; |
| 215 void OnPrintResult( | 252 void OnPrintResult( |
| 216 const Extension* extension, | 253 const Extension* extension, |
| 217 int request_id, | 254 int request_id, |
| 218 core_api::printer_provider_internal::PrintError error) override; | 255 core_api::printer_provider_internal::PrintError error) override; |
| 256 void OnUsbAccessGrantedResult( | |
| 257 const Extension* extension, | |
| 258 int request_id, | |
| 259 const core_api::printer_provider::PrinterInfo* printer_info) override; | |
| 219 | 260 |
| 220 // ExtensionRegistryObserver implementation: | 261 // ExtensionRegistryObserver implementation: |
| 221 void OnExtensionUnloaded(content::BrowserContext* browser_context, | 262 void OnExtensionUnloaded(content::BrowserContext* browser_context, |
| 222 const Extension* extension, | 263 const Extension* extension, |
| 223 UnloadedExtensionInfo::Reason reason) override; | 264 UnloadedExtensionInfo::Reason reason) override; |
| 224 | 265 |
| 225 // Called before chrome.printerProvider.onGetPrintersRequested event is | 266 // Called before chrome.printerProvider.onGetPrintersRequested event is |
| 226 // dispatched to an extension. It returns whether the extension is interested | 267 // dispatched to an extension. It returns whether the extension is interested |
| 227 // in the event. If the extension listens to the event, it's added to the set | 268 // in the event. If the extension listens to the event, it's added to the set |
| 228 // of |request| sources. |request| is |GetPrintersRequest| object associated | 269 // of |request| sources. |request| is |GetPrintersRequest| object associated |
| 229 // with the event. | 270 // with the event. |
| 230 bool WillRequestPrinters(int request_id, | 271 bool WillRequestPrinters(int request_id, |
| 231 content::BrowserContext* browser_context, | 272 content::BrowserContext* browser_context, |
| 232 const Extension* extension, | 273 const Extension* extension, |
| 233 base::ListValue* args); | 274 base::ListValue* args); |
| 234 | 275 |
| 235 content::BrowserContext* browser_context_; | 276 content::BrowserContext* browser_context_; |
| 236 | 277 |
| 237 PendingGetPrintersRequests pending_get_printers_requests_; | 278 PendingGetPrintersRequests pending_get_printers_requests_; |
| 238 | 279 |
| 239 std::map<std::string, PendingPrintRequests> pending_print_requests_; | 280 std::map<std::string, PendingPrintRequests> pending_print_requests_; |
| 240 | 281 |
| 241 std::map<std::string, PendingGetCapabilityRequests> | 282 std::map<std::string, PendingGetCapabilityRequests> |
| 242 pending_capability_requests_; | 283 pending_capability_requests_; |
| 243 | 284 |
| 285 std::map<std::string, PendingUsbPrinterInfoRequests> | |
| 286 pending_usb_printer_info_requests_; | |
| 287 | |
| 244 ScopedObserver<PrinterProviderInternalAPI, PrinterProviderInternalAPIObserver> | 288 ScopedObserver<PrinterProviderInternalAPI, PrinterProviderInternalAPIObserver> |
| 245 internal_api_observer_; | 289 internal_api_observer_; |
| 246 | 290 |
| 247 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> | 291 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
| 248 extension_registry_observer_; | 292 extension_registry_observer_; |
| 249 | 293 |
| 250 DISALLOW_COPY_AND_ASSIGN(PrinterProviderAPIImpl); | 294 DISALLOW_COPY_AND_ASSIGN(PrinterProviderAPIImpl); |
| 251 }; | 295 }; |
| 252 | 296 |
| 253 GetPrintersRequest::GetPrintersRequest( | 297 GetPrintersRequest::GetPrintersRequest( |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 394 return &it->second.job; | 438 return &it->second.job; |
| 395 } | 439 } |
| 396 | 440 |
| 397 void PendingPrintRequests::FailAll() { | 441 void PendingPrintRequests::FailAll() { |
| 398 for (auto& request : pending_requests_) | 442 for (auto& request : pending_requests_) |
| 399 request.second.callback.Run(false, | 443 request.second.callback.Run(false, |
| 400 PrinterProviderAPI::GetDefaultPrintError()); | 444 PrinterProviderAPI::GetDefaultPrintError()); |
| 401 pending_requests_.clear(); | 445 pending_requests_.clear(); |
| 402 } | 446 } |
| 403 | 447 |
| 448 PendingUsbPrinterInfoRequests::PendingUsbPrinterInfoRequests() { | |
| 449 } | |
| 450 | |
| 451 PendingUsbPrinterInfoRequests::~PendingUsbPrinterInfoRequests() { | |
| 452 } | |
| 453 | |
| 454 int PendingUsbPrinterInfoRequests::Add( | |
| 455 const PrinterProviderAPI::UsbAccessGrantedCallback& callback) { | |
| 456 pending_requests_[++last_request_id_] = callback; | |
| 457 return last_request_id_; | |
| 458 } | |
| 459 | |
| 460 void PendingUsbPrinterInfoRequests::Complete( | |
| 461 int request_id, | |
| 462 const core_api::printer_provider::PrinterInfo* printer_info) { | |
| 463 auto it = pending_requests_.find(request_id); | |
| 464 if (it == pending_requests_.end()) { | |
| 465 return; | |
| 466 } | |
| 467 | |
| 468 PrinterProviderAPI::UsbAccessGrantedCallback callback = it->second; | |
| 469 pending_requests_.erase(it); | |
| 470 | |
| 471 if (printer_info) { | |
| 472 callback.Run(*printer_info->ToValue().get()); | |
| 473 } else { | |
| 474 callback.Run(base::DictionaryValue()); | |
| 475 } | |
| 476 } | |
| 477 | |
| 478 void PendingUsbPrinterInfoRequests::FailAll() { | |
| 479 for (auto& request : pending_requests_) { | |
| 480 request.second.Run(base::DictionaryValue()); | |
| 481 } | |
| 482 pending_requests_.clear(); | |
| 483 } | |
| 484 | |
| 404 PrinterProviderAPIImpl::PrinterProviderAPIImpl( | 485 PrinterProviderAPIImpl::PrinterProviderAPIImpl( |
| 405 content::BrowserContext* browser_context) | 486 content::BrowserContext* browser_context) |
| 406 : browser_context_(browser_context), | 487 : browser_context_(browser_context), |
| 407 internal_api_observer_(this), | 488 internal_api_observer_(this), |
| 408 extension_registry_observer_(this) { | 489 extension_registry_observer_(this) { |
| 409 internal_api_observer_.Add( | 490 internal_api_observer_.Add( |
| 410 PrinterProviderInternalAPI::GetFactoryInstance()->Get(browser_context)); | 491 PrinterProviderInternalAPI::GetFactoryInstance()->Get(browser_context)); |
| 411 extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context)); | 492 extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context)); |
| 412 } | 493 } |
| 413 | 494 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 527 | 608 |
| 528 const PrinterProviderPrintJob* PrinterProviderAPIImpl::GetPrintJob( | 609 const PrinterProviderPrintJob* PrinterProviderAPIImpl::GetPrintJob( |
| 529 const Extension* extension, | 610 const Extension* extension, |
| 530 int request_id) const { | 611 int request_id) const { |
| 531 auto it = pending_print_requests_.find(extension->id()); | 612 auto it = pending_print_requests_.find(extension->id()); |
| 532 if (it == pending_print_requests_.end()) | 613 if (it == pending_print_requests_.end()) |
| 533 return nullptr; | 614 return nullptr; |
| 534 return it->second.GetPrintJob(request_id); | 615 return it->second.GetPrintJob(request_id); |
| 535 } | 616 } |
| 536 | 617 |
| 618 void PrinterProviderAPIImpl::DispatchGrantUsbPrinterAccess( | |
| 619 const std::string& extension_id, | |
| 620 int device_id, | |
| 621 const PrinterProviderAPI::UsbAccessGrantedCallback& callback) { | |
| 622 UsbService* service = device::DeviceClient::Get()->GetUsbService(); | |
| 623 DCHECK(service); | |
| 624 scoped_refptr<UsbDevice> device = service->GetDeviceById(device_id); | |
| 625 if (!device) { | |
| 626 callback.Run(base::DictionaryValue()); | |
| 627 return; | |
| 628 } | |
| 629 | |
| 630 DevicePermissionsManager* permissions_manager = | |
| 631 DevicePermissionsManager::Get(browser_context_); | |
| 632 DCHECK(permissions_manager); | |
| 633 permissions_manager->AllowUsbDevice(extension_id, device); | |
| 634 | |
| 635 EventRouter* event_router = EventRouter::Get(browser_context_); | |
| 636 if (!event_router->ExtensionHasEventListener( | |
| 637 extension_id, | |
| 638 core_api::printer_provider::OnUsbAccessGranted::kEventName)) { | |
| 639 callback.Run(base::DictionaryValue()); | |
| 640 return; | |
| 641 } | |
| 642 | |
| 643 int request_id = | |
| 644 pending_usb_printer_info_requests_[extension_id].Add(callback); | |
| 645 core_api::usb::Device usb_device; | |
| 646 usb_device.device = device->unique_id(); | |
| 647 usb_device.vendor_id = device->vendor_id(); | |
| 648 usb_device.product_id = device->product_id(); | |
| 649 | |
| 650 scoped_ptr<base::ListValue> internal_args(new base::ListValue); | |
| 651 // Request id is not part of the public API and it will be massaged out in | |
| 652 // custom bindings. | |
| 653 internal_args->AppendInteger(request_id); | |
| 654 internal_args->Append(usb_device.ToValue().release()); | |
| 655 scoped_ptr<Event> event( | |
| 656 new Event(core_api::printer_provider::OnUsbAccessGranted::kEventName, | |
| 657 internal_args.Pass())); | |
| 658 event_router->DispatchEventToExtension(extension_id, event.Pass()); | |
| 659 } | |
| 660 | |
| 537 void PrinterProviderAPIImpl::OnGetPrintersResult( | 661 void PrinterProviderAPIImpl::OnGetPrintersResult( |
| 538 const Extension* extension, | 662 const Extension* extension, |
| 539 int request_id, | 663 int request_id, |
| 540 const PrinterProviderInternalAPIObserver::PrinterInfoVector& result) { | 664 const PrinterProviderInternalAPIObserver::PrinterInfoVector& result) { |
| 541 base::ListValue printer_list; | 665 base::ListValue printer_list; |
| 542 | 666 |
| 543 // Update some printer description properties to better identify the extension | 667 // Update some printer description properties to better identify the extension |
| 544 // managing the printer. | 668 // managing the printer. |
| 545 for (size_t i = 0; i < result.size(); ++i) { | 669 for (size_t i = 0; i < result.size(); ++i) { |
| 546 scoped_ptr<base::DictionaryValue> printer(result[i]->ToValue()); | 670 scoped_ptr<base::DictionaryValue> printer(result[i]->ToValue()); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 583 core_api::printer_provider_internal::PrintError error) { | 707 core_api::printer_provider_internal::PrintError error) { |
| 584 const std::string error_str = | 708 const std::string error_str = |
| 585 error == core_api::printer_provider_internal::PRINT_ERROR_NONE | 709 error == core_api::printer_provider_internal::PRINT_ERROR_NONE |
| 586 ? PrinterProviderAPI::GetDefaultPrintError() | 710 ? PrinterProviderAPI::GetDefaultPrintError() |
| 587 : core_api::printer_provider_internal::ToString(error); | 711 : core_api::printer_provider_internal::ToString(error); |
| 588 pending_print_requests_[extension->id()].Complete( | 712 pending_print_requests_[extension->id()].Complete( |
| 589 request_id, error == core_api::printer_provider_internal::PRINT_ERROR_OK, | 713 request_id, error == core_api::printer_provider_internal::PRINT_ERROR_OK, |
| 590 error_str); | 714 error_str); |
| 591 } | 715 } |
| 592 | 716 |
| 717 void PrinterProviderAPIImpl::OnUsbAccessGrantedResult( | |
| 718 const Extension* extension, | |
| 719 int request_id, | |
| 720 const core_api::printer_provider::PrinterInfo* printer_info) { | |
| 721 pending_usb_printer_info_requests_[extension->id()].Complete(request_id, | |
|
tbarzic
2015/05/27 00:11:03
Can you reuse code from PrinterProviderAPIImpl::On
Reilly Grant (use Gerrit)
2015/05/28 21:04:10
Done.
| |
| 722 printer_info); | |
| 723 } | |
| 724 | |
| 593 void PrinterProviderAPIImpl::OnExtensionUnloaded( | 725 void PrinterProviderAPIImpl::OnExtensionUnloaded( |
| 594 content::BrowserContext* browser_context, | 726 content::BrowserContext* browser_context, |
| 595 const Extension* extension, | 727 const Extension* extension, |
| 596 UnloadedExtensionInfo::Reason reason) { | 728 UnloadedExtensionInfo::Reason reason) { |
| 597 pending_get_printers_requests_.FailAllForExtension(extension->id()); | 729 pending_get_printers_requests_.FailAllForExtension(extension->id()); |
| 598 | 730 |
| 599 auto print_it = pending_print_requests_.find(extension->id()); | 731 auto print_it = pending_print_requests_.find(extension->id()); |
| 600 if (print_it != pending_print_requests_.end()) { | 732 if (print_it != pending_print_requests_.end()) { |
| 601 print_it->second.FailAll(); | 733 print_it->second.FailAll(); |
| 602 pending_print_requests_.erase(print_it); | 734 pending_print_requests_.erase(print_it); |
| 603 } | 735 } |
| 604 | 736 |
| 605 auto capability_it = pending_capability_requests_.find(extension->id()); | 737 auto capability_it = pending_capability_requests_.find(extension->id()); |
| 606 if (capability_it != pending_capability_requests_.end()) { | 738 if (capability_it != pending_capability_requests_.end()) { |
| 607 capability_it->second.FailAll(); | 739 capability_it->second.FailAll(); |
| 608 pending_capability_requests_.erase(capability_it); | 740 pending_capability_requests_.erase(capability_it); |
| 609 } | 741 } |
| 742 | |
| 743 auto usb_it = pending_usb_printer_info_requests_.find(extension->id()); | |
| 744 if (usb_it != pending_usb_printer_info_requests_.end()) { | |
| 745 usb_it->second.FailAll(); | |
| 746 pending_usb_printer_info_requests_.erase(usb_it); | |
| 747 } | |
| 610 } | 748 } |
| 611 | 749 |
| 612 bool PrinterProviderAPIImpl::WillRequestPrinters( | 750 bool PrinterProviderAPIImpl::WillRequestPrinters( |
| 613 int request_id, | 751 int request_id, |
| 614 content::BrowserContext* browser_context, | 752 content::BrowserContext* browser_context, |
| 615 const Extension* extension, | 753 const Extension* extension, |
| 616 base::ListValue* args) { | 754 base::ListValue* args) { |
| 617 if (!extension) | 755 if (!extension) |
| 618 return false; | 756 return false; |
| 619 EventRouter* event_router = EventRouter::Get(browser_context_); | 757 EventRouter* event_router = EventRouter::Get(browser_context_); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 634 return new PrinterProviderAPIImpl(context); | 772 return new PrinterProviderAPIImpl(context); |
| 635 } | 773 } |
| 636 | 774 |
| 637 // static | 775 // static |
| 638 std::string PrinterProviderAPI::GetDefaultPrintError() { | 776 std::string PrinterProviderAPI::GetDefaultPrintError() { |
| 639 return core_api::printer_provider_internal::ToString( | 777 return core_api::printer_provider_internal::ToString( |
| 640 core_api::printer_provider_internal::PRINT_ERROR_FAILED); | 778 core_api::printer_provider_internal::PRINT_ERROR_FAILED); |
| 641 } | 779 } |
| 642 | 780 |
| 643 } // namespace extensions | 781 } // namespace extensions |
| OLD | NEW |