Skip to content

Commit

Permalink
Move useful printing backend code from chrome/service/cloud_print to …
Browse files Browse the repository at this point in the history
…printing/backend.

BUG=none
TEST=none
Review URL: http://codereview.chromium.org/3945003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@63772 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
thestig@chromium.org committed Oct 25, 2010
1 parent 992848f commit 8e553f4
Show file tree
Hide file tree
Showing 26 changed files with 790 additions and 446 deletions.
5 changes: 5 additions & 0 deletions build/common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,11 @@
'NACL_WIN64',
],
}],
['OS=="linux" and chromeos==0 and target_arch!="arm"', {
'use_cups%': 1,
}, {
'use_cups%': 0,
}],
],

# NOTE: When these end up in the Mac bundle, we need to replace '-' for '_'
Expand Down
9 changes: 0 additions & 9 deletions chrome/chrome.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -1148,15 +1148,6 @@
'include_dirs': [
'..',
],
'variables': {
'conditions': [
['OS=="linux" and chromeos==0 and target_arch!="arm"', {
'use_cups%': 1,
}, {
'use_cups%': 0,
}],
],
},
'conditions': [
['OS=="win"', {
'defines': [
Expand Down
2 changes: 0 additions & 2 deletions chrome/service/cloud_print/cloud_print_consts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ const char kPrinterCapsHashValue[] = "capsHash";
const char kPrinterTagsValue[] = "tags";
const char kProxyTagPrefix[] = "__cp__";
const char kTagsHashTagName[] = "__cp__tagshash";
const char kLocationTagName[] = "location";
const char kDriverNameTagName[] = "drivername";


const char kDefaultCloudPrintServerUrl[] = "https://www.google.com/cloudprint";
Expand Down
2 changes: 0 additions & 2 deletions chrome/service/cloud_print/cloud_print_consts.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ extern const char kPrinterCapsHashValue[];
extern const char kPrinterTagsValue[];
extern const char kProxyTagPrefix[];
extern const char kTagsHashTagName[];
extern const char kLocationTagName[];
extern const char kDriverNameTagName[];
extern const char kDefaultCloudPrintServerUrl[];
extern const char kGaiaUrl[];
extern const char kCloudPrintGaiaServiceId[];
Expand Down
4 changes: 2 additions & 2 deletions chrome/service/cloud_print/cloud_print_proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "chrome/common/pref_names.h"
#include "chrome/common/json_pref_store.h"
#include "chrome/service/cloud_print/cloud_print_consts.h"
#include "chrome/service/cloud_print/print_system.h"
#include "chrome/service/service_process.h"

// This method is invoked on the IO thread to launch the browser process to
Expand Down Expand Up @@ -133,7 +134,7 @@ void CloudPrintProxy::Shutdown() {

// Notification methods from the backend. Called on UI thread.
void CloudPrintProxy::OnPrinterListAvailable(
const cloud_print::PrinterList& printer_list) {
const printing::PrinterList& printer_list) {
DCHECK(CalledOnValidThread());
// We could potentially show UI here allowing the user to select which
// printers to register. For now, we just register all.
Expand Down Expand Up @@ -163,4 +164,3 @@ void CloudPrintProxy::OnAuthenticationFailed() {
g_service_process->io_thread()->message_loop_proxy()->PostTask(
FROM_HERE, NewRunnableFunction(&ShowTokenExpiredNotificationInBrowser));
}

3 changes: 1 addition & 2 deletions chrome/service/cloud_print/cloud_print_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class CloudPrintProxy : public CloudPrintProxyFrontend,

// Notification methods from the backend. Called on UI thread.
virtual void OnPrinterListAvailable(
const cloud_print::PrinterList& printer_list);
const printing::PrinterList& printer_list);
virtual void OnAuthenticated(const std::string& cloud_print_token,
const std::string& cloud_print_xmpp_token,
const std::string& email);
Expand All @@ -72,4 +72,3 @@ class CloudPrintProxy : public CloudPrintProxyFrontend,
};

#endif // CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_PROXY_H_

36 changes: 19 additions & 17 deletions chrome/service/cloud_print/cloud_print_proxy_backend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

#include "chrome/service/cloud_print/cloud_print_proxy_backend.h"

#include <map>
#include <vector>

#include "base/file_util.h"
#include "base/md5.h"
#include "base/rand_util.h"
Expand All @@ -17,11 +20,10 @@
#include "chrome/service/cloud_print/printer_job_handler.h"
#include "chrome/service/gaia/service_gaia_authenticator.h"
#include "chrome/service/service_process.h"
#include "googleurl/src/gurl.h"
#include "jingle/notifier/base/notifier_options.h"
#include "jingle/notifier/listener/push_notifications_thread.h"
#include "jingle/notifier/listener/talk_mediator_impl.h"

#include "googleurl/src/gurl.h"
#include "net/url_request/url_request_status.h"

// The real guts of CloudPrintProxyBackend, to keep the public client API clean.
Expand Down Expand Up @@ -58,7 +60,7 @@ class CloudPrintProxyBackend::Core
// shutdown.
void DoShutdown();
void DoRegisterSelectedPrinters(
const cloud_print::PrinterList& printer_list);
const printing::PrinterList& printer_list);

// URLFetcher::Delegate implementation.
virtual void OnURLFetchComplete(const URLFetcher* source, const GURL& url,
Expand Down Expand Up @@ -103,7 +105,7 @@ class CloudPrintProxyBackend::Core
// NotifyXXX is how the Core communicates with the frontend across
// threads.
void NotifyPrinterListAvailable(
const cloud_print::PrinterList& printer_list);
const printing::PrinterList& printer_list);
void NotifyAuthenticated(
const std::string& cloud_print_token,
const std::string& cloud_print_xmpp_token,
Expand Down Expand Up @@ -149,7 +151,7 @@ class CloudPrintProxyBackend::Core
// registered. We then pass a copy of this list to the frontend to give the
// user a chance to further trim the list. When the frontend gives us the
// final list we make a copy into this so that we can start registering.
cloud_print::PrinterList printer_list_;
printing::PrinterList printer_list_;
// The URLFetcher instance for the current request
scoped_ptr<URLFetcher> request_;
// The index of the nex printer to be uploaded.
Expand All @@ -164,7 +166,7 @@ class CloudPrintProxyBackend::Core
// so we won't have to requery the printer if the upload fails and we need
// to retry.
std::string last_uploaded_printer_name_;
cloud_print::PrinterCapsAndDefaults last_uploaded_printer_info_;
printing::PrinterCapsAndDefaults last_uploaded_printer_info_;
// A map of printer id to job handler.
typedef std::map<std::string, scoped_refptr<PrinterJobHandler> >
JobHandlerMap;
Expand Down Expand Up @@ -235,7 +237,7 @@ void CloudPrintProxyBackend::Shutdown() {
}

void CloudPrintProxyBackend::RegisterPrinters(
const cloud_print::PrinterList& printer_list) {
const printing::PrinterList& printer_list) {
core_thread_.message_loop()->PostTask(FROM_HERE,
NewRunnableMethod(
core_.get(),
Expand Down Expand Up @@ -344,7 +346,7 @@ void CloudPrintProxyBackend::Core::DoInitializeWithToken(
void CloudPrintProxyBackend::Core::StartRegistration() {
DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop());
printer_list_.clear();
print_system_->EnumeratePrinters(&printer_list_);
print_system_->GetPrintBackend()->EnumeratePrinters(&printer_list_);
server_error_count_ = 0;
// Now we need to ask the server about printers that were registered on the
// server so that we can trim this list.
Expand Down Expand Up @@ -381,7 +383,7 @@ void CloudPrintProxyBackend::Core::DoShutdown() {
}

void CloudPrintProxyBackend::Core::DoRegisterSelectedPrinters(
const cloud_print::PrinterList& printer_list) {
const printing::PrinterList& printer_list) {
DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop());
if (!print_system_.get())
return; // No print system available.
Expand Down Expand Up @@ -409,14 +411,15 @@ void CloudPrintProxyBackend::Core::RegisterNextPrinter() {
// For the next printer to be uploaded, create a multi-part post request to
// upload the printer capabilities and the printer defaults.
if (next_upload_index_ < printer_list_.size()) {
const cloud_print::PrinterBasicInfo& info =
const printing::PrinterBasicInfo& info =
printer_list_.at(next_upload_index_);
bool have_printer_info = true;
// If we are retrying a previous upload, we don't need to fetch the caps
// and defaults again.
if (info.printer_name != last_uploaded_printer_name_) {
have_printer_info = print_system_->GetPrinterCapsAndDefaults(
info.printer_name.c_str(), &last_uploaded_printer_info_);
have_printer_info =
print_system_->GetPrintBackend()->GetPrinterCapsAndDefaults(
info.printer_name.c_str(), &last_uploaded_printer_info_);
}
if (have_printer_info) {
last_uploaded_printer_name_ = info.printer_name;
Expand Down Expand Up @@ -536,7 +539,7 @@ void CloudPrintProxyBackend::Core::OnURLFetchComplete(
}

void CloudPrintProxyBackend::Core::NotifyPrinterListAvailable(
const cloud_print::PrinterList& printer_list) {
const printing::PrinterList& printer_list) {
DCHECK(MessageLoop::current() == backend_->frontend_loop_);
backend_->frontend_->OnPrinterListAvailable(printer_list);
}
Expand Down Expand Up @@ -617,7 +620,7 @@ void CloudPrintProxyBackend::Core::InitJobHandlerForPrinter(
printer_info_cloud.printer_id);
// We might already have a job handler for this printer
if (index == job_handler_map_.end()) {
cloud_print::PrinterBasicInfo printer_info;
printing::PrinterBasicInfo printer_info;
printer_data->GetString(kNameValue, &printer_info.printer_name);
DCHECK(!printer_info.printer_name.empty());
printer_data->GetString(kPrinterDescValue,
Expand All @@ -635,7 +638,7 @@ void CloudPrintProxyBackend::Core::InitJobHandlerForPrinter(
if (StartsWithASCII(tag, kTagsHashTagName, false)) {
std::vector<std::string> tag_parts;
base::SplitStringDontTrim(tag, '=', &tag_parts);
DCHECK(tag_parts.size() == 2);
DCHECK_EQ(tag_parts.size(), 2U);
if (tag_parts.size() == 2)
printer_info_cloud.tags_hash = tag_parts[1];
}
Expand Down Expand Up @@ -695,7 +698,7 @@ void CloudPrintProxyBackend::Core::HandleServerError(Task* task_to_retry) {
bool CloudPrintProxyBackend::Core::RemovePrinterFromList(
const std::string& printer_name) {
DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop());
for (cloud_print::PrinterList::iterator index = printer_list_.begin();
for (printing::PrinterList::iterator index = printer_list_.begin();
index != printer_list_.end(); index++) {
if (0 == base::strcasecmp(index->printer_name.c_str(),
printer_name.c_str())) {
Expand Down Expand Up @@ -758,4 +761,3 @@ void CloudPrintProxyBackend::Core::OnAuthError() {
backend_->frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(this,
&Core::NotifyAuthenticationFailed));
}

7 changes: 3 additions & 4 deletions chrome/service/cloud_print/cloud_print_proxy_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
#include <string>

#include "base/thread.h"
#include "chrome/service/cloud_print/print_system.h"
#include "chrome/common/net/url_fetcher.h"
#include "googleurl/src/gurl.h"
#include "printing/backend/print_backend.h"

class CloudPrintProxyService;
class DictionaryValue;
Expand All @@ -27,7 +27,7 @@ class CloudPrintProxyFrontend {

// There is a list of printers available that can be registered.
virtual void OnPrinterListAvailable(
const cloud_print::PrinterList& printer_list) = 0;
const printing::PrinterList& printer_list) = 0;
// We successfully authenticated with the cloud print server. This callback
// allows the frontend to persist the tokens.
virtual void OnAuthenticated(const std::string& cloud_print_token,
Expand Down Expand Up @@ -59,7 +59,7 @@ class CloudPrintProxyBackend {
const std::string email,
const std::string& proxy_id);
void Shutdown();
void RegisterPrinters(const cloud_print::PrinterList& printer_list);
void RegisterPrinters(const printing::PrinterList& printer_list);

private:
// The real guts of SyncBackendHost, to keep the public client API clean.
Expand All @@ -82,4 +82,3 @@ class CloudPrintProxyBackend {
};

#endif // CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_PROXY_BACKEND_H_

4 changes: 0 additions & 4 deletions chrome/service/cloud_print/print_system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@

namespace cloud_print {

PrinterBasicInfo::PrinterBasicInfo() : printer_status(0) {}

PrinterBasicInfo::~PrinterBasicInfo() {}

PrintJobDetails::PrintJobDetails()
: status(PRINT_JOB_STATUS_INVALID),
platform_status_flags(0),
Expand Down
40 changes: 10 additions & 30 deletions chrome/service/cloud_print/print_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,16 @@
class DictionaryValue;
class FilePath;

namespace printing {
class PrintBackend;
struct PrinterBasicInfo;
}

// This is the interface for platform-specific code for cloud print
namespace cloud_print {

typedef int PlatformJobId;

struct PrinterBasicInfo {
PrinterBasicInfo();
~PrinterBasicInfo();

std::string printer_name;
std::string printer_description;
int printer_status;
std::map<std::string, std::string> options;
};

typedef std::vector<PrinterBasicInfo> PrinterList;

struct PrinterCapsAndDefaults {
std::string printer_capabilities;
std::string caps_mime_type;
std::string printer_defaults;
std::string defaults_mime_type;
};

enum PrintJobStatus {
PRINT_JOB_STATUS_INVALID,
PRINT_JOB_STATUS_IN_PROGRESS,
Expand Down Expand Up @@ -75,7 +61,7 @@ struct PrintJobDetails {
// obtain available printing system.
// Please note, that PrintSystem is not platform specific, but rather
// print system specific. For example, CUPS is available on both Linux and Mac,
// but not avaialble on ChromeOS, etc. This design allows us to add more
// but not available on ChromeOS, etc. This design allows us to add more
// functionality on some platforms, while reusing core (CUPS) functions.
class PrintSystem : public base::RefCountedThreadSafe<PrintSystem> {
public:
Expand Down Expand Up @@ -113,7 +99,8 @@ class PrintSystem : public base::RefCountedThreadSafe<PrintSystem> {
virtual ~PrinterWatcher();
virtual bool StartWatching(PrinterWatcher::Delegate* delegate) = 0;
virtual bool StopWatching() = 0;
virtual bool GetCurrentPrinterInfo(PrinterBasicInfo* printer_info) = 0;
virtual bool GetCurrentPrinterInfo(
printing::PrinterBasicInfo* printer_info) = 0;
};

class JobSpooler : public base::RefCountedThreadSafe<JobSpooler> {
Expand Down Expand Up @@ -141,12 +128,8 @@ class PrintSystem : public base::RefCountedThreadSafe<PrintSystem> {

virtual ~PrintSystem();

// Enumerates the list of installed local and network printers.
virtual void EnumeratePrinters(PrinterList* printer_list) = 0;

// Gets the capabilities and defaults for a specific printer.
virtual bool GetPrinterCapsAndDefaults(const std::string& printer_name,
PrinterCapsAndDefaults* printer_info) = 0;
// Get the printing backend.
virtual printing::PrintBackend* GetPrintBackend() = 0;

// Returns true if ticket is valid.
virtual bool ValidatePrintTicket(const std::string& printer_name,
Expand All @@ -157,9 +140,6 @@ class PrintSystem : public base::RefCountedThreadSafe<PrintSystem> {
PlatformJobId job_id,
PrintJobDetails *job_details) = 0;

// Returns true if printer_name points to a valid printer.
virtual bool IsValidPrinter(const std::string& printer_name) = 0;

// Factory methods to create corresponding watcher. Callee is responsible
// for deleting objects. Return NULL if failed.
virtual PrintServerWatcher* CreatePrintServerWatcher() = 0;
Expand Down
Loading

0 comments on commit 8e553f4

Please sign in to comment.