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

Unified Diff: chrome/browser/chrome_to_mobile/receive/chrome_to_mobile_receive_device_manager.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
Index: chrome/browser/chrome_to_mobile/receive/chrome_to_mobile_receive_device_manager.h
diff --git a/chrome/browser/chrome_to_mobile/receive/chrome_to_mobile_receive_device_manager.h b/chrome/browser/chrome_to_mobile/receive/chrome_to_mobile_receive_device_manager.h
new file mode 100644
index 0000000000000000000000000000000000000000..25450aaee76b89e974885dcbbbb723d6a14b114a
--- /dev/null
+++ b/chrome/browser/chrome_to_mobile/receive/chrome_to_mobile_receive_device_manager.h
@@ -0,0 +1,127 @@
+// 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_RECEIVE_CHROME_TO_MOBILE_RECEIVE_DEVICE_MANAGER_H_
+#define CHROME_BROWSER_CHROME_TO_MOBILE_RECEIVE_CHROME_TO_MOBILE_RECEIVE_DEVICE_MANAGER_H_
+
+#include <map>
+#include <set>
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/threading/non_thread_safe.h"
+#include "chrome/browser/chrome_to_mobile/common/cloud_print_request.h"
+#include "googleurl/src/gurl.h"
+
+namespace net {
+class URLRequestContextGetter;
+} // namespace net
+
+namespace chrome_to_mobile_receive {
+
+// Class that starts the device as a receiver for the chrome-to-mobile feature.
+// This class associates the device with a google cloud printer to receive
+// chrome-to-mobile jobs.
+//
+// To use it, create a |manager| and start the device by calling
+// |CreateAndStart()| with an
+// |ChromeToMobileReceiveDeviceManager::Delegate| object which will be
+// called back when it finishes starting the device. The callback will be called
+// in the same thread where |manager| is created.
+class ChromeToMobileReceiveDeviceManager
+ : public base::NonThreadSafe,
+ public chrome_to_mobile::CloudPrintRequest::Delegate {
+ public:
+ class Delegate {
+ public:
+ Delegate();
+ virtual ~Delegate();
+ virtual void OnStartDeviceComplete(
+ ChromeToMobileReceiveDeviceManager* source) = 0;
+ };
+
+ // Creates a |ChromeToMobileReceiveDeviceManager| and starts the device by
+ // associating it with a printer at |cloud_print_service_url| with
+ // |printer_tags| to receive the chrome-to-mobile jobs. Request relevant
+ // settings are given in |_settings|.
+ //
+ // If |existing_printer_id| is nonempty, this method tries to associate this
+ // device with the printer identified by |existing_printer_id| and updates
+ // this printer with |printer_flags|.
+ //
+ // If |existing_printer_id| is empty or it fails to update the printer
+ // identified by |existing_printer_id|, a new printer will be registered.
+ //
+ // When it completes, it calls the |delegate|'s callback
+ // |OnStartDeviceComplete()|.
+ static ChromeToMobileReceiveDeviceManager* CreateAndStart(
+ const GURL& cloud_printer_server_url,
+ const std::string& existing_printer_id,
+ const std::map<std::string, std::string>& printer_tags,
+ const chrome_to_mobile::CloudPrintRequest::Settings& settings,
+ Delegate* delegate);
+ virtual ~ChromeToMobileReceiveDeviceManager();
+
+ std::string GetStartedPrinterId() const;
+ bool IsSuccess() const;
+ bool HasCloudPrintAuthError() const;
+ bool HasOAuth2AccessTokenFailure() const;
+
+ protected:
+ // |chrome_to_mobile::CloudPrintRequest::Delegate|.
+ virtual void OnRequestComplete(chrome_to_mobile::CloudPrintRequest* source)
+ OVERRIDE;
+
+ private:
+ // Constructs a |ChromeToMobileReceiveDeviceManager|.
+ ChromeToMobileReceiveDeviceManager(
+ const GURL& cloud_printer_server_url,
+ const std::string& existing_printer_id,
+ const std::map<std::string, std::string>& printer_tags,
+ const chrome_to_mobile::CloudPrintRequest::Settings& settings,
+ Delegate* delegate);
+
+ // Start up the device to receive chrome-to-mobile jobs.
+ void StartDevice();
+
+ // Methods that handle cloud print request when it completes. Returns true if
+ // |source| has been processed in this method.
+ bool HandleRegisterComplete(chrome_to_mobile::CloudPrintRequest* source);
+ bool HandleListComplete(chrome_to_mobile::CloudPrintRequest* source);
+ bool HandleDeleteComplete(chrome_to_mobile::CloudPrintRequest* source);
+ bool HandleUpdateComplete(chrome_to_mobile::CloudPrintRequest* source);
+
+ // Returns true if it has finished starting the device.
+ bool HasCompleted() const;
+
+ // Helper methods that handle requests sent to cloud print server.
+ void RegisterPrinter();
+ void DeletePrinter(const std::string& printer_id);
+ void CancelAllRequests();
+
+ // Variables passed in when constructed.
+ const GURL cloud_print_server_url_;
+ const std::string existing_printer_id_;
+ const std::map<std::string, std::string> printer_tags_;
+ const chrome_to_mobile::CloudPrintRequest::Settings settings_;
+ Delegate* const delegate_;
+
+ scoped_ptr<chrome_to_mobile::CloudPrintRequest> list_request_;
+ scoped_ptr<chrome_to_mobile::CloudPrintRequest> register_request_;
+ scoped_ptr<chrome_to_mobile::CloudPrintRequest> update_request_;
+ std::set<chrome_to_mobile::CloudPrintRequest*> delete_requests_;
+ enum {kStarting, kSuccess, kFail} start_status_;
+ // Id of the printer that is associated with this device when it has started.
+ std::string started_printer_id_;
+ bool has_oauth2_token_fetch_failure_;
+ bool has_cloud_print_auth_error_;
+
+ DISALLOW_COPY_AND_ASSIGN(ChromeToMobileReceiveDeviceManager);
+};
+
+} // namespace chrome_to_mobile_receive
+
+#endif // CHROME_BROWSER_CHROME_TO_MOBILE_RECEIVE_CHROME_TO_MOBILE_RECEIVE_DEVICE_MANAGER_H_
+

Powered by Google App Engine
This is Rietveld 408576698