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

Unified Diff: chrome/browser/printing/cloud_print/cloud_print_proxy_service.cc

Issue 3436019: Added code in the browser process to display a Cloud Print token expired desk... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Fixed Linux build Created 10 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/printing/cloud_print/cloud_print_proxy_service.h ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/printing/cloud_print/cloud_print_proxy_service.cc
===================================================================
--- chrome/browser/printing/cloud_print/cloud_print_proxy_service.cc (revision 59251)
+++ chrome/browser/printing/cloud_print/cloud_print_proxy_service.cc (working copy)
@@ -7,18 +7,45 @@
#include <stack>
#include <vector>
-#include "base/path_service.h"
+#include "app/l10n_util.h"
#include "base/utf_string_conversions.h"
+#include "chrome/browser/browser_list.h"
#include "chrome/browser/browser_process.h"
-#include "chrome/browser/chrome_thread.h"
-#include "chrome/browser/prefs/pref_service.h"
+#include "chrome/browser/notifications/desktop_notification_service.h"
+#include "chrome/browser/notifications/notification.h"
+#include "chrome/browser/notifications/notification_ui_manager.h"
#include "chrome/browser/profile.h"
-#include "chrome/browser/profile_manager.h"
-#include "chrome/common/chrome_paths.h"
-#include "chrome/common/notification_type.h"
-#include "chrome/common/pref_names.h"
+#include "grit/generated_resources.h"
-CloudPrintProxyService::CloudPrintProxyService(Profile* profile) {
+// TODO(sanjeevr): Localize the product name?
+const char kCloudPrintProductName[] = "Google Cloud Print";
+
+class CloudPrintProxyService::TokenExpiredNotificationDelegate
+ : public NotificationDelegate {
+ public:
+ explicit TokenExpiredNotificationDelegate(
+ CloudPrintProxyService* cloud_print_service)
+ : cloud_print_service_(cloud_print_service) {
+ }
+ void Display() {}
+ void Error() {
+ cloud_print_service_->OnTokenExpiredNotificationError();
+ }
+ void Close(bool by_user) {
+ cloud_print_service_->OnTokenExpiredNotificationClosed(by_user);
+ }
+ void Click() {
+ cloud_print_service_->OnTokenExpiredNotificationClick();
+ }
+ std::string id() const { return "cloudprint.tokenexpired"; }
+
+ private:
+ CloudPrintProxyService* cloud_print_service_;
+ DISALLOW_COPY_AND_ASSIGN(TokenExpiredNotificationDelegate);
+};
+
+CloudPrintProxyService::CloudPrintProxyService(Profile* profile)
+ : profile_(profile), token_expired_delegate_(NULL) {
}
CloudPrintProxyService::~CloudPrintProxyService() {
@@ -43,3 +70,48 @@
// running in the service process here.
}
+bool CloudPrintProxyService::ShowTokenExpiredNotification() {
+ // If we already have a pending notification, don't show another one.
+ if (token_expired_delegate_.get())
+ return false;
+
+ // TODO(sanjeevr): Get icon for this notification.
+ GURL icon_url;
+
+ string16 title = UTF8ToUTF16(kCloudPrintProductName);
+ string16 message =
+ l10n_util::GetStringUTF16(IDS_CLOUD_PRINT_TOKEN_EXPIRED_MESSAGE);
+ string16 content_url = DesktopNotificationService::CreateDataUrl(
+ icon_url, title, message, WebKit::WebTextDirectionDefault);
+ token_expired_delegate_ = new TokenExpiredNotificationDelegate(this);
+ Notification notification(GURL(), GURL(content_url), string16(), string16(),
John Gregg 2010/09/21 23:57:55 just FYI, this notification will be shown without
+ token_expired_delegate_.get());
+ g_browser_process->notification_ui_manager()->Add(notification, profile_);
+ // Keep the browser alive while we are showing the notification.
+ BrowserList::StartKeepAlive();
+ return true;
+}
+
+void CloudPrintProxyService::OnTokenExpiredNotificationError() {
+ TokenExpiredNotificationDone();
+}
+
+void CloudPrintProxyService::OnTokenExpiredNotificationClosed(bool by_user) {
+ TokenExpiredNotificationDone();
+}
+
+void CloudPrintProxyService::OnTokenExpiredNotificationClick() {
+ TokenExpiredNotificationDone();
+ // TODO(sanjeevr): Launch the cloud print setup flow.
+}
+
+void CloudPrintProxyService::TokenExpiredNotificationDone() {
+ if (token_expired_delegate_.get()) {
+ g_browser_process->notification_ui_manager()->Cancel(
+ Notification(GURL(), GURL(), string16(), string16(),
+ token_expired_delegate_.get()));
+ token_expired_delegate_ = NULL;
+ BrowserList::EndKeepAlive();
+ }
+}
+
« no previous file with comments | « chrome/browser/printing/cloud_print/cloud_print_proxy_service.h ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698