OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/process_util.h" | 9 #include "base/process_util.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 service_prefs_->GetString(prefs::kCloudPrintXMPPAuthToken, | 99 service_prefs_->GetString(prefs::kCloudPrintXMPPAuthToken, |
100 &cloud_print_xmpp_token); | 100 &cloud_print_xmpp_token); |
101 DCHECK(!cloud_print_xmpp_token.empty()); | 101 DCHECK(!cloud_print_xmpp_token.empty()); |
102 service_prefs_->GetString(prefs::kCloudPrintEmail, | 102 service_prefs_->GetString(prefs::kCloudPrintEmail, |
103 &cloud_print_email_); | 103 &cloud_print_email_); |
104 DCHECK(!cloud_print_email_.empty()); | 104 DCHECK(!cloud_print_email_.empty()); |
105 backend_->InitializeWithToken(cloud_print_token, cloud_print_xmpp_token, | 105 backend_->InitializeWithToken(cloud_print_token, cloud_print_xmpp_token, |
106 cloud_print_email_, proxy_id); | 106 cloud_print_email_, proxy_id); |
107 } | 107 } |
108 if (client_) { | 108 if (client_) { |
109 client_->OnCloudPrintProxyEnabled(); | 109 client_->OnCloudPrintProxyEnabled(true); |
110 } | 110 } |
111 } | 111 } |
112 | 112 |
113 void CloudPrintProxy::DisableForUser() { | 113 void CloudPrintProxy::DisableForUser() { |
114 DCHECK(CalledOnValidThread()); | 114 DCHECK(CalledOnValidThread()); |
115 cloud_print_email_.clear(); | 115 cloud_print_email_.clear(); |
116 Shutdown(); | 116 Shutdown(); |
117 if (client_) { | 117 if (client_) { |
118 client_->OnCloudPrintProxyDisabled(); | 118 client_->OnCloudPrintProxyDisabled(true); |
119 } | 119 } |
120 } | 120 } |
121 | 121 |
122 bool CloudPrintProxy::IsEnabled(std::string* email) const { | 122 bool CloudPrintProxy::IsEnabled(std::string* email) const { |
123 bool enabled = !cloud_print_email().empty(); | 123 bool enabled = !cloud_print_email().empty(); |
124 if (enabled && email) { | 124 if (enabled && email) { |
125 *email = cloud_print_email(); | 125 *email = cloud_print_email(); |
126 } | 126 } |
127 return enabled; | 127 return enabled; |
128 } | 128 } |
(...skipping 25 matching lines...) Expand all Loading... |
154 void CloudPrintProxy::OnAuthenticationFailed() { | 154 void CloudPrintProxy::OnAuthenticationFailed() { |
155 DCHECK(CalledOnValidThread()); | 155 DCHECK(CalledOnValidThread()); |
156 // If authenticated failed, we will disable the cloud print proxy. | 156 // If authenticated failed, we will disable the cloud print proxy. |
157 DisableForUser(); | 157 DisableForUser(); |
158 // Launch the browser to display a notification that the credentials have | 158 // Launch the browser to display a notification that the credentials have |
159 // expired. | 159 // expired. |
160 g_service_process->io_thread()->message_loop_proxy()->PostTask( | 160 g_service_process->io_thread()->message_loop_proxy()->PostTask( |
161 FROM_HERE, NewRunnableFunction(&ShowTokenExpiredNotificationInBrowser)); | 161 FROM_HERE, NewRunnableFunction(&ShowTokenExpiredNotificationInBrowser)); |
162 } | 162 } |
163 | 163 |
| 164 void CloudPrintProxy::OnPrintSystemUnavailable() { |
| 165 // If the print system is unavailable, we want to shutdown the proxy and |
| 166 // disable it non-persistently. |
| 167 Shutdown(); |
| 168 if (client_) { |
| 169 client_->OnCloudPrintProxyDisabled(false); |
| 170 } |
| 171 } |
| 172 |
164 void CloudPrintProxy::Shutdown() { | 173 void CloudPrintProxy::Shutdown() { |
165 DCHECK(CalledOnValidThread()); | 174 DCHECK(CalledOnValidThread()); |
166 if (backend_.get()) | 175 if (backend_.get()) |
167 backend_->Shutdown(); | 176 backend_->Shutdown(); |
168 backend_.reset(); | 177 backend_.reset(); |
169 } | 178 } |
OLD | NEW |