Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(275)

Side by Side Diff: chrome/service/cloud_print/cloud_print_proxy.cc

Issue 2914573002: Replace deprecated base::NonThreadSafe in chrome/service in favor of SequenceChecker. (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 15 matching lines...) Expand all
26 26
27 namespace cloud_print { 27 namespace cloud_print {
28 28
29 CloudPrintProxy::CloudPrintProxy() 29 CloudPrintProxy::CloudPrintProxy()
30 : service_prefs_(NULL), 30 : service_prefs_(NULL),
31 client_(NULL), 31 client_(NULL),
32 enabled_(false) { 32 enabled_(false) {
33 } 33 }
34 34
35 CloudPrintProxy::~CloudPrintProxy() { 35 CloudPrintProxy::~CloudPrintProxy() {
36 DCHECK(CalledOnValidThread()); 36 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
37 ShutdownBackend(); 37 ShutdownBackend();
38 } 38 }
39 39
40 void CloudPrintProxy::Initialize(ServiceProcessPrefs* service_prefs, 40 void CloudPrintProxy::Initialize(ServiceProcessPrefs* service_prefs,
41 Client* client) { 41 Client* client) {
42 DCHECK(CalledOnValidThread()); 42 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
43 service_prefs_ = service_prefs; 43 service_prefs_ = service_prefs;
44 client_ = client; 44 client_ = client;
45 } 45 }
46 46
47 void CloudPrintProxy::EnableForUser() { 47 void CloudPrintProxy::EnableForUser() {
48 DCHECK(CalledOnValidThread()); 48 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
49 if (!CreateBackend()) 49 if (!CreateBackend())
50 return; 50 return;
51 DCHECK(backend_.get()); 51 DCHECK(backend_.get());
52 // Read persisted robot credentials because we may decide to reuse it if the 52 // Read persisted robot credentials because we may decide to reuse it if the
53 // passed in LSID belongs the same user. 53 // passed in LSID belongs the same user.
54 std::string robot_refresh_token = service_prefs_->GetString( 54 std::string robot_refresh_token = service_prefs_->GetString(
55 prefs::kCloudPrintRobotRefreshToken, std::string()); 55 prefs::kCloudPrintRobotRefreshToken, std::string());
56 std::string robot_email = 56 std::string robot_email =
57 service_prefs_->GetString(prefs::kCloudPrintRobotEmail, std::string()); 57 service_prefs_->GetString(prefs::kCloudPrintRobotEmail, std::string());
58 user_email_ = service_prefs_->GetString(prefs::kCloudPrintEmail, user_email_); 58 user_email_ = service_prefs_->GetString(prefs::kCloudPrintEmail, user_email_);
(...skipping 12 matching lines...) Expand all
71 if (client_) { 71 if (client_) {
72 client_->OnCloudPrintProxyEnabled(true); 72 client_->OnCloudPrintProxyEnabled(true);
73 } 73 }
74 } 74 }
75 75
76 void CloudPrintProxy::EnableForUserWithRobot( 76 void CloudPrintProxy::EnableForUserWithRobot(
77 const std::string& robot_auth_code, 77 const std::string& robot_auth_code,
78 const std::string& robot_email, 78 const std::string& robot_email,
79 const std::string& user_email, 79 const std::string& user_email,
80 const base::DictionaryValue& user_settings) { 80 const base::DictionaryValue& user_settings) {
81 DCHECK(CalledOnValidThread()); 81 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
82 82
83 ShutdownBackend(); 83 ShutdownBackend();
84 std::string proxy_id( 84 std::string proxy_id(
85 service_prefs_->GetString(prefs::kCloudPrintProxyId, std::string())); 85 service_prefs_->GetString(prefs::kCloudPrintProxyId, std::string()));
86 service_prefs_->RemovePref(prefs::kCloudPrintRoot); 86 service_prefs_->RemovePref(prefs::kCloudPrintRoot);
87 if (!proxy_id.empty()) { 87 if (!proxy_id.empty()) {
88 // Keep only proxy id; 88 // Keep only proxy id;
89 service_prefs_->SetString(prefs::kCloudPrintProxyId, proxy_id); 89 service_prefs_->SetString(prefs::kCloudPrintProxyId, proxy_id);
90 } 90 }
91 service_prefs_->SetValue(prefs::kCloudPrintUserSettings, 91 service_prefs_->SetValue(prefs::kCloudPrintUserSettings,
92 user_settings.CreateDeepCopy()); 92 user_settings.CreateDeepCopy());
93 service_prefs_->WritePrefs(); 93 service_prefs_->WritePrefs();
94 94
95 if (!CreateBackend()) 95 if (!CreateBackend())
96 return; 96 return;
97 DCHECK(backend_.get()); 97 DCHECK(backend_.get());
98 user_email_ = user_email; 98 user_email_ = user_email;
99 backend_->InitializeWithRobotAuthCode(robot_auth_code, robot_email); 99 backend_->InitializeWithRobotAuthCode(robot_auth_code, robot_email);
100 if (client_) { 100 if (client_) {
101 client_->OnCloudPrintProxyEnabled(true); 101 client_->OnCloudPrintProxyEnabled(true);
102 } 102 }
103 } 103 }
104 104
105 bool CloudPrintProxy::CreateBackend() { 105 bool CloudPrintProxy::CreateBackend() {
106 DCHECK(CalledOnValidThread()); 106 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
107 if (backend_.get()) 107 if (backend_.get())
108 return false; 108 return false;
109 109
110 ConnectorSettings settings; 110 ConnectorSettings settings;
111 settings.InitFrom(service_prefs_); 111 settings.InitFrom(service_prefs_);
112 112
113 // By default we don't poll for jobs when we lose XMPP connection. But this 113 // By default we don't poll for jobs when we lose XMPP connection. But this
114 // behavior can be overridden by a preference. 114 // behavior can be overridden by a preference.
115 bool enable_job_poll = 115 bool enable_job_poll =
116 service_prefs_->GetBoolean(prefs::kCloudPrintEnableJobPoll, false); 116 service_prefs_->GetBoolean(prefs::kCloudPrintEnableJobPoll, false);
117 117
118 gaia::OAuthClientInfo oauth_client_info; 118 gaia::OAuthClientInfo oauth_client_info;
119 oauth_client_info.client_id = 119 oauth_client_info.client_id =
120 google_apis::GetOAuth2ClientID(google_apis::CLIENT_CLOUD_PRINT); 120 google_apis::GetOAuth2ClientID(google_apis::CLIENT_CLOUD_PRINT);
121 oauth_client_info.client_secret = 121 oauth_client_info.client_secret =
122 google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_CLOUD_PRINT); 122 google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_CLOUD_PRINT);
123 oauth_client_info.redirect_uri = "oob"; 123 oauth_client_info.redirect_uri = "oob";
124 backend_.reset(new CloudPrintProxyBackend( 124 backend_.reset(new CloudPrintProxyBackend(
125 this, settings, oauth_client_info, enable_job_poll)); 125 this, settings, oauth_client_info, enable_job_poll));
126 return true; 126 return true;
127 } 127 }
128 128
129 void CloudPrintProxy::UnregisterPrintersAndDisableForUser() { 129 void CloudPrintProxy::UnregisterPrintersAndDisableForUser() {
130 DCHECK(CalledOnValidThread()); 130 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
131 if (backend_.get()) { 131 if (backend_.get()) {
132 // Try getting auth and printers info from the backend. 132 // Try getting auth and printers info from the backend.
133 // We'll get notified in this case. 133 // We'll get notified in this case.
134 backend_->UnregisterPrinters(); 134 backend_->UnregisterPrinters();
135 } else { 135 } else {
136 // If no backend available, disable connector immediately. 136 // If no backend available, disable connector immediately.
137 DisableForUser(); 137 DisableForUser();
138 } 138 }
139 } 139 }
140 140
141 void CloudPrintProxy::DisableForUser() { 141 void CloudPrintProxy::DisableForUser() {
142 DCHECK(CalledOnValidThread()); 142 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
143 user_email_.clear(); 143 user_email_.clear();
144 enabled_ = false; 144 enabled_ = false;
145 if (client_) { 145 if (client_) {
146 client_->OnCloudPrintProxyDisabled(true); 146 client_->OnCloudPrintProxyDisabled(true);
147 } 147 }
148 ShutdownBackend(); 148 ShutdownBackend();
149 } 149 }
150 150
151 void CloudPrintProxy::GetProxyInfo(CloudPrintProxyInfo* info) { 151 void CloudPrintProxy::GetProxyInfo(CloudPrintProxyInfo* info) {
152 info->enabled = enabled_; 152 info->enabled = enabled_;
(...skipping 18 matching lines...) Expand all
171 printing::PrinterList printer_list; 171 printing::PrinterList printer_list;
172 print_system->EnumeratePrinters(&printer_list); 172 print_system->EnumeratePrinters(&printer_list);
173 for (size_t i = 0; i < printer_list.size(); ++i) 173 for (size_t i = 0; i < printer_list.size(); ++i)
174 printers->push_back(printer_list[i].printer_name); 174 printers->push_back(printer_list[i].printer_name);
175 } 175 }
176 176
177 void CloudPrintProxy::OnAuthenticated( 177 void CloudPrintProxy::OnAuthenticated(
178 const std::string& robot_oauth_refresh_token, 178 const std::string& robot_oauth_refresh_token,
179 const std::string& robot_email, 179 const std::string& robot_email,
180 const std::string& user_email) { 180 const std::string& user_email) {
181 DCHECK(CalledOnValidThread()); 181 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
182 service_prefs_->SetString(prefs::kCloudPrintRobotRefreshToken, 182 service_prefs_->SetString(prefs::kCloudPrintRobotRefreshToken,
183 robot_oauth_refresh_token); 183 robot_oauth_refresh_token);
184 service_prefs_->SetString(prefs::kCloudPrintRobotEmail, 184 service_prefs_->SetString(prefs::kCloudPrintRobotEmail,
185 robot_email); 185 robot_email);
186 // If authenticating from a robot, the user email will be empty. 186 // If authenticating from a robot, the user email will be empty.
187 if (!user_email.empty()) { 187 if (!user_email.empty()) {
188 user_email_ = user_email; 188 user_email_ = user_email;
189 } 189 }
190 service_prefs_->SetString(prefs::kCloudPrintEmail, user_email_); 190 service_prefs_->SetString(prefs::kCloudPrintEmail, user_email_);
191 enabled_ = true; 191 enabled_ = true;
192 DCHECK(!user_email_.empty()); 192 DCHECK(!user_email_.empty());
193 service_prefs_->WritePrefs(); 193 service_prefs_->WritePrefs();
194 // When this switch used we don't want connector continue running, we just 194 // When this switch used we don't want connector continue running, we just
195 // need authentication. 195 // need authentication.
196 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 196 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
197 switches::kCloudPrintSetupProxy)) { 197 switches::kCloudPrintSetupProxy)) {
198 ShutdownBackend(); 198 ShutdownBackend();
199 if (client_) { 199 if (client_) {
200 client_->OnCloudPrintProxyDisabled(false); 200 client_->OnCloudPrintProxyDisabled(false);
201 } 201 }
202 } 202 }
203 } 203 }
204 204
205 void CloudPrintProxy::OnAuthenticationFailed() { 205 void CloudPrintProxy::OnAuthenticationFailed() {
206 DCHECK(CalledOnValidThread()); 206 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
207 // Don't disable permanently. Could be just connection issue. 207 // Don't disable permanently. Could be just connection issue.
208 ShutdownBackend(); 208 ShutdownBackend();
209 if (client_) { 209 if (client_) {
210 client_->OnCloudPrintProxyDisabled(false); 210 client_->OnCloudPrintProxyDisabled(false);
211 } 211 }
212 } 212 }
213 213
214 void CloudPrintProxy::OnPrintSystemUnavailable() { 214 void CloudPrintProxy::OnPrintSystemUnavailable() {
215 // If the print system is unavailable, we want to shutdown the proxy and 215 // If the print system is unavailable, we want to shutdown the proxy and
216 // disable it non-persistently. 216 // disable it non-persistently.
217 ShutdownBackend(); 217 ShutdownBackend();
218 if (client_) { 218 if (client_) {
219 client_->OnCloudPrintProxyDisabled(false); 219 client_->OnCloudPrintProxyDisabled(false);
220 } 220 }
221 } 221 }
222 222
223 void CloudPrintProxy::OnUnregisterPrinters( 223 void CloudPrintProxy::OnUnregisterPrinters(
224 const std::string& auth_token, 224 const std::string& auth_token,
225 const std::list<std::string>& printer_ids) { 225 const std::list<std::string>& printer_ids) {
226 UMA_HISTOGRAM_COUNTS_10000("CloudPrint.UnregisterPrinters", 226 UMA_HISTOGRAM_COUNTS_10000("CloudPrint.UnregisterPrinters",
227 printer_ids.size()); 227 printer_ids.size());
228 ShutdownBackend(); 228 ShutdownBackend();
229 ConnectorSettings settings; 229 ConnectorSettings settings;
230 settings.InitFrom(service_prefs_); 230 settings.InitFrom(service_prefs_);
231 wipeout_.reset(new CloudPrintWipeout(this, settings.server_url())); 231 wipeout_.reset(new CloudPrintWipeout(this, settings.server_url()));
232 wipeout_->UnregisterPrinters(auth_token, printer_ids); 232 wipeout_->UnregisterPrinters(auth_token, printer_ids);
233 } 233 }
234 234
235 void CloudPrintProxy::OnXmppPingUpdated(int ping_timeout) { 235 void CloudPrintProxy::OnXmppPingUpdated(int ping_timeout) {
236 DCHECK(CalledOnValidThread()); 236 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
237 service_prefs_->SetInt(prefs::kCloudPrintXmppPingTimeout, ping_timeout); 237 service_prefs_->SetInt(prefs::kCloudPrintXmppPingTimeout, ping_timeout);
238 service_prefs_->WritePrefs(); 238 service_prefs_->WritePrefs();
239 } 239 }
240 240
241 void CloudPrintProxy::OnUnregisterPrintersComplete() { 241 void CloudPrintProxy::OnUnregisterPrintersComplete() {
242 wipeout_.reset(); 242 wipeout_.reset();
243 // Finish disabling cloud print for this user. 243 // Finish disabling cloud print for this user.
244 DisableForUser(); 244 DisableForUser();
245 } 245 }
246 246
247 void CloudPrintProxy::ShutdownBackend() { 247 void CloudPrintProxy::ShutdownBackend() {
248 DCHECK(CalledOnValidThread()); 248 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
249 if (backend_.get()) 249 if (backend_.get())
250 backend_->Shutdown(); 250 backend_->Shutdown();
251 backend_.reset(); 251 backend_.reset();
252 } 252 }
253 253
254 } // namespace cloud_print 254 } // namespace cloud_print
OLDNEW
« no previous file with comments | « chrome/service/cloud_print/cloud_print_proxy.h ('k') | chrome/service/cloud_print/cloud_print_token_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698