| 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 20 matching lines...) Expand all Loading... |
| 146 | 143 |
| 147 // TODO(sanjeevr): Allow overriding OAuthClientInfo in prefs. | 144 // TODO(sanjeevr): Allow overriding OAuthClientInfo in prefs. |
| 148 gaia::OAuthClientInfo oauth_client_info; | 145 gaia::OAuthClientInfo oauth_client_info; |
| 149 oauth_client_info.client_id = | 146 oauth_client_info.client_id = |
| 150 google_apis::GetOAuth2ClientID(google_apis::CLIENT_CLOUD_PRINT); | 147 google_apis::GetOAuth2ClientID(google_apis::CLIENT_CLOUD_PRINT); |
| 151 oauth_client_info.client_secret = | 148 oauth_client_info.client_secret = |
| 152 google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_CLOUD_PRINT); | 149 google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_CLOUD_PRINT); |
| 153 | 150 |
| 154 // By default we don't poll for jobs when we lose XMPP connection. But this | 151 // By default we don't poll for jobs when we lose XMPP connection. But this |
| 155 // behavior can be overridden by a preference. | 152 // behavior can be overridden by a preference. |
| 156 bool enable_job_poll = false; | 153 bool enable_job_poll = |
| 157 service_prefs_->GetBoolean(prefs::kCloudPrintEnableJobPoll, | 154 service_prefs_->GetBoolean(prefs::kCloudPrintEnableJobPoll, false); |
| 158 &enable_job_poll); | |
| 159 | 155 |
| 160 backend_.reset(new CloudPrintProxyBackend(this, settings_, oauth_client_info, | 156 backend_.reset(new CloudPrintProxyBackend(this, settings_, oauth_client_info, |
| 161 enable_job_poll)); | 157 enable_job_poll)); |
| 162 return true; | 158 return true; |
| 163 } | 159 } |
| 164 | 160 |
| 165 void CloudPrintProxy::UnregisterPrintersAndDisableForUser() { | 161 void CloudPrintProxy::UnregisterPrintersAndDisableForUser() { |
| 166 DCHECK(CalledOnValidThread()); | 162 DCHECK(CalledOnValidThread()); |
| 167 if (backend_.get()) { | 163 if (backend_.get()) { |
| 168 // Try getting auth and printers info from the backend. | 164 // Try getting auth and printers info from the backend. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 186 | 182 |
| 187 void CloudPrintProxy::GetProxyInfo(cloud_print::CloudPrintProxyInfo* info) { | 183 void CloudPrintProxy::GetProxyInfo(cloud_print::CloudPrintProxyInfo* info) { |
| 188 info->enabled = enabled_; | 184 info->enabled = enabled_; |
| 189 info->email.clear(); | 185 info->email.clear(); |
| 190 if (enabled_) | 186 if (enabled_) |
| 191 info->email = user_email(); | 187 info->email = user_email(); |
| 192 info->proxy_id = settings_.proxy_id(); | 188 info->proxy_id = settings_.proxy_id(); |
| 193 // If the Cloud Print service is not enabled, we may need to read the old | 189 // If the Cloud Print service is not enabled, we may need to read the old |
| 194 // value of proxy_id from prefs. | 190 // value of proxy_id from prefs. |
| 195 if (info->proxy_id.empty()) | 191 if (info->proxy_id.empty()) |
| 196 service_prefs_->GetString(prefs::kCloudPrintProxyId, &info->proxy_id); | 192 info->proxy_id = service_prefs_->GetString(prefs::kCloudPrintProxyId, ""); |
| 197 } | 193 } |
| 198 | 194 |
| 199 void CloudPrintProxy::CheckCloudPrintProxyPolicy() { | 195 void CloudPrintProxy::CheckCloudPrintProxyPolicy() { |
| 200 g_service_process->io_thread()->message_loop_proxy()->PostTask( | 196 g_service_process->io_thread()->message_loop_proxy()->PostTask( |
| 201 FROM_HERE, base::Bind(&CheckCloudPrintProxyPolicyInBrowser)); | 197 FROM_HERE, base::Bind(&CheckCloudPrintProxyPolicyInBrowser)); |
| 202 } | 198 } |
| 203 | 199 |
| 204 void CloudPrintProxy::OnAuthenticated( | 200 void CloudPrintProxy::OnAuthenticated( |
| 205 const std::string& robot_oauth_refresh_token, | 201 const std::string& robot_oauth_refresh_token, |
| 206 const std::string& robot_email, | 202 const std::string& robot_email, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 // Finish disabling cloud print for this user. | 256 // Finish disabling cloud print for this user. |
| 261 DisableForUser(); | 257 DisableForUser(); |
| 262 } | 258 } |
| 263 | 259 |
| 264 void CloudPrintProxy::ShutdownBackend() { | 260 void CloudPrintProxy::ShutdownBackend() { |
| 265 DCHECK(CalledOnValidThread()); | 261 DCHECK(CalledOnValidThread()); |
| 266 if (backend_.get()) | 262 if (backend_.get()) |
| 267 backend_->Shutdown(); | 263 backend_->Shutdown(); |
| 268 backend_.reset(); | 264 backend_.reset(); |
| 269 } | 265 } |
| OLD | NEW |