Don't delete print system on connector stop.

It may contains cached printers list.

BUG=139001
TEST=none

Review URL: https://chromiumcodereview.appspot.com/10825172

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150199 0039d316-1c4b-4281-b951-d872f2087c98
parent 38071963
...@@ -34,26 +34,33 @@ CloudPrintConnector::CloudPrintConnector( ...@@ -34,26 +34,33 @@ CloudPrintConnector::CloudPrintConnector(
} }
} }
bool CloudPrintConnector::Start() { bool CloudPrintConnector::InitPrintSystem() {
DCHECK(!print_system_.get()); if (print_system_.get())
VLOG(1) << "CP_CONNECTOR: Starting connector" return true;
<< ", proxy id: " << proxy_id_; print_system_ = cloud_print::PrintSystem::CreateInstance(
print_system_settings_.get());
pending_tasks_.clear();
print_system_ =
cloud_print::PrintSystem::CreateInstance(print_system_settings_.get());
if (!print_system_.get()) { if (!print_system_.get()) {
NOTREACHED(); NOTREACHED();
return false; // No print system available, fail initalization. return false; // No memory.
} }
cloud_print::PrintSystem::PrintSystemResult result = print_system_->Init(); cloud_print::PrintSystem::PrintSystemResult result = print_system_->Init();
if (!result.succeeded()) { if (!result.succeeded()) {
print_system_.release();
// We could not initialize the print system. We need to notify the server. // We could not initialize the print system. We need to notify the server.
ReportUserMessage(kPrintSystemFailedMessageId, result.message()); ReportUserMessage(kPrintSystemFailedMessageId, result.message());
print_system_.release();
return false; return false;
} }
return true;
}
bool CloudPrintConnector::Start() {
VLOG(1) << "CP_CONNECTOR: Starting connector"
<< ", proxy id: " << proxy_id_;
pending_tasks_.clear();
if (!InitPrintSystem())
return false;
// Start watching for updates from the print system. // Start watching for updates from the print system.
print_server_watcher_ = print_system_->CreatePrintServerWatcher(); print_server_watcher_ = print_system_->CreatePrintServerWatcher();
...@@ -67,18 +74,15 @@ bool CloudPrintConnector::Start() { ...@@ -67,18 +74,15 @@ bool CloudPrintConnector::Start() {
void CloudPrintConnector::Stop() { void CloudPrintConnector::Stop() {
VLOG(1) << "CP_CONNECTOR: Stopping connector" VLOG(1) << "CP_CONNECTOR: Stopping connector"
<< ", proxy id: " << proxy_id_; << ", proxy id: " << proxy_id_;
DCHECK(print_system_.get()); DCHECK(IsRunning());
if (print_system_.get()) { // Do uninitialization here.
// Do uninitialization here. pending_tasks_.clear();
pending_tasks_.clear(); print_server_watcher_.release();
print_server_watcher_.release();
print_system_.release();
}
request_ = NULL; request_ = NULL;
} }
bool CloudPrintConnector::IsRunning() { bool CloudPrintConnector::IsRunning() {
return print_system_.get() != NULL; return print_server_watcher_.get() != NULL;
} }
void CloudPrintConnector::GetPrinterIds(std::list<std::string>* printer_ids) { void CloudPrintConnector::GetPrinterIds(std::list<std::string>* printer_ids) {
......
...@@ -158,6 +158,7 @@ class CloudPrintConnector ...@@ -158,6 +158,7 @@ class CloudPrintConnector
const printing::PrinterCapsAndDefaults& caps_and_defaults); const printing::PrinterCapsAndDefaults& caps_and_defaults);
bool IsSamePrinter(const std::string& name1, const std::string& name2) const; bool IsSamePrinter(const std::string& name1, const std::string& name2) const;
bool InitPrintSystem();
// CloudPrintConnector client. // CloudPrintConnector client.
Client* client_; Client* client_;
...@@ -178,7 +179,7 @@ class CloudPrintConnector ...@@ -178,7 +179,7 @@ class CloudPrintConnector
JobHandlerMap job_handler_map_; JobHandlerMap job_handler_map_;
// Next response handler. // Next response handler.
ResponseHandler next_response_handler_; ResponseHandler next_response_handler_;
// The list of peding tasks to be done in the background. // The list of pending tasks to be done in the background.
std::list<PendingTask> pending_tasks_; std::list<PendingTask> pending_tasks_;
// The CloudPrintURLFetcher instance for the current request. // The CloudPrintURLFetcher instance for the current request.
scoped_refptr<CloudPrintURLFetcher> request_; scoped_refptr<CloudPrintURLFetcher> request_;
......
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