1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_HTTP_H_
6 #define CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_HTTP_H_
10 #include "base/callback.h"
11 #include "chrome/browser/local_discovery/privet_url_fetcher.h"
12 #include "chrome/browser/local_discovery/pwg_raster_converter.h"
13 #include "net/base/host_port_pair.h"
16 class RefCountedBytes
;
24 class PdfRenderSettings
;
27 namespace local_discovery
{
29 class PrivetHTTPClient
;
31 // Represents a simple request that returns pure JSON.
32 class PrivetJSONOperation
{
34 // If value is null, the operation failed.
35 typedef base::Callback
<void(
36 const base::DictionaryValue
* /*value*/)> ResultCallback
;
38 virtual ~PrivetJSONOperation() {}
40 virtual void Start() = 0;
42 virtual PrivetHTTPClient
* GetHTTPClient() = 0;
45 // Represents a full registration flow (/privet/register), normally consisting
46 // of calling the start action, the getClaimToken action, and calling the
47 // complete action. Some intervention from the caller is required to display the
48 // claim URL to the user (noted in OnPrivetRegisterClaimURL).
49 class PrivetRegisterOperation
{
55 FAILURE_MALFORMED_RESPONSE
,
64 // Called when a user needs to claim the printer by visiting the given URL.
65 virtual void OnPrivetRegisterClaimToken(
66 PrivetRegisterOperation
* operation
,
67 const std::string
& token
,
70 // TODO(noamsml): Remove all unnecessary parameters.
71 // Called in case of an error while registering. |action| is the
72 // registration action taken during the error. |reason| is the reason for
73 // the failure. |printer_http_code| is the http code returned from the
74 // printer. If it is -1, an internal error occurred while trying to complete
75 // the request. |json| may be null if printer_http_code signifies an error.
76 virtual void OnPrivetRegisterError(PrivetRegisterOperation
* operation
,
77 const std::string
& action
,
79 int printer_http_code
,
80 const base::DictionaryValue
* json
) = 0;
82 // Called when the registration is done.
83 virtual void OnPrivetRegisterDone(PrivetRegisterOperation
* operation
,
84 const std::string
& device_id
) = 0;
87 virtual ~PrivetRegisterOperation() {}
89 virtual void Start() = 0;
90 // Owner SHOULD call explicitly before destroying operation.
91 virtual void Cancel() = 0;
92 virtual void CompleteRegistration() = 0;
94 virtual PrivetHTTPClient
* GetHTTPClient() = 0;
97 class PrivetLocalPrintOperation
{
101 virtual ~Delegate() {}
102 virtual void OnPrivetPrintingDone(
103 const PrivetLocalPrintOperation
* print_operation
) = 0;
104 virtual void OnPrivetPrintingError(
105 const PrivetLocalPrintOperation
* print_operation
, int http_code
) = 0;
108 virtual ~PrivetLocalPrintOperation() {}
110 virtual void Start() = 0;
113 // Required print data. MUST be called before calling |Start()|.
114 virtual void SetData(base::RefCountedBytes
* data
) = 0;
116 // Optional attributes for /submitdoc. Call before calling |Start()|
117 // |ticket| should be in CJT format.
118 virtual void SetTicket(const std::string
& ticket
) = 0;
119 // Username and jobname are for display only.
120 virtual void SetUsername(const std::string
& username
) = 0;
121 virtual void SetJobname(const std::string
& jobname
) = 0;
122 // If |offline| is true, we will indicate to the printer not to post the job
123 // to Google Cloud Print.
124 virtual void SetOffline(bool offline
) = 0;
125 // Document page size.
126 virtual void SetConversionSettings(
127 const printing::PdfRenderSettings
& conversion_settings
) = 0;
129 // For testing, inject an alternative PWG raster converter.
130 virtual void SetPWGRasterConverterForTesting(
131 scoped_ptr
<PWGRasterConverter
> pwg_raster_converter
) = 0;
133 virtual PrivetHTTPClient
* GetHTTPClient() = 0;
136 // Privet HTTP client. Must not outlive the operations it creates.
137 class PrivetHTTPClient
{
139 virtual ~PrivetHTTPClient() {}
140 virtual const base::DictionaryValue
* GetCachedInfo() const = 0;
142 virtual scoped_ptr
<PrivetRegisterOperation
> CreateRegisterOperation(
143 const std::string
& user
,
144 PrivetRegisterOperation::Delegate
* delegate
) = 0;
145 virtual scoped_ptr
<PrivetJSONOperation
> CreateInfoOperation(
146 const PrivetJSONOperation::ResultCallback
& callback
) = 0;
147 virtual scoped_ptr
<PrivetJSONOperation
> CreateCapabilitiesOperation(
148 const PrivetJSONOperation::ResultCallback
& callback
) = 0;
149 virtual scoped_ptr
<PrivetLocalPrintOperation
> CreateLocalPrintOperation(
150 PrivetLocalPrintOperation::Delegate
* delegate
) = 0;
151 virtual scoped_ptr
<PrivetJSONOperation
> CreateStorageListOperation(
152 const std::string
& path
,
153 const PrivetJSONOperation::ResultCallback
& callback
) = 0;
155 // A name for the HTTP client, e.g. the device name for the privet device.
156 virtual const std::string
& GetName() = 0;
159 } // namespace local_discovery
160 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_HTTP_H_