OLD | NEW |
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 #ifndef CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_CONNECTOR_H_ | 5 #ifndef CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_CONNECTOR_H_ |
6 #define CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_CONNECTOR_H_ | 6 #define CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_CONNECTOR_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "chrome/service/cloud_print/connector_settings.h" | 14 #include "chrome/service/cloud_print/connector_settings.h" |
15 #include "chrome/service/cloud_print/print_system.h" | 15 #include "chrome/service/cloud_print/print_system.h" |
16 #include "chrome/service/cloud_print/printer_job_handler.h" | 16 #include "chrome/service/cloud_print/printer_job_handler.h" |
17 | 17 |
| 18 namespace cloud_print { |
| 19 |
18 // CloudPrintConnector handles top printer management tasks. | 20 // CloudPrintConnector handles top printer management tasks. |
19 // - Matching local and cloud printers | 21 // - Matching local and cloud printers |
20 // - Registration of local printers | 22 // - Registration of local printers |
21 // - Deleting cloud printers | 23 // - Deleting cloud printers |
22 // All tasks are posted to the common queue (PendingTasks) and executed | 24 // All tasks are posted to the common queue (PendingTasks) and executed |
23 // one-by-one in FIFO order. | 25 // one-by-one in FIFO order. |
24 // CloudPrintConnector will notify client over Client interface. | 26 // CloudPrintConnector will notify client over Client interface. |
25 class CloudPrintConnector | 27 class CloudPrintConnector |
26 : public base::RefCountedThreadSafe<CloudPrintConnector>, | 28 : public base::RefCountedThreadSafe<CloudPrintConnector>, |
27 private cloud_print::PrintServerWatcherDelegate, | 29 private PrintServerWatcherDelegate, |
28 private PrinterJobHandlerDelegate, | 30 private PrinterJobHandlerDelegate, |
29 private CloudPrintURLFetcherDelegate { | 31 private CloudPrintURLFetcherDelegate { |
30 public: | 32 public: |
31 class Client { | 33 class Client { |
32 public: | 34 public: |
33 virtual void OnAuthFailed() = 0; | 35 virtual void OnAuthFailed() = 0; |
34 protected: | 36 protected: |
35 virtual ~Client() {} | 37 virtual ~Client() {} |
36 }; | 38 }; |
37 | 39 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 PendingTaskType type; | 73 PendingTaskType type; |
72 // Optional members, depending on type. | 74 // Optional members, depending on type. |
73 std::string printer_id; // For pending delete. | 75 std::string printer_id; // For pending delete. |
74 printing::PrinterBasicInfo printer_info; // For pending registration. | 76 printing::PrinterBasicInfo printer_info; // For pending registration. |
75 | 77 |
76 PendingTask() : type(PENDING_PRINTERS_NONE) {} | 78 PendingTask() : type(PENDING_PRINTERS_NONE) {} |
77 ~PendingTask() {} | 79 ~PendingTask() {} |
78 }; | 80 }; |
79 | 81 |
80 virtual ~CloudPrintConnector(); | 82 virtual ~CloudPrintConnector(); |
81 // cloud_print::PrintServerWatcherDelegate implementation | 83 // PrintServerWatcherDelegate implementation |
82 virtual void OnPrinterAdded() OVERRIDE; | 84 virtual void OnPrinterAdded() OVERRIDE; |
83 // PrinterJobHandler::Delegate implementation | 85 // PrinterJobHandler::Delegate implementation |
84 virtual void OnPrinterDeleted(const std::string& printer_name) OVERRIDE; | 86 virtual void OnPrinterDeleted(const std::string& printer_name) OVERRIDE; |
85 virtual void OnAuthError() OVERRIDE; | 87 virtual void OnAuthError() OVERRIDE; |
86 | 88 |
87 // CloudPrintURLFetcher::Delegate implementation. | 89 // CloudPrintURLFetcher::Delegate implementation. |
88 virtual CloudPrintURLFetcher::ResponseAction HandleRawData( | 90 virtual CloudPrintURLFetcher::ResponseAction HandleRawData( |
89 const net::URLFetcher* source, | 91 const net::URLFetcher* source, |
90 const GURL& url, | 92 const GURL& url, |
91 const std::string& data) OVERRIDE; | 93 const std::string& data) OVERRIDE; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 void RegisterPrinters(const printing::PrinterList& printers); | 157 void RegisterPrinters(const printing::PrinterList& printers); |
156 | 158 |
157 bool IsSamePrinter(const std::string& name1, const std::string& name2) const; | 159 bool IsSamePrinter(const std::string& name1, const std::string& name2) const; |
158 bool InitPrintSystem(); | 160 bool InitPrintSystem(); |
159 | 161 |
160 // CloudPrintConnector client. | 162 // CloudPrintConnector client. |
161 Client* client_; | 163 Client* client_; |
162 // Connector settings. | 164 // Connector settings. |
163 ConnectorSettings settings_; | 165 ConnectorSettings settings_; |
164 // Pointer to current print system. | 166 // Pointer to current print system. |
165 scoped_refptr<cloud_print::PrintSystem> print_system_; | 167 scoped_refptr<PrintSystem> print_system_; |
166 // Watcher for print system updates. | 168 // Watcher for print system updates. |
167 scoped_refptr<cloud_print::PrintSystem::PrintServerWatcher> | 169 scoped_refptr<PrintSystem::PrintServerWatcher> |
168 print_server_watcher_; | 170 print_server_watcher_; |
169 // A map of printer id to job handler. | 171 // A map of printer id to job handler. |
170 typedef std::map<std::string, scoped_refptr<PrinterJobHandler> > | 172 typedef std::map<std::string, scoped_refptr<PrinterJobHandler> > |
171 JobHandlerMap; | 173 JobHandlerMap; |
172 JobHandlerMap job_handler_map_; | 174 JobHandlerMap job_handler_map_; |
173 // Next response handler. | 175 // Next response handler. |
174 ResponseHandler next_response_handler_; | 176 ResponseHandler next_response_handler_; |
175 // The list of pending tasks to be done in the background. | 177 // The list of pending tasks to be done in the background. |
176 std::list<PendingTask> pending_tasks_; | 178 std::list<PendingTask> pending_tasks_; |
177 // The CloudPrintURLFetcher instance for the current request. | 179 // The CloudPrintURLFetcher instance for the current request. |
178 scoped_refptr<CloudPrintURLFetcher> request_; | 180 scoped_refptr<CloudPrintURLFetcher> request_; |
179 // The CloudPrintURLFetcher instance for the user message request. | 181 // The CloudPrintURLFetcher instance for the user message request. |
180 scoped_refptr<CloudPrintURLFetcher> user_message_request_; | 182 scoped_refptr<CloudPrintURLFetcher> user_message_request_; |
181 | 183 |
182 DISALLOW_COPY_AND_ASSIGN(CloudPrintConnector); | 184 DISALLOW_COPY_AND_ASSIGN(CloudPrintConnector); |
183 }; | 185 }; |
184 | 186 |
| 187 } // namespace cloud_print |
| 188 |
185 #endif // CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_CONNECTOR_H_ | 189 #endif // CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_CONNECTOR_H_ |
186 | 190 |
OLD | NEW |