cloud_print_proxy_service.h revision 5821806d5e7f356e8fa4b058a389a808ea183019
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_BROWSER_PRINTING_CLOUD_PRINT_CLOUD_PRINT_PROXY_SERVICE_H_ 6#define CHROME_BROWSER_PRINTING_CLOUD_PRINT_CLOUD_PRINT_PROXY_SERVICE_H_ 7 8#include <string> 9#include <vector> 10 11#include "base/basictypes.h" 12#include "base/callback_forward.h" 13#include "base/memory/weak_ptr.h" 14#include "base/observer_list.h" 15#include "base/prefs/public/pref_change_registrar.h" 16#include "base/prefs/public/pref_observer.h" 17#include "chrome/browser/printing/cloud_print/cloud_print_setup_handler.h" 18#include "chrome/browser/profiles/profile_keyed_service.h" 19 20class Profile; 21class ServiceProcessControl; 22 23namespace cloud_print { 24struct CloudPrintProxyInfo; 25} // namespace cloud_print 26 27// Layer between the browser user interface and the cloud print proxy code 28// running in the service process. 29class CloudPrintProxyService 30 : public CloudPrintSetupHandlerDelegate, 31 public ProfileKeyedService, 32 public PrefObserver { 33 public: 34 explicit CloudPrintProxyService(Profile* profile); 35 virtual ~CloudPrintProxyService(); 36 37 // Initializes the object. This should be called every time an object of this 38 // class is constructed. 39 void Initialize(); 40 41 // Enables/disables cloud printing for the user 42 virtual void EnableForUser(const std::string& lsid, const std::string& email); 43 virtual void EnableForUserWithRobot( 44 const std::string& robot_auth_code, 45 const std::string& robot_email, 46 const std::string& user_email, 47 bool connect_new_printers, 48 const std::vector<std::string>& printer_blacklist); 49 virtual void DisableForUser(); 50 51 // Query the service process for the status of the cloud print proxy and 52 // update the browser prefs. 53 void RefreshStatusFromService(); 54 55 // Disable the service if the policy to do so is set, and once the 56 // disablement is verified, quit the browser. Returns true if the policy is 57 // not set or the connector was not enabled. 58 bool EnforceCloudPrintConnectorPolicyAndQuit(); 59 60 bool ShowTokenExpiredNotification(); 61 std::string proxy_id() const { return proxy_id_; } 62 63 // CloudPrintSetupHandler::Delegate implementation. 64 virtual void OnCloudPrintSetupClosed() OVERRIDE; 65 66 // PrefObserver implementation. 67 virtual void OnPreferenceChanged(PrefServiceBase* service, 68 const std::string& pref_name) OVERRIDE; 69 70 private: 71 // NotificationDelegate implementation for the token expired notification. 72 class TokenExpiredNotificationDelegate; 73 friend class TokenExpiredNotificationDelegate; 74 75 Profile* profile_; 76 scoped_refptr<TokenExpiredNotificationDelegate> token_expired_delegate_; 77 scoped_ptr<CloudPrintSetupHandler> cloud_print_setup_handler_; 78 std::string proxy_id_; 79 80 // Methods that send an IPC to the service. 81 void RefreshCloudPrintProxyStatus(); 82 void EnableCloudPrintProxy(const std::string& lsid, const std::string& email); 83 void EnableCloudPrintProxyWithRobot( 84 const std::string& robot_auth_code, 85 const std::string& robot_email, 86 const std::string& user_email, 87 bool connect_new_printers, 88 const std::vector<std::string>& printer_blacklist); 89 void DisableCloudPrintProxy(); 90 91 // Callback that gets the cloud print proxy info. 92 void ProxyInfoCallback( 93 const cloud_print::CloudPrintProxyInfo& proxy_info); 94 95 // Invoke a task that gets run after the service process successfully 96 // launches. The task typically involves sending an IPC to the service 97 // process. 98 bool InvokeServiceTask(const base::Closure& task); 99 100 void OnTokenExpiredNotificationError(); 101 void OnTokenExpiredNotificationClosed(bool by_user); 102 void OnTokenExpiredNotificationClick(); 103 void TokenExpiredNotificationDone(bool keep_alive); 104 105 // Checks the policy. Returns true if nothing needs to be done (the policy is 106 // not set or the connector is not enabled). 107 bool ApplyCloudPrintConnectorPolicy(); 108 109 // Virtual for testing. 110 virtual ServiceProcessControl* GetServiceProcessControl(); 111 112 base::WeakPtrFactory<CloudPrintProxyService> weak_factory_; 113 114 // For watching for connector enablement policy changes. 115 PrefChangeRegistrar pref_change_registrar_; 116 117 // If set, continue trying to disable the connector, and quit the process 118 // once successful. 119 bool enforcing_connector_policy_; 120 121 DISALLOW_COPY_AND_ASSIGN(CloudPrintProxyService); 122}; 123 124#endif // CHROME_BROWSER_PRINTING_CLOUD_PRINT_CLOUD_PRINT_PROXY_SERVICE_H_ 125