Index: cloud_print/gcp20/prototype/cloud_print_request.h |
diff --git a/cloud_print/gcp20/prototype/cloud_print_request.h b/cloud_print/gcp20/prototype/cloud_print_request.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..20440fa05c0c1f603278740b1f9e7d8f3f5feef4 |
--- /dev/null |
+++ b/cloud_print/gcp20/prototype/cloud_print_request.h |
@@ -0,0 +1,96 @@ |
+// Copyright 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CLOUD_PRINT_GCP20_PROTOTYPE_CLOUD_PRINT_REQUEST_H_ |
+#define CLOUD_PRINT_GCP20_PROTOTYPE_CLOUD_PRINT_REQUEST_H_ |
+ |
+#include <string> |
+ |
+#include "base/basictypes.h" |
+#include "base/callback.h" |
+#include "base/memory/weak_ptr.h" |
+#include "net/url_request/url_fetcher.h" |
+#include "net/url_request/url_fetcher_delegate.h" |
+ |
+// Request to CloudPrint with timeout control. |
+// Delegate should delete this object once it is deleting. |
+class CloudPrintRequest : public net::URLFetcherDelegate, |
+ public base::SupportsWeakPtr<CloudPrintRequest> { |
+ public: |
+ class Delegate { |
+ public: |
+ Delegate() {} |
+ virtual ~Delegate() {} |
+ |
+ // Invoked when |fetcher_| finished fetching successfully. |
+ // Use for erasing instance of CloudPrintRequest class. |
+ virtual void OnFetchComplete() = 0; |
+ |
+ // Invoked when |fetcher_| finished fetching successfully. |
+ // Use for erasing instance of CloudPrintRequest class. |
+ virtual void OnFetchError(const std::string& server_api, |
+ int server_code, int server_http_code) = 0; |
Vitaly Buka (NO REVIEWS)
2013/07/22 23:46:02
line break before int server_http_code
maksymb
2013/07/23 00:40:38
Done.
|
+ |
+ // Invoked when timeout is reached. |
+ // Use for erasing instance of CloudPrintRequest class. |
+ virtual void OnFetchTimeoutReached() = 0; |
+ |
+ // Invoked when accesstoken is needed. |
+ virtual std::string access_token() = 0; |
+ |
+ // Invoked when context_getter is needed. |
+ virtual scoped_refptr<net::URLRequestContextGetter> context_getter() = 0; |
+ }; |
+ |
+ typedef base::Callback<void(const std::string&)> ParserCallback; |
+ |
+ struct DataForUpload { |
+ std::string content; |
+ std::string content_type; |
+ }; |
+ |
+ virtual ~CloudPrintRequest(); |
+ |
+ // Creates GET request. |
+ static scoped_ptr<CloudPrintRequest> CreateGet( |
+ const GURL& url, |
+ Delegate* delegate); |
+ |
+ // Creates POST request. |
+ static scoped_ptr<CloudPrintRequest> CreatePost( |
+ const GURL& url, |
+ const DataForUpload& data, |
+ Delegate* delegate); |
+ |
+ // Starts request. Once fetch was completed, parser will be called. |
+ void Run(const ParserCallback& parser); |
+ |
+ // Add header to request. |
+ void AddHeader(const std::string& header); |
+ |
+ private: |
+ explicit CloudPrintRequest(Delegate* delegate); |
+ |
+ // net::URLFetcherDelegate methods: |
+ virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
+ |
+ // Creates request. |
+ static scoped_ptr<CloudPrintRequest> CreateRequest( |
+ const GURL& url, |
+ net::URLFetcher::RequestType method, |
+ Delegate* delegate); |
+ |
+ // Method for handling timeout. |
+ void OnRequestTimeout(); |
+ |
+ scoped_ptr<net::URLFetcher> fetcher_; |
+ ParserCallback parser_; |
+ |
+ Delegate* delegate_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(CloudPrintRequest); |
+}; |
+ |
+#endif // CLOUD_PRINT_GCP20_PROTOTYPE_CLOUD_PRINT_REQUEST_H_ |
+ |