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_internal/printer_provider_inte
rnal_api.h" | 5 #include "extensions/browser/api/printer_provider_internal/printer_provider_inte
rnal_api.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "extensions/common/api/printer_provider.h" | 9 #include "extensions/common/api/printer_provider.h" |
10 #include "extensions/common/api/printer_provider_internal.h" | 10 #include "extensions/common/api/printer_provider_internal.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 } | 40 } |
41 | 41 |
42 void PrinterProviderInternalAPI::RemoveObserver( | 42 void PrinterProviderInternalAPI::RemoveObserver( |
43 PrinterProviderInternalAPIObserver* observer) { | 43 PrinterProviderInternalAPIObserver* observer) { |
44 observers_.RemoveObserver(observer); | 44 observers_.RemoveObserver(observer); |
45 } | 45 } |
46 | 46 |
47 void PrinterProviderInternalAPI::NotifyGetPrintersResult( | 47 void PrinterProviderInternalAPI::NotifyGetPrintersResult( |
48 const Extension* extension, | 48 const Extension* extension, |
49 int request_id, | 49 int request_id, |
50 const base::ListValue& printers) { | 50 const PrinterProviderInternalAPIObserver::PrinterInfoVector& printers) { |
51 FOR_EACH_OBSERVER(PrinterProviderInternalAPIObserver, observers_, | 51 FOR_EACH_OBSERVER(PrinterProviderInternalAPIObserver, observers_, |
52 OnGetPrintersResult(extension, request_id, printers)); | 52 OnGetPrintersResult(extension, request_id, printers)); |
53 } | 53 } |
54 | 54 |
55 void PrinterProviderInternalAPI::NotifyGetCapabilityResult( | 55 void PrinterProviderInternalAPI::NotifyGetCapabilityResult( |
56 const Extension* extension, | 56 const Extension* extension, |
57 int request_id, | 57 int request_id, |
58 const base::DictionaryValue& capability) { | 58 const base::DictionaryValue& capability) { |
59 FOR_EACH_OBSERVER(PrinterProviderInternalAPIObserver, observers_, | 59 FOR_EACH_OBSERVER(PrinterProviderInternalAPIObserver, observers_, |
60 OnGetCapabilityResult(extension, request_id, capability)); | 60 OnGetCapabilityResult(extension, request_id, capability)); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 } | 125 } |
126 | 126 |
127 ExtensionFunction::ResponseAction | 127 ExtensionFunction::ResponseAction |
128 PrinterProviderInternalReportPrintersFunction::Run() { | 128 PrinterProviderInternalReportPrintersFunction::Run() { |
129 scoped_ptr<internal_api::ReportPrinters::Params> params( | 129 scoped_ptr<internal_api::ReportPrinters::Params> params( |
130 internal_api::ReportPrinters::Params::Create(*args_)); | 130 internal_api::ReportPrinters::Params::Create(*args_)); |
131 EXTENSION_FUNCTION_VALIDATE(params.get()); | 131 EXTENSION_FUNCTION_VALIDATE(params.get()); |
132 | 132 |
133 base::ListValue printers; | 133 base::ListValue printers; |
134 if (params->printers) { | 134 if (params->printers) { |
135 for (size_t i = 0; i < params->printers->size(); ++i) { | 135 PrinterProviderInternalAPI::GetFactoryInstance() |
136 scoped_ptr<base::DictionaryValue> printer( | 136 ->Get(browser_context()) |
137 params->printers->at(i)->ToValue()); | 137 ->NotifyGetPrintersResult(extension(), params->request_id, |
138 printer->SetString("extensionId", extension()->id()); | 138 *params->printers); |
139 printers.Append(printer.release()); | 139 } else { |
140 } | 140 PrinterProviderInternalAPI::GetFactoryInstance() |
| 141 ->Get(browser_context()) |
| 142 ->NotifyGetPrintersResult( |
| 143 extension(), params->request_id, |
| 144 PrinterProviderInternalAPIObserver::PrinterInfoVector()); |
141 } | 145 } |
142 | |
143 PrinterProviderInternalAPI::GetFactoryInstance() | |
144 ->Get(browser_context()) | |
145 ->NotifyGetPrintersResult(extension(), params->request_id, printers); | |
146 return RespondNow(NoArguments()); | 146 return RespondNow(NoArguments()); |
147 } | 147 } |
148 | 148 |
149 } // namespace extensions | 149 } // namespace extensions |
OLD | NEW |