Chromium Code Reviews| 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/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/path_service.h" | 10 #include "app/l10n_util.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/browser/browser_list.h" | |
| 12 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/chrome_thread.h" | 14 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 14 #include "chrome/browser/prefs/pref_service.h" | 15 #include "chrome/browser/notifications/notification.h" |
| 16 #include "chrome/browser/notifications/notification_ui_manager.h" | |
| 15 #include "chrome/browser/profile.h" | 17 #include "chrome/browser/profile.h" |
| 16 #include "chrome/browser/profile_manager.h" | 18 #include "grit/generated_resources.h" |
| 17 #include "chrome/common/chrome_paths.h" | |
| 18 #include "chrome/common/notification_type.h" | |
| 19 #include "chrome/common/pref_names.h" | |
| 20 | 19 |
| 21 CloudPrintProxyService::CloudPrintProxyService(Profile* profile) { | 20 // TODO(sanjeevr): Localize the product name? |
| 21 const char kCloudPrintProductName[] = "Google Cloud Print"; | |
| 22 | |
| 23 class CloudPrintProxyService::TokenExpiredNotificationDelegate | |
| 24 : public NotificationDelegate { | |
| 25 public: | |
| 26 explicit TokenExpiredNotificationDelegate( | |
| 27 CloudPrintProxyService* cloud_print_service) | |
| 28 : cloud_print_service_(cloud_print_service) { | |
| 29 } | |
| 30 void Display() {} | |
| 31 void Error() { | |
| 32 cloud_print_service_->OnTokenExpiredNotificationError(); | |
| 33 } | |
| 34 void Close(bool by_user) { | |
| 35 cloud_print_service_->OnTokenExpiredNotificationClosed(by_user); | |
| 36 } | |
| 37 void Click() { | |
| 38 cloud_print_service_->OnTokenExpiredNotificationClick(); | |
| 39 } | |
| 40 std::string id() const { return "cloudprint.tokenexpired"; } | |
| 41 | |
| 42 private: | |
| 43 CloudPrintProxyService* cloud_print_service_; | |
| 44 DISALLOW_COPY_AND_ASSIGN(TokenExpiredNotificationDelegate); | |
| 45 }; | |
| 46 | |
| 47 CloudPrintProxyService::CloudPrintProxyService(Profile* profile) | |
| 48 : profile_(profile), token_expired_delegate_(NULL) { | |
| 22 } | 49 } |
| 23 | 50 |
| 24 CloudPrintProxyService::~CloudPrintProxyService() { | 51 CloudPrintProxyService::~CloudPrintProxyService() { |
| 25 Shutdown(); | 52 Shutdown(); |
| 26 } | 53 } |
| 27 | 54 |
| 28 void CloudPrintProxyService::Initialize() { | 55 void CloudPrintProxyService::Initialize() { |
| 29 } | 56 } |
| 30 | 57 |
| 31 | 58 |
| 32 void CloudPrintProxyService::EnableForUser(const std::string& auth_token) { | 59 void CloudPrintProxyService::EnableForUser(const std::string& auth_token) { |
| 33 // TODO(sanjeevr): Add code to communicate with the cloud print proxy code | 60 // TODO(sanjeevr): Add code to communicate with the cloud print proxy code |
| 34 // running in the service process here. | 61 // running in the service process here. |
| 35 } | 62 } |
| 36 | 63 |
| 37 void CloudPrintProxyService::DisableForUser() { | 64 void CloudPrintProxyService::DisableForUser() { |
| 38 Shutdown(); | 65 Shutdown(); |
| 39 } | 66 } |
| 40 | 67 |
| 41 void CloudPrintProxyService::Shutdown() { | 68 void CloudPrintProxyService::Shutdown() { |
| 42 // TODO(sanjeevr): Add code to communicate with the cloud print proxy code | 69 // TODO(sanjeevr): Add code to communicate with the cloud print proxy code |
| 43 // running in the service process here. | 70 // running in the service process here. |
| 44 } | 71 } |
| 45 | 72 |
| 73 bool CloudPrintProxyService::ShowTokenExpiredNotification() { | |
| 74 // If we already have a pending notification, don't show another one. | |
| 75 if (token_expired_delegate_.get()) | |
| 76 return false; | |
| 77 | |
| 78 // TODO(sanjeevr): Get icon for this notification. | |
| 79 GURL icon_url; | |
| 80 | |
| 81 string16 title = UTF8ToUTF16(kCloudPrintProductName); | |
| 82 string16 message = | |
| 83 l10n_util::GetStringUTF16(IDS_CLOUD_PRINT_TOKEN_EXPIRED_MESSAGE); | |
| 84 string16 content_url = DesktopNotificationService::CreateDataUrl( | |
| 85 icon_url, title, message, WebKit::WebTextDirectionDefault); | |
| 86 token_expired_delegate_ = new TokenExpiredNotificationDelegate(this); | |
| 87 Notification notification(GURL(), GURL(content_url), string16(), string16(), | |
|
John Gregg
2010/09/21 23:57:55
just FYI, this notification will be shown without
| |
| 88 token_expired_delegate_.get()); | |
| 89 g_browser_process->notification_ui_manager()->Add(notification, profile_); | |
| 90 // Keep the browser alive while we are showing the notification. | |
| 91 BrowserList::StartKeepAlive(); | |
| 92 return true; | |
| 93 } | |
| 94 | |
| 95 void CloudPrintProxyService::OnTokenExpiredNotificationError() { | |
| 96 TokenExpiredNotificationDone(); | |
| 97 } | |
| 98 | |
| 99 void CloudPrintProxyService::OnTokenExpiredNotificationClosed(bool by_user) { | |
| 100 TokenExpiredNotificationDone(); | |
| 101 } | |
| 102 | |
| 103 void CloudPrintProxyService::OnTokenExpiredNotificationClick() { | |
| 104 TokenExpiredNotificationDone(); | |
| 105 // TODO(sanjeevr): Launch the cloud print setup flow. | |
| 106 } | |
| 107 | |
| 108 void CloudPrintProxyService::TokenExpiredNotificationDone() { | |
| 109 if (token_expired_delegate_.get()) { | |
| 110 g_browser_process->notification_ui_manager()->Cancel( | |
| 111 Notification(GURL(), GURL(), string16(), string16(), | |
| 112 token_expired_delegate_.get())); | |
| 113 token_expired_delegate_ = NULL; | |
| 114 BrowserList::EndKeepAlive(); | |
| 115 } | |
| 116 } | |
| 117 | |
| OLD | NEW |