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

Unified Diff: chrome/browser/chrome_to_mobile/common/cloud_print_request.h

Issue 11038063: Support chrome_to_mobile job receiving Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix format Created 8 years, 1 month 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
« no previous file with comments | « no previous file | chrome/browser/chrome_to_mobile/common/cloud_print_request.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chrome_to_mobile/common/cloud_print_request.h
diff --git a/chrome/browser/chrome_to_mobile/common/cloud_print_request.h b/chrome/browser/chrome_to_mobile/common/cloud_print_request.h
new file mode 100644
index 0000000000000000000000000000000000000000..5bbe7dd23a3fbf04c279e418cee900561819e94f
--- /dev/null
+++ b/chrome/browser/chrome_to_mobile/common/cloud_print_request.h
@@ -0,0 +1,128 @@
+// Copyright 2012 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 CHROME_BROWSER_CHROME_TO_MOBILE_COMMON_CLOUD_PRINT_REQUEST_H_
+#define CHROME_BROWSER_CHROME_TO_MOBILE_COMMON_CLOUD_PRINT_REQUEST_H_
+
+#include <string>
+
+#include "base/threading/non_thread_safe.h"
+#include "net/url_request/url_fetcher.h"
+#include "net/url_request/url_fetcher_delegate.h"
+
+class GURL;
+
+namespace net {
+class URLRequestContextGetter;
+} // namespace net
+
+class OAuth2TokenService;
+
+namespace chrome_to_mobile {
+
+class CloudPrintRequestFactory;
+
+// Class for google cloud print requests authenticated by oauth2 refresh tokens
+// managed by an |OAuth2TokenService|.
+//
+// It handles the common process that applies to all cloud print server
+// requests, such as cloud print header settings, common parameter generation
+// and oauth2 access token fetching.
+//
+// To use this class, call |CloudPrintRequest::CreateAndStart()| to create an
+// instance and start it with (1) request data, (2) additional settings, and (3)
+// a pointer to the object to be notified when the request has been loaded,
+// which should inherit from |CloudPrintRequest::Delegate|.
+//
+// When the request is completed,
+// |CloudPrintRequest::Delegate::OnRequestComplete()| will be called with a
+// pointer to the |CloudPrintRequest|. From that point until the original
+// |CloudPrintRequest| instance is destroyed, accessor methods can be used to
+// check the status of the request.
+//
+// If the |CloudPrintRequest| is destroyed before the callback happens, the
+// request will be canceled and no callback will occur.
+//
+// The |CloudPrintRequest| instance can be created on any thread;
+// |CloudPrintRequest::Delegate::OnRequestComplete()| will be called back on
+// the same thread where the instance was craeted.
+class CloudPrintRequest : public base::NonThreadSafe {
+ public:
+ class Delegate {
+ public:
+ Delegate();
+ ~Delegate();
+ virtual void OnRequestComplete(CloudPrintRequest* source) = 0;
+ };
+
+ // Struct that contains request related information.
+ struct Settings {
+ Settings(const std::string& cloud_print_client_id,
+ net::URLRequestContextGetter* request_context_getter,
+ OAuth2TokenService* oauth2_token_service);
+ Settings();
+
+ std::string cloud_print_client_id;
+ net::URLRequestContextGetter* request_context_getter;
+ OAuth2TokenService* oauth2_token_service;
+ };
+
+ CloudPrintRequest();
+ virtual ~CloudPrintRequest();
+
+ // Creates a |CloudPrintRequest| and starts the request. A request that
+ // fetches oauth2 access token using |settings.oauth2_token_service| is sent
+ // before this method returns.
+ //
+ // Note for testing purpose, |CloudPrintRequestFactory| can be registered (by
+ // calling |SetFactory()|) to create |CloudPrintRequest|s. This method creates
+ // a |CloudPrintRequestImpl| if no factory registered, otherwise the
+ // registered factory is used to create requests.
+ static CloudPrintRequest* CreateAndStart(
+ const GURL& url,
+ const std::string& additional_header,
+ const net::URLFetcher::RequestType& request_type,
+ const std::string& post_data_mime_type,
+ const std::string& post_data,
+ const Settings& setting,
+ Delegate* delegate);
+
+ // Convenient methods for GET and Post Requests.
+ static CloudPrintRequest* CreateAndStartGetRequest(const GURL& request_url,
+ const Settings& settings,
+ Delegate* delegate);
+ static CloudPrintRequest* CreateAndStartPostRequest(
+ const GURL& request_url,
+ const std::string& post_data_mime_type,
+ const std::string& post_data,
+ const Settings& settings,
+ Delegate* delegate);
+
+ // APIs to access the request status.
+ // Returns true if it fails to get an oauth accss token to start the cloud
+ // print request.
+ virtual bool HasOAuth2AccessTokenFailure() const = 0;
+ // Returns true if it has received authentication error from google cloud
+ // print server.
+ virtual bool HasCloudPrintAuthError() const = 0;
+ // Returns the mime type if a response has been received; an empty string
+ // otherwise.
+ virtual std::string GetResponseMimeType() const = 0;
+ // Returns the response data as a string and sets |*success| true if a cloud
+ // response has been received with success response status and response code
+ // 200.
+ virtual std::string GetResponseData(bool* success) const = 0;
+
+ // Helper methods used in testing to set up testing
+ // |CloudPrintRequestFactory|.
+ static void SetFactory(CloudPrintRequestFactory* factory);
+ static CloudPrintRequestFactory* GetFactory();
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(CloudPrintRequest);
+};
+
+} // namespace chrome_to_mobile
+
+#endif // CHROME_BROWSER_CHROME_TO_MOBILE_COMMON_CLOUD_PRINT_REQUEST_H_
« no previous file with comments | « no previous file | chrome/browser/chrome_to_mobile/common/cloud_print_request.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698