Commit e3af2bb7 authored by Pranav Batra's avatar Pranav Batra Committed by Commit Bot

Add PrintPreviewStickySettings::GetRecentlyUsedPrinters()

Add method GetRecentlyUsedPrinters() for use with the CUPS proxy.

Bug: 1015662
Test: xvfb-run ./unit_tests --gtest_filter=PrintPreviewStickySettingsUnittest.*

Change-Id: I908f47d45259ab8dd941d320dad66275b95e00b3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2359729
Commit-Queue: Pranav Batra <batrapranav@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#807228}
parent 098d3576
......@@ -57,6 +57,14 @@ void PrintPreviewStickySettings::RestoreFromPrefs(PrefService* prefs) {
base::flat_map<std::string, int>
PrintPreviewStickySettings::GetPrinterRecentlyUsedRanks() {
int current_rank = 0;
base::flat_map<std::string, int> recently_used_ranks;
for (const std::string& printer_id : GetRecentlyUsedPrinters())
recently_used_ranks[printer_id] = current_rank++;
return recently_used_ranks;
}
std::vector<std::string> PrintPreviewStickySettings::GetRecentlyUsedPrinters() {
const std::string* sticky_settings_state = printer_app_state();
if (!sticky_settings_state)
return {};
......@@ -71,15 +79,15 @@ PrintPreviewStickySettings::GetPrinterRecentlyUsedRanks() {
if (!recent_destinations)
return {};
base::flat_map<std::string, int> recently_used_ranks;
int current_rank = 0;
std::vector<std::string> printers;
printers.reserve(recent_destinations->GetList().size());
for (const auto& recent_destination : recent_destinations->GetList()) {
const std::string* printer_id = recent_destination.FindStringKey(kId);
if (!printer_id)
continue;
recently_used_ranks[*printer_id] = current_rank++;
printers.push_back(*printer_id);
}
return recently_used_ranks;
return printers;
}
// static
......
......@@ -6,6 +6,7 @@
#define CHROME_BROWSER_PRINTING_PRINT_PREVIEW_STICKY_SETTINGS_H_
#include <string>
#include <vector>
#include "base/containers/flat_map.h"
#include "base/optional.h"
......@@ -43,6 +44,11 @@ class PrintPreviewStickySettings {
// the rank the more recent the printer was used.
base::flat_map<std::string, int> GetPrinterRecentlyUsedRanks();
// Parses serialized printing sticky settings state and extracts the list of
// recently used printers. The list is ordered from most recently used to
// least recently used.
std::vector<std::string> GetRecentlyUsedPrinters();
static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
private:
......
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