| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/service/cloud_print/cloud_print_proxy.h" | 5 #include "chrome/service/cloud_print/cloud_print_proxy.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/process_util.h" | 10 #include "base/process_util.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 client_ = client; | 83 client_ = client; |
| 84 } | 84 } |
| 85 | 85 |
| 86 void CloudPrintProxy::EnableForUser(const std::string& lsid) { | 86 void CloudPrintProxy::EnableForUser(const std::string& lsid) { |
| 87 DCHECK(CalledOnValidThread()); | 87 DCHECK(CalledOnValidThread()); |
| 88 if (!CreateBackend()) | 88 if (!CreateBackend()) |
| 89 return; | 89 return; |
| 90 DCHECK(backend_.get()); | 90 DCHECK(backend_.get()); |
| 91 // Read persisted robot credentials because we may decide to reuse it if the | 91 // Read persisted robot credentials because we may decide to reuse it if the |
| 92 // passed in LSID belongs the same user. | 92 // passed in LSID belongs the same user. |
| 93 std::string robot_refresh_token; | 93 std::string robot_refresh_token = |
| 94 service_prefs_->GetString(prefs::kCloudPrintRobotRefreshToken, | 94 service_prefs_->GetString(prefs::kCloudPrintRobotRefreshToken, ""); |
| 95 &robot_refresh_token); | 95 std::string robot_email = |
| 96 std::string robot_email; | 96 service_prefs_->GetString(prefs::kCloudPrintRobotEmail, ""); |
| 97 service_prefs_->GetString(prefs::kCloudPrintRobotEmail, | 97 user_email_ = service_prefs_->GetString(prefs::kCloudPrintEmail, user_email_); |
| 98 &robot_email); | |
| 99 service_prefs_->GetString(prefs::kCloudPrintEmail, &user_email_); | |
| 100 | 98 |
| 101 // If we have been passed in an LSID, we want to use this to authenticate. | 99 // If we have been passed in an LSID, we want to use this to authenticate. |
| 102 // Else we will try and retrieve the last used auth tokens from prefs. | 100 // Else we will try and retrieve the last used auth tokens from prefs. |
| 103 if (!lsid.empty()) { | 101 if (!lsid.empty()) { |
| 104 backend_->InitializeWithLsid(lsid, robot_refresh_token, robot_email, | 102 backend_->InitializeWithLsid(lsid, robot_refresh_token, robot_email, |
| 105 user_email_); | 103 user_email_); |
| 106 } else { | 104 } else { |
| 107 // See if we have persisted robot credentials. | 105 // See if we have persisted robot credentials. |
| 108 if (!robot_refresh_token.empty()) { | 106 if (!robot_refresh_token.empty()) { |
| 109 DCHECK(!robot_email.empty()); | 107 DCHECK(!robot_email.empty()); |
| 110 backend_->InitializeWithRobotToken(robot_refresh_token, robot_email); | 108 backend_->InitializeWithRobotToken(robot_refresh_token, robot_email); |
| 111 } else { | 109 } else { |
| 112 // Finally see if we have persisted user credentials (legacy case). | 110 // Finally see if we have persisted user credentials (legacy case). |
| 113 std::string cloud_print_token; | 111 std::string cloud_print_token = |
| 114 service_prefs_->GetString(prefs::kCloudPrintAuthToken, | 112 service_prefs_->GetString(prefs::kCloudPrintAuthToken, ""); |
| 115 &cloud_print_token); | |
| 116 DCHECK(!cloud_print_token.empty()); | 113 DCHECK(!cloud_print_token.empty()); |
| 117 backend_->InitializeWithToken(cloud_print_token); | 114 backend_->InitializeWithToken(cloud_print_token); |
| 118 } | 115 } |
| 119 } | 116 } |
| 120 if (client_) { | 117 if (client_) { |
| 121 client_->OnCloudPrintProxyEnabled(true); | 118 client_->OnCloudPrintProxyEnabled(true); |
| 122 } | 119 } |
| 123 } | 120 } |
| 124 | 121 |
| 125 void CloudPrintProxy::EnableForUserWithRobot( | 122 void CloudPrintProxy::EnableForUserWithRobot( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 139 | 136 |
| 140 bool CloudPrintProxy::CreateBackend() { | 137 bool CloudPrintProxy::CreateBackend() { |
| 141 DCHECK(CalledOnValidThread()); | 138 DCHECK(CalledOnValidThread()); |
| 142 if (backend_.get()) | 139 if (backend_.get()) |
| 143 return false; | 140 return false; |
| 144 | 141 |
| 145 settings_.InitFrom(service_prefs_); | 142 settings_.InitFrom(service_prefs_); |
| 146 | 143 |
| 147 // By default we don't poll for jobs when we lose XMPP connection. But this | 144 // By default we don't poll for jobs when we lose XMPP connection. But this |
| 148 // behavior can be overridden by a preference. | 145 // behavior can be overridden by a preference. |
| 149 bool enable_job_poll = false; | 146 bool enable_job_poll = |
| 150 service_prefs_->GetBoolean(prefs::kCloudPrintEnableJobPoll, &enable_job_poll); | 147 service_prefs_->GetBoolean(prefs::kCloudPrintEnableJobPoll, false); |
| 151 | 148 |
| 152 gaia::OAuthClientInfo oauth_client_info; | 149 gaia::OAuthClientInfo oauth_client_info; |
| 153 oauth_client_info.client_id = | 150 oauth_client_info.client_id = |
| 154 google_apis::GetOAuth2ClientID(google_apis::CLIENT_CLOUD_PRINT); | 151 google_apis::GetOAuth2ClientID(google_apis::CLIENT_CLOUD_PRINT); |
| 155 oauth_client_info.client_secret = | 152 oauth_client_info.client_secret = |
| 156 google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_CLOUD_PRINT); | 153 google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_CLOUD_PRINT); |
| 157 backend_.reset(new CloudPrintProxyBackend(this, settings_, oauth_client_info, | 154 backend_.reset(new CloudPrintProxyBackend(this, settings_, oauth_client_info, |
| 158 enable_job_poll)); | 155 enable_job_poll)); |
| 159 | |
| 160 return true; | 156 return true; |
| 161 } | 157 } |
| 162 | 158 |
| 163 void CloudPrintProxy::UnregisterPrintersAndDisableForUser() { | 159 void CloudPrintProxy::UnregisterPrintersAndDisableForUser() { |
| 164 DCHECK(CalledOnValidThread()); | 160 DCHECK(CalledOnValidThread()); |
| 165 if (backend_.get()) { | 161 if (backend_.get()) { |
| 166 // Try getting auth and printers info from the backend. | 162 // Try getting auth and printers info from the backend. |
| 167 // We'll get notified in this case. | 163 // We'll get notified in this case. |
| 168 backend_->UnregisterPrinters(); | 164 backend_->UnregisterPrinters(); |
| 169 } else { | 165 } else { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 184 | 180 |
| 185 void CloudPrintProxy::GetProxyInfo(cloud_print::CloudPrintProxyInfo* info) { | 181 void CloudPrintProxy::GetProxyInfo(cloud_print::CloudPrintProxyInfo* info) { |
| 186 info->enabled = enabled_; | 182 info->enabled = enabled_; |
| 187 info->email.clear(); | 183 info->email.clear(); |
| 188 if (enabled_) | 184 if (enabled_) |
| 189 info->email = user_email(); | 185 info->email = user_email(); |
| 190 info->proxy_id = settings_.proxy_id(); | 186 info->proxy_id = settings_.proxy_id(); |
| 191 // If the Cloud Print service is not enabled, we may need to read the old | 187 // If the Cloud Print service is not enabled, we may need to read the old |
| 192 // value of proxy_id from prefs. | 188 // value of proxy_id from prefs. |
| 193 if (info->proxy_id.empty()) | 189 if (info->proxy_id.empty()) |
| 194 service_prefs_->GetString(prefs::kCloudPrintProxyId, &info->proxy_id); | 190 info->proxy_id = service_prefs_->GetString(prefs::kCloudPrintProxyId, ""); |
| 195 } | 191 } |
| 196 | 192 |
| 197 void CloudPrintProxy::CheckCloudPrintProxyPolicy() { | 193 void CloudPrintProxy::CheckCloudPrintProxyPolicy() { |
| 198 g_service_process->io_thread()->message_loop_proxy()->PostTask( | 194 g_service_process->io_thread()->message_loop_proxy()->PostTask( |
| 199 FROM_HERE, base::Bind(&CheckCloudPrintProxyPolicyInBrowser)); | 195 FROM_HERE, base::Bind(&CheckCloudPrintProxyPolicyInBrowser)); |
| 200 } | 196 } |
| 201 | 197 |
| 202 void CloudPrintProxy::OnAuthenticated( | 198 void CloudPrintProxy::OnAuthenticated( |
| 203 const std::string& robot_oauth_refresh_token, | 199 const std::string& robot_oauth_refresh_token, |
| 204 const std::string& robot_email, | 200 const std::string& robot_email, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 // Finish disabling cloud print for this user. | 254 // Finish disabling cloud print for this user. |
| 259 DisableForUser(); | 255 DisableForUser(); |
| 260 } | 256 } |
| 261 | 257 |
| 262 void CloudPrintProxy::ShutdownBackend() { | 258 void CloudPrintProxy::ShutdownBackend() { |
| 263 DCHECK(CalledOnValidThread()); | 259 DCHECK(CalledOnValidThread()); |
| 264 if (backend_.get()) | 260 if (backend_.get()) |
| 265 backend_->Shutdown(); | 261 backend_->Shutdown(); |
| 266 backend_.reset(); | 262 backend_.reset(); |
| 267 } | 263 } |
| OLD | NEW |