OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "chromeos/printing/ppd_provider.h" | 5 #include "chromeos/printing/ppd_provider.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <deque> | 8 #include <deque> |
9 #include <unordered_map> | 9 #include <unordered_map> |
10 #include <utility> | 10 #include <utility> |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 | 424 |
425 if (top_list.get() == nullptr) { | 425 if (top_list.get() == nullptr) { |
426 // We got something malformed back. | 426 // We got something malformed back. |
427 FailQueuedMetadataResolutions(PpdProvider::INTERNAL_ERROR); | 427 FailQueuedMetadataResolutions(PpdProvider::INTERNAL_ERROR); |
428 return; | 428 return; |
429 } | 429 } |
430 | 430 |
431 // This should just be a simple list of locale strings. | 431 // This should just be a simple list of locale strings. |
432 std::vector<std::string> available_locales; | 432 std::vector<std::string> available_locales; |
433 bool found_en = false; | 433 bool found_en = false; |
434 for (const std::unique_ptr<base::Value>& entry : *top_list) { | 434 for (const base::Value& entry : *top_list) { |
435 std::string tmp; | 435 std::string tmp; |
436 // Locales should have at *least* a two-character country code. 100 is an | 436 // Locales should have at *least* a two-character country code. 100 is an |
437 // arbitrary upper bound for length to protect against extreme bogosity. | 437 // arbitrary upper bound for length to protect against extreme bogosity. |
438 if (!entry->GetAsString(&tmp) || tmp.size() < 2 || tmp.size() > 100) { | 438 if (!entry.GetAsString(&tmp) || tmp.size() < 2 || tmp.size() > 100) { |
439 FailQueuedMetadataResolutions(PpdProvider::INTERNAL_ERROR); | 439 FailQueuedMetadataResolutions(PpdProvider::INTERNAL_ERROR); |
440 return; | 440 return; |
441 } | 441 } |
442 if (tmp == "en") { | 442 if (tmp == "en") { |
443 found_en = true; | 443 found_en = true; |
444 } | 444 } |
445 available_locales.push_back(tmp); | 445 available_locales.push_back(tmp); |
446 } | 446 } |
447 if (available_locales.empty() || !found_en) { | 447 if (available_locales.empty() || !found_en) { |
448 // We have no locales, or we didn't get an english locale (which is our | 448 // We have no locales, or we didn't get an english locale (which is our |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
596 | 596 |
597 if (top_list.get() == nullptr) { | 597 if (top_list.get() == nullptr) { |
598 // We got something malformed back. | 598 // We got something malformed back. |
599 LOG(ERROR) << "Malformed top list"; | 599 LOG(ERROR) << "Malformed top list"; |
600 result = PpdProvider::INTERNAL_ERROR; | 600 result = PpdProvider::INTERNAL_ERROR; |
601 } else { | 601 } else { |
602 // We'll set result to SUCCESS if we do find the device. | 602 // We'll set result to SUCCESS if we do find the device. |
603 result = PpdProvider::NOT_FOUND; | 603 result = PpdProvider::NOT_FOUND; |
604 for (const auto& entry : *top_list) { | 604 for (const auto& entry : *top_list) { |
605 int device_id; | 605 int device_id; |
606 base::ListValue* sub_list; | 606 const base::ListValue* sub_list; |
607 | 607 |
608 // Each entry should be a size-2 list with an integer and a string. | 608 // Each entry should be a size-2 list with an integer and a string. |
609 if (!entry->GetAsList(&sub_list) || sub_list->GetSize() != 2 || | 609 if (!entry.GetAsList(&sub_list) || sub_list->GetSize() != 2 || |
610 !sub_list->GetInteger(0, &device_id) || | 610 !sub_list->GetInteger(0, &device_id) || |
611 !sub_list->GetString(1, &contents) || device_id < 0 || | 611 !sub_list->GetString(1, &contents) || device_id < 0 || |
612 device_id > 0xffff) { | 612 device_id > 0xffff) { |
613 // Malformed data. | 613 // Malformed data. |
614 LOG(ERROR) << "Malformed line in usb device list"; | 614 LOG(ERROR) << "Malformed line in usb device list"; |
615 result = PpdProvider::INTERNAL_ERROR; | 615 result = PpdProvider::INTERNAL_ERROR; |
616 break; | 616 break; |
617 } | 617 } |
618 if (device_id == desired_device_id) { | 618 if (device_id == desired_device_id) { |
619 // Found it. | 619 // Found it. |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
784 if (tmp != PpdProvider::SUCCESS) { | 784 if (tmp != PpdProvider::SUCCESS) { |
785 return tmp; | 785 return tmp; |
786 } | 786 } |
787 auto top_list = base::ListValue::From(base::JSONReader::Read(buffer)); | 787 auto top_list = base::ListValue::From(base::JSONReader::Read(buffer)); |
788 | 788 |
789 if (top_list.get() == nullptr) { | 789 if (top_list.get() == nullptr) { |
790 // We got something malformed back. | 790 // We got something malformed back. |
791 return PpdProvider::INTERNAL_ERROR; | 791 return PpdProvider::INTERNAL_ERROR; |
792 } | 792 } |
793 for (const auto& entry : *top_list) { | 793 for (const auto& entry : *top_list) { |
794 base::ListValue* sub_list; | 794 const base::ListValue* sub_list; |
795 contents->push_back({}); | 795 contents->push_back({}); |
796 if (!entry->GetAsList(&sub_list) || sub_list->GetSize() != 2 || | 796 if (!entry.GetAsList(&sub_list) || sub_list->GetSize() != 2 || |
797 !sub_list->GetString(0, &contents->back().first) || | 797 !sub_list->GetString(0, &contents->back().first) || |
798 !sub_list->GetString(1, &contents->back().second)) { | 798 !sub_list->GetString(1, &contents->back().second)) { |
799 contents->clear(); | 799 contents->clear(); |
800 return PpdProvider::INTERNAL_ERROR; | 800 return PpdProvider::INTERNAL_ERROR; |
801 } | 801 } |
802 } | 802 } |
803 return PpdProvider::SUCCESS; | 803 return PpdProvider::SUCCESS; |
804 } | 804 } |
805 | 805 |
806 // Create the list of manufacturers from |cached_metadata_|. Requires that | 806 // Create the list of manufacturers from |cached_metadata_|. Requires that |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
908 scoped_refptr<net::URLRequestContextGetter> url_context_getter, | 908 scoped_refptr<net::URLRequestContextGetter> url_context_getter, |
909 scoped_refptr<PpdCache> ppd_cache, | 909 scoped_refptr<PpdCache> ppd_cache, |
910 scoped_refptr<base::SequencedTaskRunner> disk_task_runner, | 910 scoped_refptr<base::SequencedTaskRunner> disk_task_runner, |
911 const PpdProvider::Options& options) { | 911 const PpdProvider::Options& options) { |
912 return scoped_refptr<PpdProvider>( | 912 return scoped_refptr<PpdProvider>( |
913 new PpdProviderImpl(browser_locale, url_context_getter, ppd_cache, | 913 new PpdProviderImpl(browser_locale, url_context_getter, ppd_cache, |
914 disk_task_runner, options)); | 914 disk_task_runner, options)); |
915 } | 915 } |
916 } // namespace printing | 916 } // namespace printing |
917 } // namespace chromeos | 917 } // namespace chromeos |
OLD | NEW |