Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(173)

Side by Side Diff: chrome/browser/chromeos/printing/specifics_translation.cc

Issue 2956173002: Introduce the field make_and_model for synced printers. (Closed)
Patch Set: done Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/chromeos/printing/specifics_translation_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 // Combines |make| and |model| with a space to generate a make and model string.
55 // If |model| already represents the make and model, the string is just |model|.
56 // This is to prevent strings of the form '<make> <make> <model>'.
57 std::string MakeAndModel(base::StringPiece make, base::StringPiece model) {
58 return model.starts_with(make) ? model.as_string()
59 : base::JoinString({make, model}, " ");
60 }
61
52 } // namespace 62 } // namespace
53 63
54 std::unique_ptr<Printer> SpecificsToPrinter( 64 std::unique_ptr<Printer> SpecificsToPrinter(
55 const sync_pb::PrinterSpecifics& specifics) { 65 const sync_pb::PrinterSpecifics& specifics) {
56 DCHECK(!specifics.id().empty()); 66 DCHECK(!specifics.id().empty());
57 67
58 auto printer = base::MakeUnique<Printer>( 68 auto printer = base::MakeUnique<Printer>(
59 specifics.id(), base::Time::FromJavaTime(specifics.updated_timestamp())); 69 specifics.id(), base::Time::FromJavaTime(specifics.updated_timestamp()));
60 printer->set_display_name(specifics.display_name()); 70 printer->set_display_name(specifics.display_name());
61 printer->set_description(specifics.description()); 71 printer->set_description(specifics.description());
62 printer->set_manufacturer(specifics.manufacturer()); 72 printer->set_manufacturer(specifics.manufacturer());
63 printer->set_model(specifics.model()); 73 printer->set_model(specifics.model());
74 if (!specifics.make_and_model().empty()) {
75 printer->set_make_and_model(specifics.make_and_model());
76 } else {
77 printer->set_make_and_model(
78 MakeAndModel(specifics.manufacturer(), specifics.model()));
79 }
64 printer->set_uri(specifics.uri()); 80 printer->set_uri(specifics.uri());
65 printer->set_uuid(specifics.uuid()); 81 printer->set_uuid(specifics.uuid());
66 82
67 *printer->mutable_ppd_reference() = SpecificsToPpd(specifics.ppd_reference()); 83 *printer->mutable_ppd_reference() = SpecificsToPpd(specifics.ppd_reference());
68 84
69 return printer; 85 return printer;
70 } 86 }
71 87
72 std::unique_ptr<sync_pb::PrinterSpecifics> PrinterToSpecifics( 88 std::unique_ptr<sync_pb::PrinterSpecifics> PrinterToSpecifics(
73 const Printer& printer) { 89 const Printer& printer) {
(...skipping 15 matching lines...) Expand all
89 105
90 if (!printer.description().empty()) 106 if (!printer.description().empty())
91 specifics->set_description(printer.description()); 107 specifics->set_description(printer.description());
92 108
93 if (!printer.manufacturer().empty()) 109 if (!printer.manufacturer().empty())
94 specifics->set_manufacturer(printer.manufacturer()); 110 specifics->set_manufacturer(printer.manufacturer());
95 111
96 if (!printer.model().empty()) 112 if (!printer.model().empty())
97 specifics->set_model(printer.model()); 113 specifics->set_model(printer.model());
98 114
115 if (!printer.make_and_model().empty())
116 specifics->set_make_and_model(printer.make_and_model());
117
99 if (!printer.uri().empty()) 118 if (!printer.uri().empty())
100 specifics->set_uri(printer.uri()); 119 specifics->set_uri(printer.uri());
101 120
102 if (!printer.uuid().empty()) 121 if (!printer.uuid().empty())
103 specifics->set_uuid(printer.uuid()); 122 specifics->set_uuid(printer.uuid());
104 123
105 MergeReferenceToSpecifics(specifics->mutable_ppd_reference(), 124 MergeReferenceToSpecifics(specifics->mutable_ppd_reference(),
106 printer.ppd_reference()); 125 printer.ppd_reference());
107 } 126 }
108 127
109 } // namespace printing 128 } // namespace printing
110 } // namespace chromeos 129 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/printing/specifics_translation_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698