| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" | 5 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" |
| 6 | 6 |
| 7 #include <stack> | 7 #include <stack> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 g_browser_process->notification_ui_manager()->CancelById( | 158 g_browser_process->notification_ui_manager()->CancelById( |
| 159 token_expired_delegate_->id()); | 159 token_expired_delegate_->id()); |
| 160 token_expired_delegate_ = NULL; | 160 token_expired_delegate_ = NULL; |
| 161 if (!keep_alive) | 161 if (!keep_alive) |
| 162 BrowserList::EndKeepAlive(); | 162 BrowserList::EndKeepAlive(); |
| 163 } | 163 } |
| 164 } | 164 } |
| 165 | 165 |
| 166 void CloudPrintProxyService::ApplyCloudPrintConnectorPolicy() { | 166 void CloudPrintProxyService::ApplyCloudPrintConnectorPolicy() { |
| 167 if (!profile_->GetPrefs()->GetBoolean(prefs::kCloudPrintProxyEnabled)) { | 167 if (!profile_->GetPrefs()->GetBoolean(prefs::kCloudPrintProxyEnabled)) { |
| 168 std::string email; | 168 std::string email = |
| 169 email = profile_->GetPrefs()->GetString(prefs::kCloudPrintEmail); | 169 profile_->GetPrefs()->GetString(prefs::kCloudPrintEmail); |
| 170 if (!email.empty()) { | 170 if (!email.empty()) { |
| 171 DisableForUser(); | 171 DisableForUser(); |
| 172 profile_->GetPrefs()->SetString(prefs::kCloudPrintEmail, std::string()); | 172 profile_->GetPrefs()->SetString(prefs::kCloudPrintEmail, std::string()); |
| 173 } | 173 } |
| 174 } | 174 } |
| 175 } | 175 } |
| 176 | 176 |
| 177 void CloudPrintProxyService::OnCloudPrintSetupClosed() { | 177 void CloudPrintProxyService::OnCloudPrintSetupClosed() { |
| 178 MessageLoop::current()->PostTask( | 178 MessageLoop::current()->PostTask( |
| 179 FROM_HERE, base::Bind(&BrowserList::EndKeepAlive)); | 179 FROM_HERE, base::Bind(&BrowserList::EndKeepAlive)); |
| 180 } | 180 } |
| 181 | 181 |
| 182 void CloudPrintProxyService::Observe( | 182 void CloudPrintProxyService::Observe( |
| 183 int type, | 183 int type, |
| 184 const content::NotificationSource& source, | 184 const content::NotificationSource& source, |
| 185 const content::NotificationDetails& details) { | 185 const content::NotificationDetails& details) { |
| 186 if (type == chrome::NOTIFICATION_PREF_CHANGED) { | 186 DCHECK_EQ(chrome::NOTIFICATION_PREF_CHANGED, type); |
| 187 ApplyCloudPrintConnectorPolicy(); | 187 ApplyCloudPrintConnectorPolicy(); |
| 188 } else { | |
| 189 NOTREACHED(); | |
| 190 } | |
| 191 } | 188 } |
| 192 | 189 |
| 193 void CloudPrintProxyService::RefreshCloudPrintProxyStatus() { | 190 void CloudPrintProxyService::RefreshCloudPrintProxyStatus() { |
| 194 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 191 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 195 ServiceProcessControl* process_control = GetServiceProcessControl(); | 192 ServiceProcessControl* process_control = GetServiceProcessControl(); |
| 196 DCHECK(process_control->is_connected()); | 193 DCHECK(process_control->IsConnected()); |
| 197 ServiceProcessControl::CloudPrintProxyInfoHandler callback = | 194 ServiceProcessControl::CloudPrintProxyInfoHandler callback = |
| 198 base::Bind(&CloudPrintProxyService::ProxyInfoCallback, | 195 base::Bind(&CloudPrintProxyService::ProxyInfoCallback, |
| 199 base::Unretained(this)); | 196 base::Unretained(this)); |
| 200 // GetCloudPrintProxyInfo takes ownership of callback. | 197 // GetCloudPrintProxyInfo takes ownership of callback. |
| 201 process_control->GetCloudPrintProxyInfo(callback); | 198 process_control->GetCloudPrintProxyInfo(callback); |
| 202 } | 199 } |
| 203 | 200 |
| 204 void CloudPrintProxyService::EnableCloudPrintProxy(const std::string& lsid, | 201 void CloudPrintProxyService::EnableCloudPrintProxy(const std::string& lsid, |
| 205 const std::string& email) { | 202 const std::string& email) { |
| 206 ServiceProcessControl* process_control = GetServiceProcessControl(); | 203 ServiceProcessControl* process_control = GetServiceProcessControl(); |
| 207 DCHECK(process_control->is_connected()); | 204 DCHECK(process_control->IsConnected()); |
| 208 process_control->Send(new ServiceMsg_EnableCloudPrintProxy(lsid)); | 205 process_control->Send(new ServiceMsg_EnableCloudPrintProxy(lsid)); |
| 209 // Assume the IPC worked. | 206 // Assume the IPC worked. |
| 210 profile_->GetPrefs()->SetString(prefs::kCloudPrintEmail, email); | 207 profile_->GetPrefs()->SetString(prefs::kCloudPrintEmail, email); |
| 211 } | 208 } |
| 212 | 209 |
| 213 void CloudPrintProxyService::EnableCloudPrintProxyWithRobot( | 210 void CloudPrintProxyService::EnableCloudPrintProxyWithRobot( |
| 214 const std::string& robot_auth_code, | 211 const std::string& robot_auth_code, |
| 215 const std::string& robot_email, | 212 const std::string& robot_email, |
| 216 const std::string& user_email) { | 213 const std::string& user_email) { |
| 217 ServiceProcessControl* process_control = GetServiceProcessControl(); | 214 ServiceProcessControl* process_control = GetServiceProcessControl(); |
| 218 DCHECK(process_control->is_connected()); | 215 DCHECK(process_control->IsConnected()); |
| 219 process_control->Send(new ServiceMsg_EnableCloudPrintProxyWithRobot( | 216 process_control->Send(new ServiceMsg_EnableCloudPrintProxyWithRobot( |
| 220 robot_auth_code, | 217 robot_auth_code, |
| 221 robot_email, | 218 robot_email, |
| 222 user_email)); | 219 user_email)); |
| 223 // Assume the IPC worked. | 220 // Assume the IPC worked. |
| 224 profile_->GetPrefs()->SetString(prefs::kCloudPrintEmail, user_email); | 221 profile_->GetPrefs()->SetString(prefs::kCloudPrintEmail, user_email); |
| 225 } | 222 } |
| 226 | 223 |
| 227 void CloudPrintProxyService::DisableCloudPrintProxy() { | 224 void CloudPrintProxyService::DisableCloudPrintProxy() { |
| 228 ServiceProcessControl* process_control = GetServiceProcessControl(); | 225 ServiceProcessControl* process_control = GetServiceProcessControl(); |
| 229 DCHECK(process_control->is_connected()); | 226 DCHECK(process_control->IsConnected()); |
| 230 process_control->Send(new ServiceMsg_DisableCloudPrintProxy); | 227 process_control->Send(new ServiceMsg_DisableCloudPrintProxy); |
| 231 // Assume the IPC worked. | 228 // Assume the IPC worked. |
| 232 profile_->GetPrefs()->SetString(prefs::kCloudPrintEmail, std::string()); | 229 profile_->GetPrefs()->SetString(prefs::kCloudPrintEmail, std::string()); |
| 233 } | 230 } |
| 234 | 231 |
| 235 void CloudPrintProxyService::ProxyInfoCallback( | 232 void CloudPrintProxyService::ProxyInfoCallback( |
| 236 const cloud_print::CloudPrintProxyInfo& proxy_info) { | 233 const cloud_print::CloudPrintProxyInfo& proxy_info) { |
| 237 proxy_id_ = proxy_info.proxy_id; | 234 proxy_id_ = proxy_info.proxy_id; |
| 238 profile_->GetPrefs()->SetString( | 235 profile_->GetPrefs()->SetString( |
| 239 prefs::kCloudPrintEmail, | 236 prefs::kCloudPrintEmail, |
| 240 proxy_info.enabled ? proxy_info.email : std::string()); | 237 proxy_info.enabled ? proxy_info.email : std::string()); |
| 241 ApplyCloudPrintConnectorPolicy(); | 238 ApplyCloudPrintConnectorPolicy(); |
| 242 } | 239 } |
| 243 | 240 |
| 244 bool CloudPrintProxyService::InvokeServiceTask(const base::Closure& task) { | 241 bool CloudPrintProxyService::InvokeServiceTask(const base::Closure& task) { |
| 245 GetServiceProcessControl()->Launch(task, base::Closure()); | 242 GetServiceProcessControl()->Launch(task, base::Closure()); |
| 246 return true; | 243 return true; |
| 247 } | 244 } |
| 248 | 245 |
| 249 ServiceProcessControl* CloudPrintProxyService::GetServiceProcessControl() { | 246 ServiceProcessControl* CloudPrintProxyService::GetServiceProcessControl() { |
| 250 return ServiceProcessControl::GetInstance(); | 247 return ServiceProcessControl::GetInstance(); |
| 251 } | 248 } |
| OLD | NEW |