1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_PROXY_H_ 6 #define CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_PROXY_H_ 7 8 #include <list> 9 #include <string> 10 #include <vector> 11 12 #include "base/basictypes.h" 13 #include "base/memory/scoped_ptr.h" 14 #include "base/threading/non_thread_safe.h" 15 #include "chrome/service/cloud_print/cloud_print_proxy_backend.h" 16 #include "chrome/service/cloud_print/cloud_print_wipeout.h" 17 18 class ServiceProcessPrefs; 19 20 namespace cloud_print { 21 22 struct CloudPrintProxyInfo; 23 24 // CloudPrintProxy is the layer between the service process UI thread 25 // and the cloud print proxy backend. 26 class CloudPrintProxy : public CloudPrintProxyFrontend, 27 public CloudPrintWipeout::Client, 28 public base::NonThreadSafe { 29 public: 30 class Client { 31 public: 32 virtual ~Client() {} 33 virtual void OnCloudPrintProxyEnabled(bool persist_state) {} 34 virtual void OnCloudPrintProxyDisabled(bool persist_state) {} 35 }; 36 CloudPrintProxy(); 37 virtual ~CloudPrintProxy(); 38 39 // Initializes the object. This should be called every time an object of this 40 // class is constructed. 41 void Initialize(ServiceProcessPrefs* service_prefs, Client* client); 42 43 // Enables/disables cloud printing for the user 44 void EnableForUser(); 45 void EnableForUserWithRobot( 46 const std::string& robot_auth_code, 47 const std::string& robot_email, 48 const std::string& user_email, 49 const base::DictionaryValue& user_settings); 50 void UnregisterPrintersAndDisableForUser(); 51 void DisableForUser(); 52 // Returns the proxy info. 53 void GetProxyInfo(CloudPrintProxyInfo* info); 54 55 // Launches a browser to see if the proxy policy has been set. 56 void CheckCloudPrintProxyPolicy(); 57 58 const std::string& user_email() const { 59 return user_email_; 60 } 61 62 // CloudPrintProxyFrontend implementation. Called on UI thread. 63 virtual void OnAuthenticated(const std::string& robot_oauth_refresh_token, 64 const std::string& robot_email, 65 const std::string& user_email) OVERRIDE; 66 virtual void OnAuthenticationFailed() OVERRIDE; 67 virtual void OnPrintSystemUnavailable() OVERRIDE; 68 virtual void OnUnregisterPrinters( 69 const std::string& auth_token, 70 const std::list<std::string>& printer_ids) OVERRIDE; 71 72 // CloudPrintWipeout::Client implementation. 73 virtual void OnUnregisterPrintersComplete() OVERRIDE; 74 75 protected: 76 void ShutdownBackend(); 77 bool CreateBackend(); 78 79 // Our asynchronous backend to communicate with sync components living on 80 // other threads. 81 scoped_ptr<CloudPrintProxyBackend> backend_; 82 // This class does not own this. It is guaranteed to remain valid for the 83 // lifetime of this class. 84 ServiceProcessPrefs* service_prefs_; 85 // This class does not own this. If non-NULL, It is guaranteed to remain 86 // valid for the lifetime of this class. 87 Client* client_; 88 // The email address of the account used to authenticate to the Cloud Print 89 // service. 90 std::string user_email_; 91 // This is set to true when the Cloud Print proxy is enabled and after 92 // successful authentication with the Cloud Print service. 93 bool enabled_; 94 // Connector settings. 95 ConnectorSettings settings_; 96 // This is a cleanup class for unregistering printers on proxy disable. 97 scoped_ptr<CloudPrintWipeout> wipeout_; 98 99 DISALLOW_COPY_AND_ASSIGN(CloudPrintProxy); 100 }; 101 102 } // namespace cloud_print 103 104 #endif // CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_PROXY_H_ 105