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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 client_ = client; | 78 client_ = client; |
79 } | 79 } |
80 | 80 |
81 void CloudPrintProxy::EnableForUser(const std::string& lsid) { | 81 void CloudPrintProxy::EnableForUser(const std::string& lsid) { |
82 DCHECK(CalledOnValidThread()); | 82 DCHECK(CalledOnValidThread()); |
83 if (!CreateBackend()) | 83 if (!CreateBackend()) |
84 return; | 84 return; |
85 DCHECK(backend_.get()); | 85 DCHECK(backend_.get()); |
86 // Read persisted robot credentials because we may decide to reuse it if the | 86 // Read persisted robot credentials because we may decide to reuse it if the |
87 // passed in LSID belongs the same user. | 87 // passed in LSID belongs the same user. |
88 std::string robot_refresh_token = | 88 std::string robot_refresh_token = service_prefs_->GetString( |
89 service_prefs_->GetString(prefs::kCloudPrintRobotRefreshToken, ""); | 89 prefs::kCloudPrintRobotRefreshToken, std::string()); |
90 std::string robot_email = | 90 std::string robot_email = |
91 service_prefs_->GetString(prefs::kCloudPrintRobotEmail, ""); | 91 service_prefs_->GetString(prefs::kCloudPrintRobotEmail, std::string()); |
92 user_email_ = service_prefs_->GetString(prefs::kCloudPrintEmail, user_email_); | 92 user_email_ = service_prefs_->GetString(prefs::kCloudPrintEmail, user_email_); |
93 | 93 |
94 // If we have been passed in an LSID, we want to use this to authenticate. | 94 // If we have been passed in an LSID, we want to use this to authenticate. |
95 // Else we will try and retrieve the last used auth tokens from prefs. | 95 // Else we will try and retrieve the last used auth tokens from prefs. |
96 if (!lsid.empty()) { | 96 if (!lsid.empty()) { |
97 backend_->InitializeWithLsid(lsid, robot_refresh_token, robot_email, | 97 backend_->InitializeWithLsid(lsid, robot_refresh_token, robot_email, |
98 user_email_); | 98 user_email_); |
99 } else { | 99 } else { |
100 // See if we have persisted robot credentials. | 100 // See if we have persisted robot credentials. |
101 if (!robot_refresh_token.empty()) { | 101 if (!robot_refresh_token.empty()) { |
102 DCHECK(!robot_email.empty()); | 102 DCHECK(!robot_email.empty()); |
103 backend_->InitializeWithRobotToken(robot_refresh_token, robot_email); | 103 backend_->InitializeWithRobotToken(robot_refresh_token, robot_email); |
104 } else { | 104 } else { |
105 // Finally see if we have persisted user credentials (legacy case). | 105 // Finally see if we have persisted user credentials (legacy case). |
106 std::string cloud_print_token = | 106 std::string cloud_print_token = |
107 service_prefs_->GetString(prefs::kCloudPrintAuthToken, ""); | 107 service_prefs_->GetString(prefs::kCloudPrintAuthToken, std::string()); |
108 DCHECK(!cloud_print_token.empty()); | 108 DCHECK(!cloud_print_token.empty()); |
109 backend_->InitializeWithToken(cloud_print_token); | 109 backend_->InitializeWithToken(cloud_print_token); |
110 } | 110 } |
111 } | 111 } |
112 if (client_) { | 112 if (client_) { |
113 client_->OnCloudPrintProxyEnabled(true); | 113 client_->OnCloudPrintProxyEnabled(true); |
114 } | 114 } |
115 } | 115 } |
116 | 116 |
117 void CloudPrintProxy::EnableForUserWithRobot( | 117 void CloudPrintProxy::EnableForUserWithRobot( |
118 const std::string& robot_auth_code, | 118 const std::string& robot_auth_code, |
119 const std::string& robot_email, | 119 const std::string& robot_email, |
120 const std::string& user_email, | 120 const std::string& user_email, |
121 bool connect_new_printers, | 121 bool connect_new_printers, |
122 const std::vector<std::string>& printer_blacklist) { | 122 const std::vector<std::string>& printer_blacklist) { |
123 DCHECK(CalledOnValidThread()); | 123 DCHECK(CalledOnValidThread()); |
124 | 124 |
125 ShutdownBackend(); | 125 ShutdownBackend(); |
126 std::string proxy_id( | 126 std::string proxy_id( |
127 service_prefs_->GetString(prefs::kCloudPrintProxyId, "")); | 127 service_prefs_->GetString(prefs::kCloudPrintProxyId, std::string())); |
128 service_prefs_->RemovePref(prefs::kCloudPrintRoot); | 128 service_prefs_->RemovePref(prefs::kCloudPrintRoot); |
129 if (!proxy_id.empty()) { | 129 if (!proxy_id.empty()) { |
130 // Keep only proxy id; | 130 // Keep only proxy id; |
131 service_prefs_->SetString(prefs::kCloudPrintProxyId, proxy_id); | 131 service_prefs_->SetString(prefs::kCloudPrintProxyId, proxy_id); |
132 } | 132 } |
133 service_prefs_->SetBoolean(prefs::kCloudPrintConnectNewPrinters, | 133 service_prefs_->SetBoolean(prefs::kCloudPrintConnectNewPrinters, |
134 connect_new_printers); | 134 connect_new_printers); |
135 if (!printer_blacklist.empty()) { | 135 if (!printer_blacklist.empty()) { |
136 scoped_ptr<base::ListValue> printers(new base::ListValue()); | 136 scoped_ptr<base::ListValue> printers(new base::ListValue()); |
137 printers->AppendStrings(printer_blacklist); | 137 printers->AppendStrings(printer_blacklist); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 | 197 |
198 void CloudPrintProxy::GetProxyInfo(CloudPrintProxyInfo* info) { | 198 void CloudPrintProxy::GetProxyInfo(CloudPrintProxyInfo* info) { |
199 info->enabled = enabled_; | 199 info->enabled = enabled_; |
200 info->email.clear(); | 200 info->email.clear(); |
201 if (enabled_) | 201 if (enabled_) |
202 info->email = user_email(); | 202 info->email = user_email(); |
203 info->proxy_id = settings_.proxy_id(); | 203 info->proxy_id = settings_.proxy_id(); |
204 // If the Cloud Print service is not enabled, we may need to read the old | 204 // If the Cloud Print service is not enabled, we may need to read the old |
205 // value of proxy_id from prefs. | 205 // value of proxy_id from prefs. |
206 if (info->proxy_id.empty()) | 206 if (info->proxy_id.empty()) |
207 info->proxy_id = service_prefs_->GetString(prefs::kCloudPrintProxyId, ""); | 207 info->proxy_id = |
| 208 service_prefs_->GetString(prefs::kCloudPrintProxyId, std::string()); |
208 } | 209 } |
209 | 210 |
210 void CloudPrintProxy::CheckCloudPrintProxyPolicy() { | 211 void CloudPrintProxy::CheckCloudPrintProxyPolicy() { |
211 g_service_process->io_thread()->message_loop_proxy()->PostTask( | 212 g_service_process->io_thread()->message_loop_proxy()->PostTask( |
212 FROM_HERE, base::Bind(&CheckCloudPrintProxyPolicyInBrowser)); | 213 FROM_HERE, base::Bind(&CheckCloudPrintProxyPolicyInBrowser)); |
213 } | 214 } |
214 | 215 |
215 void CloudPrintProxy::OnAuthenticated( | 216 void CloudPrintProxy::OnAuthenticated( |
216 const std::string& robot_oauth_refresh_token, | 217 const std::string& robot_oauth_refresh_token, |
217 const std::string& robot_email, | 218 const std::string& robot_email, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 } | 274 } |
274 | 275 |
275 void CloudPrintProxy::ShutdownBackend() { | 276 void CloudPrintProxy::ShutdownBackend() { |
276 DCHECK(CalledOnValidThread()); | 277 DCHECK(CalledOnValidThread()); |
277 if (backend_.get()) | 278 if (backend_.get()) |
278 backend_->Shutdown(); | 279 backend_->Shutdown(); |
279 backend_.reset(); | 280 backend_.reset(); |
280 } | 281 } |
281 | 282 |
282 } // namespace cloud_print | 283 } // namespace cloud_print |
OLD | NEW |