Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(129)

Side by Side Diff: chrome/service/cloud_print/cloud_print_connector.cc

Issue 10825172: Don't delete print system on connector stop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/service/cloud_print/cloud_print_connector.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/service/cloud_print/cloud_print_connector.h" 5 #include "chrome/service/cloud_print/cloud_print_connector.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/md5.h" 9 #include "base/md5.h"
10 #include "base/rand_util.h" 10 #include "base/rand_util.h"
(...skipping 16 matching lines...) Expand all
27 : client_(client), 27 : client_(client),
28 proxy_id_(proxy_id), 28 proxy_id_(proxy_id),
29 cloud_print_server_url_(cloud_print_server_url), 29 cloud_print_server_url_(cloud_print_server_url),
30 next_response_handler_(NULL) { 30 next_response_handler_(NULL) {
31 if (print_system_settings) { 31 if (print_system_settings) {
32 // It is possible to have no print settings specified. 32 // It is possible to have no print settings specified.
33 print_system_settings_.reset(print_system_settings->DeepCopy()); 33 print_system_settings_.reset(print_system_settings->DeepCopy());
34 } 34 }
35 } 35 }
36 36
37 bool CloudPrintConnector::InitPrintSystem() {
38 if (print_system_.get())
39 return true;
40 print_system_ = cloud_print::PrintSystem::CreateInstance(
41 print_system_settings_.get());
42 if (!print_system_.get()) {
43 NOTREACHED();
44 return false; // No memory.
45 }
46 cloud_print::PrintSystem::PrintSystemResult result = print_system_->Init();
47 if (!result.succeeded()) {
48 print_system_.release();
49 // We could not initialize the print system. We need to notify the server.
50 ReportUserMessage(kPrintSystemFailedMessageId, result.message());
51 return false;
52 }
53 return true;
54 }
55
37 bool CloudPrintConnector::Start() { 56 bool CloudPrintConnector::Start() {
38 DCHECK(!print_system_.get());
39 VLOG(1) << "CP_CONNECTOR: Starting connector" 57 VLOG(1) << "CP_CONNECTOR: Starting connector"
40 << ", proxy id: " << proxy_id_; 58 << ", proxy id: " << proxy_id_;
41 59
42 pending_tasks_.clear(); 60 pending_tasks_.clear();
43 61
44 print_system_ = 62 if (!InitPrintSystem())
45 cloud_print::PrintSystem::CreateInstance(print_system_settings_.get());
46 if (!print_system_.get()) {
47 NOTREACHED();
48 return false; // No print system available, fail initalization.
49 }
50 cloud_print::PrintSystem::PrintSystemResult result = print_system_->Init();
51 if (!result.succeeded()) {
52 // We could not initialize the print system. We need to notify the server.
53 ReportUserMessage(kPrintSystemFailedMessageId, result.message());
54 print_system_.release();
55 return false; 63 return false;
56 }
57 64
58 // Start watching for updates from the print system. 65 // Start watching for updates from the print system.
59 print_server_watcher_ = print_system_->CreatePrintServerWatcher(); 66 print_server_watcher_ = print_system_->CreatePrintServerWatcher();
60 print_server_watcher_->StartWatching(this); 67 print_server_watcher_->StartWatching(this);
61 68
62 // Get list of registered printers. 69 // Get list of registered printers.
63 AddPendingAvailableTask(); 70 AddPendingAvailableTask();
64 return true; 71 return true;
65 } 72 }
66 73
67 void CloudPrintConnector::Stop() { 74 void CloudPrintConnector::Stop() {
68 VLOG(1) << "CP_CONNECTOR: Stopping connector" 75 VLOG(1) << "CP_CONNECTOR: Stopping connector"
69 << ", proxy id: " << proxy_id_; 76 << ", proxy id: " << proxy_id_;
70 DCHECK(print_system_.get()); 77 DCHECK(IsRunning());
71 if (print_system_.get()) { 78 // Do uninitialization here.
72 // Do uninitialization here. 79 pending_tasks_.clear();
73 pending_tasks_.clear(); 80 print_server_watcher_.release();
74 print_server_watcher_.release();
75 print_system_.release();
76 }
77 request_ = NULL; 81 request_ = NULL;
78 } 82 }
79 83
80 bool CloudPrintConnector::IsRunning() { 84 bool CloudPrintConnector::IsRunning() {
81 return print_system_.get() != NULL; 85 return print_server_watcher_.get() != NULL;
82 } 86 }
83 87
84 void CloudPrintConnector::GetPrinterIds(std::list<std::string>* printer_ids) { 88 void CloudPrintConnector::GetPrinterIds(std::list<std::string>* printer_ids) {
85 DCHECK(printer_ids); 89 DCHECK(printer_ids);
86 printer_ids->clear(); 90 printer_ids->clear();
87 for (JobHandlerMap::const_iterator iter = job_handler_map_.begin(); 91 for (JobHandlerMap::const_iterator iter = job_handler_map_.begin();
88 iter != job_handler_map_.end(); ++iter) { 92 iter != job_handler_map_.end(); ++iter) {
89 printer_ids->push_back(iter->first); 93 printer_ids->push_back(iter->first);
90 } 94 }
91 } 95 }
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 mime_type, 554 mime_type,
551 post_data, 555 post_data,
552 &CloudPrintConnector::HandleRegisterPrinterResponse); 556 &CloudPrintConnector::HandleRegisterPrinterResponse);
553 } 557 }
554 558
555 bool CloudPrintConnector::IsSamePrinter(const std::string& name1, 559 bool CloudPrintConnector::IsSamePrinter(const std::string& name1,
556 const std::string& name2) const { 560 const std::string& name2) const {
557 return (0 == base::strcasecmp(name1.c_str(), name2.c_str())); 561 return (0 == base::strcasecmp(name1.c_str(), name2.c_str()));
558 } 562 }
559 563
OLDNEW
« no previous file with comments | « chrome/service/cloud_print/cloud_print_connector.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698