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

Unified Diff: cloud_print/gcp20/prototype/cloud_print_request.h

Issue 19866002: GCP2.0 Device: Receiving printjobs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@confirmation
Patch Set: Created 7 years, 5 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 side-by-side diff with in-line comments
Download patch
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..9c82fe8c9a421a1411e0eba4cba86283956084b5
--- /dev/null
+++ b/cloud_print/gcp20/prototype/cloud_print_request.h
@@ -0,0 +1,97 @@
+// 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;
+
+ // 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;
gene 2013/07/23 09:36:23 GetAccessToken() - ??? By formatting function a ge
maksymb 2013/07/23 19:02:37 Done.
+
+ // Invoked when context_getter is needed.
+ virtual scoped_refptr<net::URLRequestContextGetter> context_getter() = 0;
gene 2013/07/23 09:36:23 GetContextGetter() same here
maksymb 2013/07/23 19:02:37 Done.
+ };
+
+ typedef base::Callback<void(const std::string&)> ParserCallback;
+
+ struct DataForUpload {
gene 2013/07/23 09:36:23 Looks like you use this struct only once to pass p
maksymb 2013/07/23 19:02:37 Done.
+ std::string content;
+ std::string content_type;
+ };
+
+ virtual ~CloudPrintRequest();
+
+ // Creates GET request.
+ static scoped_ptr<CloudPrintRequest> CreateGet(
+ const GURL& url,
gene 2013/07/23 09:36:23 nit: looks like you can put params to the function
maksymb 2013/07/23 19:02:37 Done.
+ Delegate* delegate);
+
+ // Creates POST request.
+ static scoped_ptr<CloudPrintRequest> CreatePost(
+ const GURL& url,
gene 2013/07/23 09:36:23 nit: as above comment?
maksymb 2013/07/23 19:02:37 Done.
+ const DataForUpload& data,
+ Delegate* delegate);
+
+ // Starts request. Once fetch was completed, parser will be called.
+ void Run(const ParserCallback& parser);
gene 2013/07/23 09:36:23 This is really confusing. Why do you need both del
maksymb 2013/07/23 19:02:37 Left Delegate only.
+
+ // 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_
+
« no previous file with comments | « no previous file | cloud_print/gcp20/prototype/cloud_print_request.cc » ('j') | cloud_print/gcp20/prototype/cloud_print_request.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698