Commit 5c3feaef authored by justincarlson's avatar justincarlson Committed by Commit Bot

Make chromeos CUPS printing code namespaces consistent.

Previously printing code was in a mix of chromeos:: and
chromeos::printing.  This standardizes everything on chromeos::,
removing the chromeos::printing namespace completely.

These changes are almost entirely mechanical.  I did rename the factory function "CreateProvider" to the less generic "CreatePpdProvider" since it's now in ::chromeos directly.

BUG=702710

Review-Url: https://codereview.chromium.org/2975013002
Cr-Commit-Position: refs/heads/master@{#487334}
parent a1d23fe4
......@@ -15,9 +15,8 @@
#include "net/url_request/url_request_context_getter.h"
namespace chromeos {
namespace printing {
scoped_refptr<PpdProvider> CreateProvider(Profile* profile) {
scoped_refptr<PpdProvider> CreatePpdProvider(Profile* profile) {
base::FilePath ppd_cache_path =
profile->GetPath().Append(FILE_PATH_LITERAL("PPDCache"));
......@@ -26,5 +25,4 @@ scoped_refptr<PpdProvider> CreateProvider(Profile* profile) {
PpdCache::Create(ppd_cache_path));
}
} // namespace printing
} // namespace chromeos
......@@ -10,13 +10,11 @@
class Profile;
namespace chromeos {
namespace printing {
class PpdProvider;
scoped_refptr<PpdProvider> CreateProvider(Profile* profile);
scoped_refptr<PpdProvider> CreatePpdProvider(Profile* profile);
} // namespace printing
} // namsepace chromeos
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_PRINTING_PPD_PROVIDER_FACTORY_H_
......@@ -4,7 +4,9 @@
#include "chrome/browser/chromeos/printing/printer_configurer.h"
#include <map>
#include <memory>
#include <set>
#include <string>
#include <vector>
......@@ -43,7 +45,7 @@ namespace {
class PrinterConfigurerImpl : public PrinterConfigurer {
public:
explicit PrinterConfigurerImpl(Profile* profile)
: ppd_provider_(printing::CreateProvider(profile)), weak_factory_(this) {}
: ppd_provider_(CreatePpdProvider(profile)), weak_factory_(this) {}
PrinterConfigurerImpl(const PrinterConfigurerImpl&) = delete;
PrinterConfigurerImpl& operator=(const PrinterConfigurerImpl&) = delete;
......@@ -64,7 +66,7 @@ class PrinterConfigurerImpl : public PrinterConfigurer {
return;
}
auto* client = chromeos::DBusThreadManager::Get()->GetDebugDaemonClient();
auto* client = DBusThreadManager::Get()->GetDebugDaemonClient();
client->CupsAddAutoConfiguredPrinter(
printer.id(), printer.uri(),
......@@ -119,7 +121,7 @@ class PrinterConfigurerImpl : public PrinterConfigurer {
void AddPrinter(const Printer& printer,
const std::string& ppd_contents,
const PrinterSetupCallback& cb) {
auto* client = chromeos::DBusThreadManager::Get()->GetDebugDaemonClient();
auto* client = DBusThreadManager::Get()->GetDebugDaemonClient();
client->CupsAddManuallyConfiguredPrinter(
printer.id(), printer.uri(), ppd_contents,
......@@ -179,31 +181,31 @@ class PrinterConfigurerImpl : public PrinterConfigurer {
void ResolvePpdDone(const Printer& printer,
const PrinterSetupCallback& cb,
printing::PpdProvider::CallbackResultCode result,
PpdProvider::CallbackResultCode result,
const std::string& ppd_contents,
const std::vector<std::string>& ppd_filters) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
switch (result) {
case chromeos::printing::PpdProvider::SUCCESS:
case PpdProvider::SUCCESS:
DCHECK(!ppd_contents.empty());
if (!RequiresComponent(printer, cb, ppd_contents, ppd_filters)) {
AddPrinter(printer, ppd_contents, cb);
}
break;
case printing::PpdProvider::CallbackResultCode::NOT_FOUND:
case PpdProvider::CallbackResultCode::NOT_FOUND:
cb.Run(PrinterSetupResult::kPpdNotFound);
break;
case printing::PpdProvider::CallbackResultCode::SERVER_ERROR:
case PpdProvider::CallbackResultCode::SERVER_ERROR:
cb.Run(PrinterSetupResult::kPpdUnretrievable);
break;
case printing::PpdProvider::CallbackResultCode::INTERNAL_ERROR:
case PpdProvider::CallbackResultCode::INTERNAL_ERROR:
// TODO(skau): Add kPpdTooLarge when it's reported by the PpdProvider.
cb.Run(PrinterSetupResult::kFatalError);
break;
}
}
scoped_refptr<printing::PpdProvider> ppd_provider_;
scoped_refptr<PpdProvider> ppd_provider_;
base::WeakPtrFactory<PrinterConfigurerImpl> weak_factory_;
};
......
......@@ -16,7 +16,6 @@
#include "components/sync/protocol/printer_specifics.pb.h"
namespace chromeos {
namespace printing {
namespace {
......@@ -125,5 +124,4 @@ void MergePrinterToSpecifics(const Printer& printer,
printer.ppd_reference());
}
} // namespace printing
} // namespace chromeos
......@@ -11,7 +11,6 @@
#include "components/sync/protocol/printer_specifics.pb.h"
namespace chromeos {
namespace printing {
// Convert |printer| into its local representation. Enforces that only one
// field in PpdReference is filled in. In order of preference, we populate
......@@ -31,7 +30,6 @@ std::unique_ptr<sync_pb::PrinterSpecifics> PrinterToSpecifics(
void MergePrinterToSpecifics(const Printer& printer,
sync_pb::PrinterSpecifics* specifics);
} // namespace printing
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_PRINTING_SPECIFICS_TRANSLATION_H_
......@@ -30,7 +30,6 @@ constexpr char kEffectiveMakeAndModel[] = "Manufacturer Model T1000";
} // namespace
namespace chromeos {
namespace printing {
TEST(SpecificsTranslationTest, SpecificsToPrinter) {
sync_pb::PrinterSpecifics specifics;
......@@ -223,5 +222,4 @@ TEST(SpecificsTranslationTest, MakeAndModelPreferred) {
EXPECT_EQ(kMakeAndModel, printer->make_and_model());
}
} // namespace printing
} // namespace chromeos
......@@ -36,14 +36,14 @@ bool UpdatePrinterPref(PrintersSyncBridge* sync_bridge,
base::Optional<sync_pb::PrinterSpecifics> specifics =
sync_bridge->GetPrinter(id);
if (!specifics.has_value()) {
sync_bridge->AddPrinter(printing::PrinterToSpecifics(printer));
sync_bridge->AddPrinter(PrinterToSpecifics(printer));
return true;
}
// Preserve fields in the proto which we don't understand.
std::unique_ptr<sync_pb::PrinterSpecifics> updated_printer =
base::MakeUnique<sync_pb::PrinterSpecifics>(*specifics);
printing::MergePrinterToSpecifics(printer, updated_printer.get());
MergePrinterToSpecifics(printer, updated_printer.get());
sync_bridge->AddPrinter(std::move(updated_printer));
return false;
......@@ -80,7 +80,7 @@ std::vector<std::unique_ptr<Printer>> SyncedPrintersManager::GetPrinters()
std::vector<sync_pb::PrinterSpecifics> values =
sync_bridge_->GetAllPrinters();
for (const auto& value : values) {
printers.push_back(printing::SpecificsToPrinter(value));
printers.push_back(SpecificsToPrinter(value));
}
return printers;
......@@ -112,7 +112,7 @@ std::unique_ptr<Printer> SyncedPrintersManager::GetPrinter(
base::Optional<sync_pb::PrinterSpecifics> printer =
sync_bridge_->GetPrinter(printer_id);
return printer.has_value() ? printing::SpecificsToPrinter(*printer) : nullptr;
return printer.has_value() ? SpecificsToPrinter(*printer) : nullptr;
}
void SyncedPrintersManager::RegisterPrinter(std::unique_ptr<Printer> printer) {
......@@ -142,7 +142,7 @@ bool SyncedPrintersManager::RemovePrinter(const std::string& printer_id) {
sync_bridge_->GetPrinter(printer_id);
bool success = false;
if (printer.has_value()) {
std::unique_ptr<Printer> p = printing::SpecificsToPrinter(*printer);
std::unique_ptr<Printer> p = SpecificsToPrinter(*printer);
success = sync_bridge_->RemovePrinter(p->id());
if (success) {
for (Observer& obs : observers_) {
......@@ -201,7 +201,7 @@ void SyncedPrintersManager::UpdateRecommendedPrinters() {
// unique so we'll hash the record. This will not collide with the UUIDs
// generated for user entries.
std::string id = base::MD5String(printer_json);
printer_dictionary->SetString(printing::kPrinterId, id);
printer_dictionary->SetString(kPrinterId, id);
if (base::ContainsKey(new_printers, id)) {
// Skip duplicated entries.
......@@ -216,7 +216,7 @@ void SyncedPrintersManager::UpdateRecommendedPrinters() {
new_printers[id] = std::move(old->second);
} else {
auto printer =
printing::RecommendedPrinterToPrinter(*printer_dictionary, timestamp);
RecommendedPrinterToPrinter(*printer_dictionary, timestamp);
printer->set_source(Printer::SRC_POLICY);
new_printers[id] = std::move(printer);
......
......@@ -27,8 +27,8 @@ namespace chromeos {
namespace {
const char kPrinterId[] = "UUID-UUID-UUID-PRINTER";
const char kUri[] = "ipps://printer.chromium.org/ipp/print";
const char kTestPrinterId[] = "UUID-UUID-UUID-PRINTER";
const char kTestUri[] = "ipps://printer.chromium.org/ipp/print";
const char kLexJson[] = R"json({
"display_name": "LexaPrint",
......@@ -109,11 +109,11 @@ class SyncedPrintersManagerTest : public testing::Test {
TEST_F(SyncedPrintersManagerTest, AddPrinter) {
LoggingObserver observer;
manager_.AddObserver(&observer);
manager_.RegisterPrinter(base::MakeUnique<Printer>(kPrinterId));
manager_.RegisterPrinter(base::MakeUnique<Printer>(kTestPrinterId));
auto printers = manager_.GetPrinters();
ASSERT_EQ(1U, printers.size());
EXPECT_EQ(kPrinterId, printers[0]->id());
EXPECT_EQ(kTestPrinterId, printers[0]->id());
EXPECT_EQ(Printer::Source::SRC_USER_PREFS, printers[0]->source());
EXPECT_TRUE(observer.AddCalled());
......@@ -129,9 +129,9 @@ TEST_F(SyncedPrintersManagerTest, UpdatePrinterAssignsId) {
}
TEST_F(SyncedPrintersManagerTest, UpdatePrinter) {
manager_.RegisterPrinter(base::MakeUnique<Printer>(kPrinterId));
auto updated_printer = base::MakeUnique<Printer>(kPrinterId);
updated_printer->set_uri(kUri);
manager_.RegisterPrinter(base::MakeUnique<Printer>(kTestPrinterId));
auto updated_printer = base::MakeUnique<Printer>(kTestPrinterId);
updated_printer->set_uri(kTestUri);
// Register observer so it only receives the update event.
LoggingObserver observer;
......@@ -141,7 +141,7 @@ TEST_F(SyncedPrintersManagerTest, UpdatePrinter) {
auto printers = manager_.GetPrinters();
ASSERT_EQ(1U, printers.size());
EXPECT_EQ(kUri, printers[0]->uri());
EXPECT_EQ(kTestUri, printers[0]->uri());
EXPECT_TRUE(observer.UpdateCalled());
EXPECT_FALSE(observer.AddCalled());
......@@ -149,15 +149,15 @@ TEST_F(SyncedPrintersManagerTest, UpdatePrinter) {
TEST_F(SyncedPrintersManagerTest, RemovePrinter) {
manager_.RegisterPrinter(base::MakeUnique<Printer>("OtherUUID"));
manager_.RegisterPrinter(base::MakeUnique<Printer>(kPrinterId));
manager_.RegisterPrinter(base::MakeUnique<Printer>(kTestPrinterId));
manager_.RegisterPrinter(base::MakeUnique<Printer>());
manager_.RemovePrinter(kPrinterId);
manager_.RemovePrinter(kTestPrinterId);
auto printers = manager_.GetPrinters();
ASSERT_EQ(2U, printers.size());
EXPECT_NE(kPrinterId, printers.at(0)->id());
EXPECT_NE(kPrinterId, printers.at(1)->id());
EXPECT_NE(kTestPrinterId, printers.at(0)->id());
EXPECT_NE(kTestPrinterId, printers.at(1)->id());
}
// Tests for policy printers
......@@ -216,21 +216,21 @@ TEST_F(SyncedPrintersManagerTest, GetRecommendedPrinter) {
}
TEST_F(SyncedPrintersManagerTest, PrinterNotInstalled) {
Printer printer(kPrinterId, base::Time::FromInternalValue(1000));
Printer printer(kTestPrinterId, base::Time::FromInternalValue(1000));
EXPECT_FALSE(manager_.IsConfigurationCurrent(printer));
}
TEST_F(SyncedPrintersManagerTest, PrinterIsInstalled) {
Printer printer(kPrinterId, base::Time::FromInternalValue(1000));
Printer printer(kTestPrinterId, base::Time::FromInternalValue(1000));
manager_.PrinterInstalled(printer);
EXPECT_TRUE(manager_.IsConfigurationCurrent(printer));
}
TEST_F(SyncedPrintersManagerTest, UpdatedPrinterConfiguration) {
Printer printer(kPrinterId, base::Time::FromInternalValue(1000));
Printer printer(kTestPrinterId, base::Time::FromInternalValue(1000));
manager_.PrinterInstalled(printer);
Printer updated_printer(kPrinterId, base::Time::FromInternalValue(2000));
Printer updated_printer(kTestPrinterId, base::Time::FromInternalValue(2000));
EXPECT_FALSE(manager_.IsConfigurationCurrent(updated_printer));
}
......
......@@ -37,8 +37,6 @@
namespace chromeos {
namespace {
using printing::PpdProvider;
// Aggregates the information needed for printer setup so it's easier to pass it
// around.
struct SetUpPrinterData {
......@@ -211,8 +209,7 @@ class UsbPrinterDetectorImpl : public UsbPrinterDetector,
data->is_new = true;
// Look for an exact match based on USB ids.
scoped_refptr<PpdProvider> ppd_provider =
printing::CreateProvider(profile_);
scoped_refptr<PpdProvider> ppd_provider = CreatePpdProvider(profile_);
ppd_provider->ResolveUsbIds(
device->vendor_id(), device->product_id(),
base::Bind(&UsbPrinterDetectorImpl::ResolveUsbIdsDone,
......
......@@ -185,7 +185,7 @@ class PrinterBackendProxyChromeos : public PrinterBackendProxy {
}
chromeos::SyncedPrintersManager* prefs_;
scoped_refptr<chromeos::printing::PpdProvider> ppd_provider_;
scoped_refptr<chromeos::PpdProvider> ppd_provider_;
std::unique_ptr<chromeos::PrinterConfigurer> printer_configurer_;
base::WeakPtrFactory<PrinterBackendProxyChromeos> weak_factory_;
......
......@@ -131,7 +131,7 @@ CupsPrintersHandler::CupsPrintersHandler(content::WebUI* webui)
: printer_detector_(nullptr),
profile_(Profile::FromWebUI(webui)),
weak_factory_(this) {
ppd_provider_ = printing::CreateProvider(profile_);
ppd_provider_ = CreatePpdProvider(profile_);
printer_configurer_ = PrinterConfigurer::Create(profile_);
}
......@@ -516,28 +516,28 @@ void CupsPrintersHandler::HandleSelectPPDFile(const base::ListValue* args) {
void CupsPrintersHandler::ResolveManufacturersDone(
const std::string& js_callback,
printing::PpdProvider::CallbackResultCode result_code,
PpdProvider::CallbackResultCode result_code,
const std::vector<std::string>& manufacturers) {
auto manufacturers_value = base::MakeUnique<base::ListValue>();
if (result_code == printing::PpdProvider::SUCCESS) {
if (result_code == PpdProvider::SUCCESS) {
manufacturers_value->AppendStrings(manufacturers);
}
base::DictionaryValue response;
response.SetBoolean("success", result_code == printing::PpdProvider::SUCCESS);
response.SetBoolean("success", result_code == PpdProvider::SUCCESS);
response.Set("manufacturers", std::move(manufacturers_value));
ResolveJavascriptCallback(base::Value(js_callback), response);
}
void CupsPrintersHandler::ResolvePrintersDone(
const std::string& js_callback,
printing::PpdProvider::CallbackResultCode result_code,
PpdProvider::CallbackResultCode result_code,
const std::vector<std::string>& printers) {
auto printers_value = base::MakeUnique<base::ListValue>();
if (result_code == printing::PpdProvider::SUCCESS) {
if (result_code == PpdProvider::SUCCESS) {
printers_value->AppendStrings(printers);
}
base::DictionaryValue response;
response.SetBoolean("success", result_code == printing::PpdProvider::SUCCESS);
response.SetBoolean("success", result_code == PpdProvider::SUCCESS);
response.Set("models", std::move(printers_value));
ResolveJavascriptCallback(base::Value(js_callback), response);
}
......
......@@ -25,11 +25,9 @@ class ListValue;
class Profile;
namespace chromeos {
namespace printing {
class PpdProvider;
}
class CombiningPrinterDetector;
class PpdProvider;
namespace settings {
......@@ -89,14 +87,12 @@ class CupsPrintersHandler : public ::settings::SettingsPageUIHandler,
void HandleSelectPPDFile(const base::ListValue* args);
// PpdProvider callback handlers.
void ResolveManufacturersDone(
const std::string& js_callback,
printing::PpdProvider::CallbackResultCode result_code,
const std::vector<std::string>& available);
void ResolvePrintersDone(
const std::string& js_callback,
printing::PpdProvider::CallbackResultCode result_code,
const std::vector<std::string>& available);
void ResolveManufacturersDone(const std::string& js_callback,
PpdProvider::CallbackResultCode result_code,
const std::vector<std::string>& available);
void ResolvePrintersDone(const std::string& js_callback,
PpdProvider::CallbackResultCode result_code,
const std::vector<std::string>& available);
// ui::SelectFileDialog::Listener override:
void FileSelected(const base::FilePath& path,
......@@ -120,7 +116,7 @@ class CupsPrintersHandler : public ::settings::SettingsPageUIHandler,
bool ipp_everywhere);
std::unique_ptr<CombiningPrinterDetector> printer_detector_;
scoped_refptr<printing::PpdProvider> ppd_provider_;
scoped_refptr<PpdProvider> ppd_provider_;
std::unique_ptr<PrinterConfigurer> printer_configurer_;
Profile* profile_;
......
......@@ -27,7 +27,6 @@
#include "net/filter/gzip_header.h"
namespace chromeos {
namespace printing {
namespace {
// Return the (full) path to the file we expect to find the given key at.
......@@ -165,5 +164,4 @@ scoped_refptr<PpdCache> PpdCache::Create(const base::FilePath& cache_base_dir) {
return scoped_refptr<PpdCache>(new PpdCacheImpl(cache_base_dir));
}
} // namespace printing
} // namespace chromeos
......@@ -15,7 +15,6 @@
#include "chromeos/chromeos_export.h"
namespace chromeos {
namespace printing {
// PpdCache manages a cache of locally-stored PPD files. At its core, it
// operates like a persistent hash from PpdReference to files. If you give the
......@@ -62,7 +61,6 @@ class CHROMEOS_EXPORT PpdCache : public base::RefCounted<PpdCache> {
virtual ~PpdCache() {}
};
} // namespace printing
} // namespace chromeos
#endif // CHROMEOS_PRINTING_PPD_CACHE_H_
......@@ -21,7 +21,6 @@
#include "testing/gtest/include/gtest/gtest.h"
namespace chromeos {
namespace printing {
namespace {
// This fixture just points the cache at a temporary directory for the life of
......@@ -114,5 +113,4 @@ TEST_F(PpdCacheTest, MissThenHit) {
}
} // namespace
} // namespace printing
} // namespace chromeos
......@@ -40,7 +40,6 @@
#include "url/gurl.h"
namespace chromeos {
namespace printing {
namespace {
// Extract cupsFilter/cupsFilter2 filter names from the contents
......@@ -1020,5 +1019,4 @@ scoped_refptr<PpdProvider> PpdProvider::Create(
return scoped_refptr<PpdProvider>(new PpdProviderImpl(
browser_locale, url_context_getter, ppd_cache, options));
}
} // namespace printing
} // namespace chromeos
......@@ -20,7 +20,6 @@ class URLRequestContextGetter;
}
namespace chromeos {
namespace printing {
class PpdCache;
......@@ -137,7 +136,6 @@ class CHROMEOS_EXPORT PpdProvider : public base::RefCounted<PpdProvider> {
virtual ~PpdProvider() {}
};
} // namespace printing
} // namespace chromeos
#endif // CHROMEOS_PRINTING_PPD_PROVIDER_H_
......@@ -26,7 +26,6 @@
#include "testing/gtest/include/gtest/gtest.h"
namespace chromeos {
namespace printing {
namespace {
......@@ -556,5 +555,4 @@ TEST_F(PpdProviderTest, ExtractPpdFilters) {
}
} // namespace
} // namespace printing
} // namespace chromeos
......@@ -80,8 +80,6 @@ bool DictionaryToPrinter(const DictionaryValue& value, Printer* printer) {
} // namespace
namespace printing {
const char kPrinterId[] = "id";
std::unique_ptr<Printer> RecommendedPrinterToPrinter(
......@@ -90,7 +88,7 @@ std::unique_ptr<Printer> RecommendedPrinterToPrinter(
DCHECK(!timestamp.is_null());
std::string id;
if (!pref.GetString(printing::kPrinterId, &id)) {
if (!pref.GetString(kPrinterId, &id)) {
LOG(WARNING) << "Record id required";
return nullptr;
}
......@@ -117,5 +115,4 @@ std::unique_ptr<Printer> RecommendedPrinterToPrinter(
return printer;
}
} // namespace printing
} // namespace chromeos
......@@ -16,7 +16,6 @@ class Time;
}
namespace chromeos {
namespace printing {
CHROMEOS_EXPORT extern const char kPrinterId[];
......@@ -26,7 +25,6 @@ CHROMEOS_EXPORT std::unique_ptr<Printer> RecommendedPrinterToPrinter(
const base::DictionaryValue& pref,
const base::Time& timestamp);
} // namespace printing
} // namespace chromeos
#endif // CHROMEOS_PRINTING_PRINTER_TRANSLATOR_H_
......@@ -13,7 +13,6 @@
#include "testing/gtest/include/gtest/gtest.h"
namespace chromeos {
namespace printing {
// Printer test data
const char kHash[] = "ABCDEF123456";
......@@ -161,5 +160,4 @@ TEST(PrinterTranslatorTest, RecommendedPrinterToPrinterBlankModel) {
EXPECT_EQ(kMake, printer->make_and_model());
}
} // namespace printing
} // namespace chromeos
......@@ -6,14 +6,12 @@
#define CHROMEOS_PRINTING_PRINTING_CONSTANTS_H_
namespace chromeos {
namespace printing {
// Maximum size of a PPD file that we will accept, currently 250k. This number
// is relatively
// arbitrary, we just don't want to try to handle ridiculously huge files.
constexpr size_t kMaxPpdSizeBytes = 250 * 1024;
} // namespace printing
} // namespace chromeos
#endif // CHROMEOS_PRINTING_PRINTING_CONSTANTS_H_
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