Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 <memory> | 5 #include <memory> |
| 6 #include <string> | 6 #include <string> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/strings/string_piece.h" | |
| 12 #include "base/strings/string_util.h" | |
| 11 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 12 #include "chrome/browser/chromeos/printing/specifics_translation.h" | 14 #include "chrome/browser/chromeos/printing/specifics_translation.h" |
| 13 #include "chromeos/printing/printer_configuration.h" | 15 #include "chromeos/printing/printer_configuration.h" |
| 14 #include "components/sync/protocol/printer_specifics.pb.h" | 16 #include "components/sync/protocol/printer_specifics.pb.h" |
| 15 | 17 |
| 16 namespace chromeos { | 18 namespace chromeos { |
| 17 namespace printing { | 19 namespace printing { |
| 18 | 20 |
| 19 namespace { | 21 namespace { |
| 20 | 22 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 42 specifics->set_autoconf(ref.autoconf); | 44 specifics->set_autoconf(ref.autoconf); |
| 43 } else if (!ref.user_supplied_ppd_url.empty()) { | 45 } else if (!ref.user_supplied_ppd_url.empty()) { |
| 44 specifics->Clear(); | 46 specifics->Clear(); |
| 45 specifics->set_user_supplied_ppd_url(ref.user_supplied_ppd_url); | 47 specifics->set_user_supplied_ppd_url(ref.user_supplied_ppd_url); |
| 46 } else if (!ref.effective_make_and_model.empty()) { | 48 } else if (!ref.effective_make_and_model.empty()) { |
| 47 specifics->Clear(); | 49 specifics->Clear(); |
| 48 specifics->set_effective_make_and_model(ref.effective_make_and_model); | 50 specifics->set_effective_make_and_model(ref.effective_make_and_model); |
| 49 } | 51 } |
| 50 } | 52 } |
| 51 | 53 |
| 54 std::string MakeAndModel(base::StringPiece make, base::StringPiece model) { | |
|
Carlson
2017/06/28 17:38:36
Function comment. Also, I'm not 100% sure this wi
skau
2017/06/28 21:25:35
I think it's a small enough subset. Mostly, I'm t
| |
| 55 return model.starts_with(make) ? model.as_string() | |
| 56 : base::JoinString({make, model}, " "); | |
| 57 } | |
| 58 | |
| 52 } // namespace | 59 } // namespace |
| 53 | 60 |
| 54 std::unique_ptr<Printer> SpecificsToPrinter( | 61 std::unique_ptr<Printer> SpecificsToPrinter( |
| 55 const sync_pb::PrinterSpecifics& specifics) { | 62 const sync_pb::PrinterSpecifics& specifics) { |
| 56 DCHECK(!specifics.id().empty()); | 63 DCHECK(!specifics.id().empty()); |
| 57 | 64 |
| 58 auto printer = base::MakeUnique<Printer>( | 65 auto printer = base::MakeUnique<Printer>( |
| 59 specifics.id(), base::Time::FromJavaTime(specifics.updated_timestamp())); | 66 specifics.id(), base::Time::FromJavaTime(specifics.updated_timestamp())); |
| 60 printer->set_display_name(specifics.display_name()); | 67 printer->set_display_name(specifics.display_name()); |
| 61 printer->set_description(specifics.description()); | 68 printer->set_description(specifics.description()); |
| 62 printer->set_manufacturer(specifics.manufacturer()); | 69 printer->set_manufacturer(specifics.manufacturer()); |
| 63 printer->set_model(specifics.model()); | 70 printer->set_model(specifics.model()); |
| 71 if (!specifics.make_and_model().empty()) { | |
| 72 printer->set_make_and_model(specifics.make_and_model()); | |
| 73 } else { | |
| 74 printer->set_make_and_model( | |
| 75 MakeAndModel(specifics.manufacturer(), specifics.model())); | |
| 76 } | |
| 64 printer->set_uri(specifics.uri()); | 77 printer->set_uri(specifics.uri()); |
| 65 printer->set_uuid(specifics.uuid()); | 78 printer->set_uuid(specifics.uuid()); |
| 66 | 79 |
| 67 *printer->mutable_ppd_reference() = SpecificsToPpd(specifics.ppd_reference()); | 80 *printer->mutable_ppd_reference() = SpecificsToPpd(specifics.ppd_reference()); |
| 68 | 81 |
| 69 return printer; | 82 return printer; |
| 70 } | 83 } |
| 71 | 84 |
| 72 std::unique_ptr<sync_pb::PrinterSpecifics> PrinterToSpecifics( | 85 std::unique_ptr<sync_pb::PrinterSpecifics> PrinterToSpecifics( |
| 73 const Printer& printer) { | 86 const Printer& printer) { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 89 | 102 |
| 90 if (!printer.description().empty()) | 103 if (!printer.description().empty()) |
| 91 specifics->set_description(printer.description()); | 104 specifics->set_description(printer.description()); |
| 92 | 105 |
| 93 if (!printer.manufacturer().empty()) | 106 if (!printer.manufacturer().empty()) |
| 94 specifics->set_manufacturer(printer.manufacturer()); | 107 specifics->set_manufacturer(printer.manufacturer()); |
| 95 | 108 |
| 96 if (!printer.model().empty()) | 109 if (!printer.model().empty()) |
| 97 specifics->set_model(printer.model()); | 110 specifics->set_model(printer.model()); |
| 98 | 111 |
| 112 if (!printer.make_and_model().empty()) | |
| 113 specifics->set_make_and_model(printer.make_and_model()); | |
| 114 | |
| 99 if (!printer.uri().empty()) | 115 if (!printer.uri().empty()) |
| 100 specifics->set_uri(printer.uri()); | 116 specifics->set_uri(printer.uri()); |
| 101 | 117 |
| 102 if (!printer.uuid().empty()) | 118 if (!printer.uuid().empty()) |
| 103 specifics->set_uuid(printer.uuid()); | 119 specifics->set_uuid(printer.uuid()); |
| 104 | 120 |
| 105 MergeReferenceToSpecifics(specifics->mutable_ppd_reference(), | 121 MergeReferenceToSpecifics(specifics->mutable_ppd_reference(), |
| 106 printer.ppd_reference()); | 122 printer.ppd_reference()); |
| 107 } | 123 } |
| 108 | 124 |
| 109 } // namespace printing | 125 } // namespace printing |
| 110 } // namespace chromeos | 126 } // namespace chromeos |
| OLD | NEW |