Commit 6459a2fd authored by David Valleau's avatar David Valleau Committed by Commit Bot

Adding a "IsPrinterRegistered" Function to SyncedPrintersManager

R=skau@chromium.org

Bug: 777035
Change-Id: Ia33b81c1fe77b8b373fd16b91693e18287782fef
Reviewed-on: https://chromium-review.googlesource.com/929873Reviewed-by: default avatarSean Kau <skau@chromium.org>
Commit-Queue: Sean Kau <skau@chromium.org>
Cr-Commit-Position: refs/heads/master@{#538651}
parent e6c2eafb
...@@ -377,6 +377,11 @@ base::Optional<sync_pb::PrinterSpecifics> PrintersSyncBridge::GetPrinter( ...@@ -377,6 +377,11 @@ base::Optional<sync_pb::PrinterSpecifics> PrintersSyncBridge::GetPrinter(
return {*iter->second}; return {*iter->second};
} }
bool PrintersSyncBridge::HasPrinter(const std::string& id) const {
base::AutoLock lock(data_lock_);
return all_data_.find(id) != all_data_.end();
}
void PrintersSyncBridge::CommitPrinterPut( void PrintersSyncBridge::CommitPrinterPut(
const sync_pb::PrinterSpecifics& printer) { const sync_pb::PrinterSpecifics& printer) {
std::unique_ptr<ModelTypeStore::WriteBatch> batch = std::unique_ptr<ModelTypeStore::WriteBatch> batch =
......
...@@ -61,6 +61,8 @@ class PrintersSyncBridge : public syncer::ModelTypeSyncBridge { ...@@ -61,6 +61,8 @@ class PrintersSyncBridge : public syncer::ModelTypeSyncBridge {
// Returns the printer with |id| from storage if it could be found. // Returns the printer with |id| from storage if it could be found.
base::Optional<sync_pb::PrinterSpecifics> GetPrinter( base::Optional<sync_pb::PrinterSpecifics> GetPrinter(
const std::string& id) const; const std::string& id) const;
// Returns whether or not the printer with |id| is contained in the storage.
bool HasPrinter(const std::string& id) const;
class Observer { class Observer {
public: public:
......
...@@ -141,7 +141,7 @@ class SyncedPrintersManagerImpl : public SyncedPrintersManager, ...@@ -141,7 +141,7 @@ class SyncedPrintersManagerImpl : public SyncedPrintersManager,
PrinterConfigurer::SetupFingerprint(printer); PrinterConfigurer::SetupFingerprint(printer);
// Register this printer if it's the first time we're using it. // Register this printer if it's the first time we're using it.
if (GetPrinterLocked(printer.id()) == nullptr) { if (!IsPrinterRegistered(printer.id())) {
UpdateConfiguredPrinterLocked(printer); UpdateConfiguredPrinterLocked(printer);
} }
} }
...@@ -191,6 +191,14 @@ class SyncedPrintersManagerImpl : public SyncedPrintersManager, ...@@ -191,6 +191,14 @@ class SyncedPrintersManagerImpl : public SyncedPrintersManager,
return printer.has_value() ? SpecificsToPrinter(*printer) : nullptr; return printer.has_value() ? SpecificsToPrinter(*printer) : nullptr;
} }
// Determines whether or not the printer with the given |printer_id| has
// already been registered.
bool IsPrinterRegistered(const std::string& printer_id) {
return enterprise_printers_.find(printer_id) !=
enterprise_printers_.end() ||
sync_bridge_->HasPrinter(printer_id);
}
void UpdateConfiguredPrinterLocked(const Printer& printer_arg) { void UpdateConfiguredPrinterLocked(const Printer& printer_arg) {
lock_.AssertAcquired(); lock_.AssertAcquired();
DCHECK_EQ(Printer::SRC_USER_PREFS, printer_arg.source()); DCHECK_EQ(Printer::SRC_USER_PREFS, printer_arg.source());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment