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.has_autoconf() && specifics.autoconf()) { |
Carlson
2017/05/22 23:46:07
The has_autoconf() here is not needed.
skau
2017/05/23 01:00:21
Done.
| |
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 | |
Carlson
2017/05/22 23:46:07
Not sure what "default object" means here -- you m
| |
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->set_autoconf(ref.autoconf); | |
Carlson
2017/05/22 23:46:07
You could write each of these as
if (...) {
speci
skau
2017/05/23 01:00:21
Done.
| |
42 specifics->clear_user_supplied_ppd_url(); | |
43 specifics->clear_effective_make_and_model(); | |
44 } else if (!ref.user_supplied_ppd_url.empty()) { | |
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 specifics->clear_autoconf(); |
40 | 47 specifics->clear_effective_make_and_model(); |
41 if (!ref.effective_make_and_model.empty()) { | 48 } else if (!ref.effective_make_and_model.empty()) { |
42 specifics->set_effective_make_and_model(ref.effective_make_and_model); | 49 specifics->set_effective_make_and_model(ref.effective_make_and_model); |
50 specifics->clear_autoconf(); | |
51 specifics->clear_user_supplied_ppd_url(); | |
43 } | 52 } |
44 } | 53 } |
45 | 54 |
46 } // namespace | 55 } // namespace |
47 | 56 |
48 std::unique_ptr<Printer> SpecificsToPrinter( | 57 std::unique_ptr<Printer> SpecificsToPrinter( |
49 const sync_pb::PrinterSpecifics& specifics) { | 58 const sync_pb::PrinterSpecifics& specifics) { |
50 DCHECK(!specifics.id().empty()); | 59 DCHECK(!specifics.id().empty()); |
51 | 60 |
52 auto printer = base::MakeUnique<Printer>( | 61 auto printer = base::MakeUnique<Printer>( |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 | 104 |
96 if (!printer.uuid().empty()) | 105 if (!printer.uuid().empty()) |
97 specifics->set_uuid(printer.uuid()); | 106 specifics->set_uuid(printer.uuid()); |
98 | 107 |
99 MergeReferenceToSpecifics(specifics->mutable_ppd_reference(), | 108 MergeReferenceToSpecifics(specifics->mutable_ppd_reference(), |
100 printer.ppd_reference()); | 109 printer.ppd_reference()); |
101 } | 110 } |
102 | 111 |
103 } // namespace printing | 112 } // namespace printing |
104 } // namespace chromeos | 113 } // namespace chromeos |
OLD | NEW |