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/browser/printing/cloud_print/cloud_print_proxy_service.h" | 5 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" |
6 | 6 |
7 #include <stack> | 7 #include <stack> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/lifetime/application_lifetime.h" |
15 #include "chrome/browser/notifications/desktop_notification_service.h" | 16 #include "chrome/browser/notifications/desktop_notification_service.h" |
16 #include "chrome/browser/notifications/notification.h" | 17 #include "chrome/browser/notifications/notification.h" |
17 #include "chrome/browser/notifications/notification_ui_manager.h" | 18 #include "chrome/browser/notifications/notification_ui_manager.h" |
18 #include "chrome/browser/prefs/pref_service.h" | 19 #include "chrome/browser/prefs/pref_service.h" |
19 #include "chrome/browser/printing/cloud_print/cloud_print_setup_flow.h" | 20 #include "chrome/browser/printing/cloud_print/cloud_print_setup_flow.h" |
20 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/browser/service/service_process_control.h" | 22 #include "chrome/browser/service/service_process_control.h" |
22 #include "chrome/browser/ui/browser_list.h" | |
23 #include "chrome/common/chrome_notification_types.h" | 23 #include "chrome/common/chrome_notification_types.h" |
24 #include "chrome/common/cloud_print/cloud_print_proxy_info.h" | 24 #include "chrome/common/cloud_print/cloud_print_proxy_info.h" |
25 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
26 #include "chrome/common/service_messages.h" | 26 #include "chrome/common/service_messages.h" |
27 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
28 #include "grit/generated_resources.h" | 28 #include "grit/generated_resources.h" |
29 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
30 | 30 |
31 using content::BrowserThread; | 31 using content::BrowserThread; |
32 | 32 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 string16 title = l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT); | 138 string16 title = l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT); |
139 string16 message = | 139 string16 message = |
140 l10n_util::GetStringFUTF16(IDS_CLOUD_PRINT_TOKEN_EXPIRED_MESSAGE, title); | 140 l10n_util::GetStringFUTF16(IDS_CLOUD_PRINT_TOKEN_EXPIRED_MESSAGE, title); |
141 string16 content_url = DesktopNotificationService::CreateDataUrl( | 141 string16 content_url = DesktopNotificationService::CreateDataUrl( |
142 icon_url, title, message, WebKit::WebTextDirectionDefault); | 142 icon_url, title, message, WebKit::WebTextDirectionDefault); |
143 token_expired_delegate_ = new TokenExpiredNotificationDelegate(this); | 143 token_expired_delegate_ = new TokenExpiredNotificationDelegate(this); |
144 Notification notification(GURL(), GURL(content_url), string16(), string16(), | 144 Notification notification(GURL(), GURL(content_url), string16(), string16(), |
145 token_expired_delegate_.get()); | 145 token_expired_delegate_.get()); |
146 g_browser_process->notification_ui_manager()->Add(notification, profile_); | 146 g_browser_process->notification_ui_manager()->Add(notification, profile_); |
147 // Keep the browser alive while we are showing the notification. | 147 // Keep the browser alive while we are showing the notification. |
148 BrowserList::StartKeepAlive(); | 148 browser::StartKeepAlive(); |
149 return true; | 149 return true; |
150 } | 150 } |
151 | 151 |
152 void CloudPrintProxyService::OnTokenExpiredNotificationError() { | 152 void CloudPrintProxyService::OnTokenExpiredNotificationError() { |
153 TokenExpiredNotificationDone(false); | 153 TokenExpiredNotificationDone(false); |
154 } | 154 } |
155 | 155 |
156 void CloudPrintProxyService::OnTokenExpiredNotificationClosed(bool by_user) { | 156 void CloudPrintProxyService::OnTokenExpiredNotificationClosed(bool by_user) { |
157 TokenExpiredNotificationDone(false); | 157 TokenExpiredNotificationDone(false); |
158 } | 158 } |
159 | 159 |
160 void CloudPrintProxyService::OnTokenExpiredNotificationClick() { | 160 void CloudPrintProxyService::OnTokenExpiredNotificationClick() { |
161 TokenExpiredNotificationDone(true); | 161 TokenExpiredNotificationDone(true); |
162 // Clear the cached cloud print email pref so that the cloud print setup | 162 // Clear the cached cloud print email pref so that the cloud print setup |
163 // flow happens. | 163 // flow happens. |
164 profile_->GetPrefs()->SetString(prefs::kCloudPrintEmail, std::string()); | 164 profile_->GetPrefs()->SetString(prefs::kCloudPrintEmail, std::string()); |
165 cloud_print_setup_handler_.reset(new CloudPrintSetupHandler(this)); | 165 cloud_print_setup_handler_.reset(new CloudPrintSetupHandler(this)); |
166 CloudPrintSetupFlow::OpenDialog( | 166 CloudPrintSetupFlow::OpenDialog( |
167 profile_, cloud_print_setup_handler_->AsWeakPtr(), NULL); | 167 profile_, cloud_print_setup_handler_->AsWeakPtr(), NULL); |
168 } | 168 } |
169 | 169 |
170 void CloudPrintProxyService::TokenExpiredNotificationDone(bool keep_alive) { | 170 void CloudPrintProxyService::TokenExpiredNotificationDone(bool keep_alive) { |
171 if (token_expired_delegate_.get()) { | 171 if (token_expired_delegate_.get()) { |
172 g_browser_process->notification_ui_manager()->CancelById( | 172 g_browser_process->notification_ui_manager()->CancelById( |
173 token_expired_delegate_->id()); | 173 token_expired_delegate_->id()); |
174 token_expired_delegate_ = NULL; | 174 token_expired_delegate_ = NULL; |
175 if (!keep_alive) | 175 if (!keep_alive) |
176 BrowserList::EndKeepAlive(); | 176 browser::EndKeepAlive(); |
177 } | 177 } |
178 } | 178 } |
179 | 179 |
180 bool CloudPrintProxyService::ApplyCloudPrintConnectorPolicy() { | 180 bool CloudPrintProxyService::ApplyCloudPrintConnectorPolicy() { |
181 if (!profile_->GetPrefs()->GetBoolean(prefs::kCloudPrintProxyEnabled)) { | 181 if (!profile_->GetPrefs()->GetBoolean(prefs::kCloudPrintProxyEnabled)) { |
182 std::string email = | 182 std::string email = |
183 profile_->GetPrefs()->GetString(prefs::kCloudPrintEmail); | 183 profile_->GetPrefs()->GetString(prefs::kCloudPrintEmail); |
184 if (!email.empty()) { | 184 if (!email.empty()) { |
185 DisableForUser(); | 185 DisableForUser(); |
186 profile_->GetPrefs()->SetString(prefs::kCloudPrintEmail, std::string()); | 186 profile_->GetPrefs()->SetString(prefs::kCloudPrintEmail, std::string()); |
187 if (enforcing_connector_policy_) { | 187 if (enforcing_connector_policy_) { |
188 MessageLoop::current()->PostTask( | 188 MessageLoop::current()->PostTask( |
189 FROM_HERE, | 189 FROM_HERE, |
190 base::Bind(&CloudPrintProxyService::RefreshCloudPrintProxyStatus, | 190 base::Bind(&CloudPrintProxyService::RefreshCloudPrintProxyStatus, |
191 weak_factory_.GetWeakPtr())); | 191 weak_factory_.GetWeakPtr())); |
192 } | 192 } |
193 return false; | 193 return false; |
194 } else if (enforcing_connector_policy_) { | 194 } else if (enforcing_connector_policy_) { |
195 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 195 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
196 } | 196 } |
197 } | 197 } |
198 return true; | 198 return true; |
199 } | 199 } |
200 | 200 |
201 void CloudPrintProxyService::OnCloudPrintSetupClosed() { | 201 void CloudPrintProxyService::OnCloudPrintSetupClosed() { |
202 MessageLoop::current()->PostTask( | 202 MessageLoop::current()->PostTask( |
203 FROM_HERE, base::Bind(&BrowserList::EndKeepAlive)); | 203 FROM_HERE, base::Bind(&browser::EndKeepAlive)); |
204 } | 204 } |
205 | 205 |
206 void CloudPrintProxyService::Observe( | 206 void CloudPrintProxyService::Observe( |
207 int type, | 207 int type, |
208 const content::NotificationSource& source, | 208 const content::NotificationSource& source, |
209 const content::NotificationDetails& details) { | 209 const content::NotificationDetails& details) { |
210 DCHECK_EQ(chrome::NOTIFICATION_PREF_CHANGED, type); | 210 DCHECK_EQ(chrome::NOTIFICATION_PREF_CHANGED, type); |
211 ApplyCloudPrintConnectorPolicy(); | 211 ApplyCloudPrintConnectorPolicy(); |
212 } | 212 } |
213 | 213 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 } | 263 } |
264 | 264 |
265 bool CloudPrintProxyService::InvokeServiceTask(const base::Closure& task) { | 265 bool CloudPrintProxyService::InvokeServiceTask(const base::Closure& task) { |
266 GetServiceProcessControl()->Launch(task, base::Closure()); | 266 GetServiceProcessControl()->Launch(task, base::Closure()); |
267 return true; | 267 return true; |
268 } | 268 } |
269 | 269 |
270 ServiceProcessControl* CloudPrintProxyService::GetServiceProcessControl() { | 270 ServiceProcessControl* CloudPrintProxyService::GetServiceProcessControl() { |
271 return ServiceProcessControl::GetInstance(); | 271 return ServiceProcessControl::GetInstance(); |
272 } | 272 } |
OLD | NEW |