Chromium Code Reviews| Index: chrome/browser/printing/cloud_print/cloud_print_proxy_service.cc |
| diff --git a/chrome/browser/printing/cloud_print/cloud_print_proxy_service.cc b/chrome/browser/printing/cloud_print/cloud_print_proxy_service.cc |
| index cebec21af388a0f7648176353fb143201ebc306a..63766e9c80578c654cc08949e0153c2fb6bb0e38 100644 |
| --- a/chrome/browser/printing/cloud_print/cloud_print_proxy_service.cc |
| +++ b/chrome/browser/printing/cloud_print/cloud_print_proxy_service.cc |
| @@ -19,6 +19,7 @@ |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/service/service_process_control.h" |
| #include "chrome/browser/ui/browser_list.h" |
| +#include "chrome/common/chrome_notification_types.h" |
| #include "chrome/common/cloud_print/cloud_print_proxy_info.h" |
| #include "chrome/common/pref_names.h" |
| #include "chrome/common/service_messages.h" |
| @@ -66,11 +67,17 @@ CloudPrintProxyService::~CloudPrintProxyService() { |
| void CloudPrintProxyService::Initialize() { |
| if (profile_->GetPrefs()->HasPrefPath(prefs::kCloudPrintEmail) && |
| - !profile_->GetPrefs()->GetString(prefs::kCloudPrintEmail).empty()) { |
| - // If the cloud print proxy is enabled, establish a channel with the |
| - // service process and update the status. |
| + (!profile_->GetPrefs()->GetString(prefs::kCloudPrintEmail).empty() || |
| + !profile_->GetPrefs()->GetBoolean(prefs::kCloudPrintProxyEnabled))) { |
| + // If the cloud print proxy is enabled, or the policy preventing it from |
| + // being enabled is set, establish a channel with the service process and |
| + // update the status. This will check the policy when the status is sent |
| + // back. |
| RefreshStatusFromService(); |
| } |
| + |
| + pref_change_registrar_.Init(profile_->GetPrefs()); |
| + pref_change_registrar_.Add(prefs::kCloudPrintProxyEnabled, this); |
| } |
| void CloudPrintProxyService::RefreshStatusFromService() { |
| @@ -81,22 +88,25 @@ void CloudPrintProxyService::RefreshStatusFromService() { |
| void CloudPrintProxyService::EnableForUser(const std::string& lsid, |
| const std::string& email) { |
| - InvokeServiceTask( |
| - base::Bind(&CloudPrintProxyService::EnableCloudPrintProxy, |
| - weak_factory_.GetWeakPtr(), lsid, email)); |
| + if (profile_->GetPrefs()->GetBoolean(prefs::kCloudPrintProxyEnabled)) { |
| + InvokeServiceTask( |
| + base::Bind(&CloudPrintProxyService::EnableCloudPrintProxy, |
| + weak_factory_.GetWeakPtr(), lsid, email)); |
| + } |
| } |
| void CloudPrintProxyService::EnableForUserWithRobot( |
| const std::string& robot_auth_code, |
| const std::string& robot_email, |
| const std::string& user_email) { |
| - InvokeServiceTask( |
| - base::Bind(&CloudPrintProxyService::EnableCloudPrintProxyWithRobot, |
| - weak_factory_.GetWeakPtr(), robot_auth_code, robot_email, |
| - user_email)); |
| + if (profile_->GetPrefs()->GetBoolean(prefs::kCloudPrintProxyEnabled)) { |
| + InvokeServiceTask( |
| + base::Bind(&CloudPrintProxyService::EnableCloudPrintProxyWithRobot, |
| + weak_factory_.GetWeakPtr(), robot_auth_code, robot_email, |
| + user_email)); |
| + } |
| } |
| - |
| void CloudPrintProxyService::DisableForUser() { |
| InvokeServiceTask( |
| base::Bind(&CloudPrintProxyService::DisableCloudPrintProxy, |
| @@ -153,14 +163,36 @@ void CloudPrintProxyService::TokenExpiredNotificationDone(bool keep_alive) { |
| } |
| } |
| +void CloudPrintProxyService::ApplyCloudPrintConnectorPolicy() { |
| + if (!profile_->GetPrefs()->GetBoolean(prefs::kCloudPrintProxyEnabled)) { |
| + std::string email; |
|
Peter Kasting
2011/11/21 20:51:32
Nit: Combine this line with the next
|
| + email = profile_->GetPrefs()->GetString(prefs::kCloudPrintEmail); |
| + if (!email.empty()) { |
| + DisableForUser(); |
| + profile_->GetPrefs()->SetString(prefs::kCloudPrintEmail, std::string()); |
| + } |
| + } |
| +} |
| + |
| void CloudPrintProxyService::OnCloudPrintSetupClosed() { |
| MessageLoop::current()->PostTask( |
| FROM_HERE, base::Bind(&BrowserList::EndKeepAlive)); |
| } |
| +void CloudPrintProxyService::Observe( |
| + int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) { |
| + if (type == chrome::NOTIFICATION_PREF_CHANGED) { |
|
Peter Kasting
2011/11/21 20:51:32
Nit: Convert this conditional to a simple:
DCHE
|
| + ApplyCloudPrintConnectorPolicy(); |
| + } else { |
| + NOTREACHED(); |
| + } |
| +} |
| + |
| void CloudPrintProxyService::RefreshCloudPrintProxyStatus() { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| - ServiceProcessControl* process_control = ServiceProcessControl::GetInstance(); |
| + ServiceProcessControl* process_control = GetServiceProcessControl(); |
| DCHECK(process_control->is_connected()); |
| ServiceProcessControl::CloudPrintProxyInfoHandler callback = |
| base::Bind(&CloudPrintProxyService::ProxyInfoCallback, |
| @@ -171,7 +203,7 @@ void CloudPrintProxyService::RefreshCloudPrintProxyStatus() { |
| void CloudPrintProxyService::EnableCloudPrintProxy(const std::string& lsid, |
| const std::string& email) { |
| - ServiceProcessControl* process_control = ServiceProcessControl::GetInstance(); |
| + ServiceProcessControl* process_control = GetServiceProcessControl(); |
| DCHECK(process_control->is_connected()); |
| process_control->Send(new ServiceMsg_EnableCloudPrintProxy(lsid)); |
| // Assume the IPC worked. |
| @@ -182,7 +214,7 @@ void CloudPrintProxyService::EnableCloudPrintProxyWithRobot( |
| const std::string& robot_auth_code, |
| const std::string& robot_email, |
| const std::string& user_email) { |
| - ServiceProcessControl* process_control = ServiceProcessControl::GetInstance(); |
| + ServiceProcessControl* process_control = GetServiceProcessControl(); |
| DCHECK(process_control->is_connected()); |
| process_control->Send(new ServiceMsg_EnableCloudPrintProxyWithRobot( |
| robot_auth_code, |
| @@ -192,9 +224,8 @@ void CloudPrintProxyService::EnableCloudPrintProxyWithRobot( |
| profile_->GetPrefs()->SetString(prefs::kCloudPrintEmail, user_email); |
| } |
| - |
| void CloudPrintProxyService::DisableCloudPrintProxy() { |
| - ServiceProcessControl* process_control = ServiceProcessControl::GetInstance(); |
| + ServiceProcessControl* process_control = GetServiceProcessControl(); |
| DCHECK(process_control->is_connected()); |
| process_control->Send(new ServiceMsg_DisableCloudPrintProxy); |
| // Assume the IPC worked. |
| @@ -207,9 +238,14 @@ void CloudPrintProxyService::ProxyInfoCallback( |
| profile_->GetPrefs()->SetString( |
| prefs::kCloudPrintEmail, |
| proxy_info.enabled ? proxy_info.email : std::string()); |
| + ApplyCloudPrintConnectorPolicy(); |
| } |
| bool CloudPrintProxyService::InvokeServiceTask(const base::Closure& task) { |
| - ServiceProcessControl::GetInstance()->Launch(task, base::Closure()); |
| + GetServiceProcessControl()->Launch(task, base::Closure()); |
| return true; |
| } |
| + |
| +ServiceProcessControl* CloudPrintProxyService::GetServiceProcessControl() { |
| + return ServiceProcessControl::GetInstance(); |
| +} |