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/time/time.h" | 11 #include "base/time/time.h" |
12 #include "chrome/browser/chromeos/printing/specifics_translation.h" | 12 #include "chrome/browser/chromeos/printing/specifics_translation.h" |
13 #include "chromeos/printing/printer_configuration.h" | 13 #include "chromeos/printing/printer_configuration.h" |
14 #include "components/sync/protocol/printer_specifics.pb.h" | 14 #include "components/sync/protocol/printer_specifics.pb.h" |
15 | 15 |
16 namespace chromeos { | 16 namespace chromeos { |
17 namespace printing { | 17 namespace printing { |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 Printer::PpdReference SpecificsToPpd( | 21 Printer::PpdReference SpecificsToPpd( |
22 const sync_pb::PrinterPPDReference& specifics) { | 22 const sync_pb::PrinterPPDReference& specifics) { |
23 Printer::PpdReference ref; | 23 Printer::PpdReference ref; |
24 if (specifics.has_user_supplied_ppd_url()) { | 24 if (specifics.autoconf()) { |
| 25 ref.autoconf = specifics.autoconf(); |
| 26 } else if (specifics.has_user_supplied_ppd_url()) { |
25 ref.user_supplied_ppd_url = specifics.user_supplied_ppd_url(); | 27 ref.user_supplied_ppd_url = specifics.user_supplied_ppd_url(); |
26 } | 28 } else if (specifics.has_effective_make_and_model()) { |
27 | |
28 if (specifics.has_effective_make_and_model()) { | |
29 ref.effective_make_and_model = specifics.effective_make_and_model(); | 29 ref.effective_make_and_model = specifics.effective_make_and_model(); |
30 } | 30 } |
31 | 31 |
32 return ref; | 32 return ref; |
33 } | 33 } |
34 | 34 |
| 35 // Overwrite fields in |specifics| with an appropriately filled field from |
| 36 // |ref|. If |ref| is the default object, nothing will be changed in |
| 37 // |specifics|. |
35 void MergeReferenceToSpecifics(sync_pb::PrinterPPDReference* specifics, | 38 void MergeReferenceToSpecifics(sync_pb::PrinterPPDReference* specifics, |
36 const Printer::PpdReference& ref) { | 39 const Printer::PpdReference& ref) { |
37 if (!ref.user_supplied_ppd_url.empty()) { | 40 if (ref.autoconf) { |
| 41 specifics->Clear(); |
| 42 specifics->set_autoconf(ref.autoconf); |
| 43 } else if (!ref.user_supplied_ppd_url.empty()) { |
| 44 specifics->Clear(); |
38 specifics->set_user_supplied_ppd_url(ref.user_supplied_ppd_url); | 45 specifics->set_user_supplied_ppd_url(ref.user_supplied_ppd_url); |
39 } | 46 } else if (!ref.effective_make_and_model.empty()) { |
40 | 47 specifics->Clear(); |
41 if (!ref.effective_make_and_model.empty()) { | |
42 specifics->set_effective_make_and_model(ref.effective_make_and_model); | 48 specifics->set_effective_make_and_model(ref.effective_make_and_model); |
43 } | 49 } |
44 } | 50 } |
45 | 51 |
46 } // namespace | 52 } // namespace |
47 | 53 |
48 std::unique_ptr<Printer> SpecificsToPrinter( | 54 std::unique_ptr<Printer> SpecificsToPrinter( |
49 const sync_pb::PrinterSpecifics& specifics) { | 55 const sync_pb::PrinterSpecifics& specifics) { |
50 DCHECK(!specifics.id().empty()); | 56 DCHECK(!specifics.id().empty()); |
51 | 57 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 | 101 |
96 if (!printer.uuid().empty()) | 102 if (!printer.uuid().empty()) |
97 specifics->set_uuid(printer.uuid()); | 103 specifics->set_uuid(printer.uuid()); |
98 | 104 |
99 MergeReferenceToSpecifics(specifics->mutable_ppd_reference(), | 105 MergeReferenceToSpecifics(specifics->mutable_ppd_reference(), |
100 printer.ppd_reference()); | 106 printer.ppd_reference()); |
101 } | 107 } |
102 | 108 |
103 } // namespace printing | 109 } // namespace printing |
104 } // namespace chromeos | 110 } // namespace chromeos |
OLD | NEW |