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..046ca2da346e9ee21e52740a1c1baf52f51e1af5 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,6 +88,7 @@ void CloudPrintProxyService::RefreshStatusFromService() { |
| void CloudPrintProxyService::EnableForUser(const std::string& lsid, |
| const std::string& email) { |
| + DCHECK(profile_->GetPrefs()->GetBoolean(prefs::kCloudPrintProxyEnabled)); |
|
Mattias Nissler (ping if slow)
2011/11/14 08:33:06
nit: Since EnableForUser() is in the public interf
Scott Byer
2011/11/15 01:42:23
Done, and in EnableForUserWithRobot as well.
|
| InvokeServiceTask( |
| base::Bind(&CloudPrintProxyService::EnableCloudPrintProxy, |
| weak_factory_.GetWeakPtr(), lsid, email)); |
| @@ -90,13 +98,13 @@ void CloudPrintProxyService::EnableForUserWithRobot( |
| const std::string& robot_auth_code, |
| const std::string& robot_email, |
| const std::string& user_email) { |
| + DCHECK(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 +161,38 @@ void CloudPrintProxyService::TokenExpiredNotificationDone(bool keep_alive) { |
| } |
| } |
| +void CloudPrintProxyService::ApplyCloudPrintConnectorPolicy() { |
| + if (!profile_->GetPrefs()->GetBoolean(prefs::kCloudPrintProxyEnabled)) { |
| + std::string email; |
| + if (profile_->GetPrefs()->HasPrefPath(prefs::kCloudPrintEmail)) { |
|
Mattias Nissler (ping if slow)
2011/11/14 08:33:06
You might as well avoid the HasPrefPath call and j
Scott Byer
2011/11/15 01:42:23
Makes sense. Done.
|
| + 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) { |
| + 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(); |
| +} |