#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/local_discovery/privet_http.h"
+#include "components/cloud_devices/common/cloud_device_description.h"
#include "printing/pdf_render_settings.h"
+namespace printing {
+struct PwgRasterSettings;
+};
+
namespace local_discovery {
-class PrivetHTTPClientImpl;
+class PrivetHTTPClient;
class PrivetInfoOperationImpl : public PrivetJSONOperation,
public PrivetURLFetcher::Delegate {
public:
- PrivetInfoOperationImpl(PrivetHTTPClientImpl* privet_client,
+ PrivetInfoOperationImpl(PrivetHTTPClient* privet_client,
const PrivetJSONOperation::ResultCallback& callback);
virtual ~PrivetInfoOperationImpl();
virtual void OnError(PrivetURLFetcher* fetcher,
PrivetURLFetcher::ErrorType error) OVERRIDE;
virtual void OnParsedJson(PrivetURLFetcher* fetcher,
- const base::DictionaryValue* value,
+ const base::DictionaryValue& value,
bool has_error) OVERRIDE;
private:
- PrivetHTTPClientImpl* privet_client_;
+ PrivetHTTPClient* privet_client_;
PrivetJSONOperation::ResultCallback callback_;
scoped_ptr<PrivetURLFetcher> url_fetcher_;
};
public PrivetURLFetcher::Delegate,
public base::SupportsWeakPtr<PrivetRegisterOperationImpl> {
public:
- PrivetRegisterOperationImpl(PrivetHTTPClientImpl* privet_client,
+ PrivetRegisterOperationImpl(PrivetHTTPClient* privet_client,
const std::string& user,
PrivetRegisterOperation::Delegate* delegate);
virtual ~PrivetRegisterOperationImpl();
PrivetURLFetcher::ErrorType error) OVERRIDE;
virtual void OnParsedJson(PrivetURLFetcher* fetcher,
- const base::DictionaryValue* value,
+ const base::DictionaryValue& value,
bool has_error) OVERRIDE;
virtual void OnNeedPrivetToken(
private:
class Cancelation : public PrivetURLFetcher::Delegate {
public:
- Cancelation(PrivetHTTPClientImpl* privet_client,
- const std::string& user);
+ Cancelation(PrivetHTTPClient* privet_client, const std::string& user);
virtual ~Cancelation();
virtual void OnError(PrivetURLFetcher* fetcher,
PrivetURLFetcher::ErrorType error) OVERRIDE;
virtual void OnParsedJson(PrivetURLFetcher* fetcher,
- const base::DictionaryValue* value,
+ const base::DictionaryValue& value,
bool has_error) OVERRIDE;
void Cleanup();
void StartInfoOperation();
void OnPrivetInfoDone(const base::DictionaryValue* value);
-
void StartResponse(const base::DictionaryValue& value);
void GetClaimTokenResponse(const base::DictionaryValue& value);
void CompleteResponse(const base::DictionaryValue& value);
std::string current_action_;
scoped_ptr<PrivetURLFetcher> url_fetcher_;
PrivetRegisterOperation::Delegate* delegate_;
- PrivetHTTPClientImpl* privet_client_;
+ PrivetHTTPClient* privet_client_;
ResponseHandler next_response_handler_;
// Required to ensure destroying completed register operations doesn't cause
// extraneous cancelations.
class PrivetJSONOperationImpl : public PrivetJSONOperation,
public PrivetURLFetcher::Delegate {
public:
- PrivetJSONOperationImpl(
- PrivetHTTPClientImpl* privet_client,
- const std::string& path,
- const std::string& query_params,
- const PrivetJSONOperation::ResultCallback& callback);
+ PrivetJSONOperationImpl(PrivetHTTPClient* privet_client,
+ const std::string& path,
+ const std::string& query_params,
+ const PrivetJSONOperation::ResultCallback& callback);
virtual ~PrivetJSONOperationImpl();
virtual void Start() OVERRIDE;
virtual void OnError(PrivetURLFetcher* fetcher,
PrivetURLFetcher::ErrorType error) OVERRIDE;
virtual void OnParsedJson(PrivetURLFetcher* fetcher,
- const base::DictionaryValue* value,
+ const base::DictionaryValue& value,
bool has_error) OVERRIDE;
virtual void OnNeedPrivetToken(
PrivetURLFetcher* fetcher,
const PrivetURLFetcher::TokenCallback& callback) OVERRIDE;
private:
- PrivetHTTPClientImpl* privet_client_;
+ PrivetHTTPClient* privet_client_;
std::string path_;
std::string query_params_;
PrivetJSONOperation::ResultCallback callback_;
public PrivetURLFetcher::Delegate {
public:
PrivetDataReadOperationImpl(
- PrivetHTTPClientImpl* privet_client,
+ PrivetHTTPClient* privet_client,
const std::string& path,
const std::string& query_params,
const PrivetDataReadOperation::ResultCallback& callback);
virtual void OnError(PrivetURLFetcher* fetcher,
PrivetURLFetcher::ErrorType error) OVERRIDE;
virtual void OnParsedJson(PrivetURLFetcher* fetcher,
- const base::DictionaryValue* value,
+ const base::DictionaryValue& value,
bool has_error) OVERRIDE;
virtual void OnNeedPrivetToken(
PrivetURLFetcher* fetcher,
const base::FilePath& file_path) OVERRIDE;
private:
- PrivetHTTPClientImpl* privet_client_;
+ PrivetHTTPClient* privet_client_;
std::string path_;
std::string query_params_;
int range_start_;
: public PrivetLocalPrintOperation,
public PrivetURLFetcher::Delegate {
public:
- PrivetLocalPrintOperationImpl(
- PrivetHTTPClientImpl* privet_client,
- PrivetLocalPrintOperation::Delegate* delegate);
+ PrivetLocalPrintOperationImpl(PrivetHTTPClient* privet_client,
+ PrivetLocalPrintOperation::Delegate* delegate);
virtual ~PrivetLocalPrintOperationImpl();
virtual void Start() OVERRIDE;
virtual void SetData(base::RefCountedBytes* data) OVERRIDE;
+ virtual void SetCapabilities(const std::string& capabilities) OVERRIDE;
+
virtual void SetTicket(const std::string& ticket) OVERRIDE;
virtual void SetUsername(const std::string& user) OVERRIDE;
virtual void OnError(PrivetURLFetcher* fetcher,
PrivetURLFetcher::ErrorType error) OVERRIDE;
virtual void OnParsedJson(PrivetURLFetcher* fetcher,
- const base::DictionaryValue* value,
+ const base::DictionaryValue& value,
bool has_error) OVERRIDE;
virtual void OnNeedPrivetToken(
PrivetURLFetcher* fetcher,
ResponseCallback;
void StartInitialRequest();
- void GetCapabilities();
void DoCreatejob();
void DoSubmitdoc();
void StartPrinting();
void OnPrivetInfoDone(const base::DictionaryValue* value);
- void OnCapabilitiesResponse(bool has_error,
- const base::DictionaryValue* value);
void OnSubmitdocResponse(bool has_error,
const base::DictionaryValue* value);
void OnCreatejobResponse(bool has_error,
const base::DictionaryValue* value);
void OnPWGRasterConverted(bool success, const base::FilePath& pwg_file_path);
+ void FillPwgRasterSettings(printing::PwgRasterSettings* transfrom_settings);
- PrivetHTTPClientImpl* privet_client_;
+ PrivetHTTPClient* privet_client_;
PrivetLocalPrintOperation::Delegate* delegate_;
ResponseCallback current_response_;
- std::string ticket_;
+ cloud_devices::CloudDeviceDescription ticket_;
+ cloud_devices::CloudDeviceDescription capabilities_;
+
scoped_refptr<base::RefCountedBytes> data_;
base::FilePath pwg_file_path_;
bool use_pdf_;
- bool has_capabilities_;
bool has_extended_workflow_;
bool started_;
bool offline_;
net::URLRequestContextGetter* request_context);
virtual ~PrivetHTTPClientImpl();
- virtual const base::DictionaryValue* GetCachedInfo() const OVERRIDE;
+ // PrivetHTTPClient implementation.
+ virtual const std::string& GetName() OVERRIDE;
+ virtual scoped_ptr<PrivetJSONOperation> CreateInfoOperation(
+ const PrivetJSONOperation::ResultCallback& callback) OVERRIDE;
+ virtual scoped_ptr<PrivetURLFetcher> CreateURLFetcher(
+ const GURL& url,
+ net::URLFetcher::RequestType request_type,
+ PrivetURLFetcher::Delegate* delegate) OVERRIDE;
+ virtual void RefreshPrivetToken(
+ const PrivetURLFetcher::TokenCallback& token_callback) OVERRIDE;
- virtual scoped_ptr<PrivetRegisterOperation> CreateRegisterOperation(
- const std::string& user,
- PrivetRegisterOperation::Delegate* delegate) OVERRIDE;
+ private:
+ typedef std::vector<PrivetURLFetcher::TokenCallback> TokenCallbackVector;
+ void OnPrivetInfoDone(const base::DictionaryValue* value);
+
+ std::string name_;
+ scoped_refptr<net::URLRequestContextGetter> request_context_;
+ net::HostPortPair host_port_;
+
+ scoped_ptr<PrivetJSONOperation> info_operation_;
+ TokenCallbackVector token_callbacks_;
+
+ DISALLOW_COPY_AND_ASSIGN(PrivetHTTPClientImpl);
+};
+
+class PrivetV1HTTPClientImpl : public PrivetV1HTTPClient {
+ public:
+ explicit PrivetV1HTTPClientImpl(scoped_ptr<PrivetHTTPClient> info_client);
+ virtual ~PrivetV1HTTPClientImpl();
+
+ virtual const std::string& GetName() OVERRIDE;
virtual scoped_ptr<PrivetJSONOperation> CreateInfoOperation(
const PrivetJSONOperation::ResultCallback& callback) OVERRIDE;
-
+ virtual scoped_ptr<PrivetRegisterOperation> CreateRegisterOperation(
+ const std::string& user,
+ PrivetRegisterOperation::Delegate* delegate) OVERRIDE;
virtual scoped_ptr<PrivetJSONOperation> CreateCapabilitiesOperation(
const PrivetJSONOperation::ResultCallback& callback) OVERRIDE;
-
virtual scoped_ptr<PrivetLocalPrintOperation> CreateLocalPrintOperation(
PrivetLocalPrintOperation::Delegate* delegate) OVERRIDE;
-
virtual scoped_ptr<PrivetJSONOperation> CreateStorageListOperation(
const std::string& path,
const PrivetJSONOperation::ResultCallback& callback) OVERRIDE;
-
virtual scoped_ptr<PrivetDataReadOperation> CreateStorageReadOperation(
const std::string& path,
const PrivetDataReadOperation::ResultCallback& callback) OVERRIDE;
- virtual const std::string& GetName() OVERRIDE;
-
- scoped_ptr<PrivetURLFetcher> CreateURLFetcher(
- const GURL& url,
- net::URLFetcher::RequestType request_type,
- PrivetURLFetcher::Delegate* delegate) const;
-
- void CacheInfo(const base::DictionaryValue* cached_info);
-
- bool HasToken() const;
-
- void RefreshPrivetToken(
- const PrivetURLFetcher::TokenCallback& token_callback);
-
private:
- typedef std::vector<PrivetURLFetcher::TokenCallback> TokenCallbackVector;
+ PrivetHTTPClient* info_client() { return info_client_.get(); }
- void OnPrivetInfoDone(const base::DictionaryValue* value);
-
- std::string name_;
- PrivetURLFetcherFactory fetcher_factory_;
- net::HostPortPair host_port_;
- scoped_ptr<base::DictionaryValue> cached_info_;
+ scoped_ptr<PrivetHTTPClient> info_client_;
- scoped_ptr<PrivetJSONOperation> info_operation_;
- TokenCallbackVector token_callbacks_;
+ DISALLOW_COPY_AND_ASSIGN(PrivetV1HTTPClientImpl);
};
} // namespace local_discovery