| 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/status_icons/desktop_notification_balloon.h" | 5 #include "chrome/browser/status_icons/desktop_notification_balloon.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
| 9 #include "base/threading/thread_restrictions.h" | 9 #include "base/threading/thread_restrictions.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 // Prefix added to the notification ids. | 25 // Prefix added to the notification ids. |
| 26 const char kNotificationPrefix[] = "desktop_notification_balloon."; | 26 const char kNotificationPrefix[] = "desktop_notification_balloon."; |
| 27 | 27 |
| 28 // Timeout for automatically dismissing the notification balloon. | 28 // Timeout for automatically dismissing the notification balloon. |
| 29 const size_t kTimeoutSeconds = 6; | 29 const size_t kTimeoutSeconds = 6; |
| 30 | 30 |
| 31 class DummyNotificationDelegate : public NotificationDelegate { | 31 class DummyNotificationDelegate : public NotificationDelegate { |
| 32 public: | 32 public: |
| 33 explicit DummyNotificationDelegate(const std::string& id) | 33 explicit DummyNotificationDelegate(const std::string& id) |
| 34 : id_(kNotificationPrefix + id) {} | 34 : id_(kNotificationPrefix + id) {} |
| 35 virtual ~DummyNotificationDelegate() {} | |
| 36 | 35 |
| 37 virtual void Display() OVERRIDE { | 36 virtual void Display() OVERRIDE { |
| 38 MessageLoop::current()->PostDelayedTask( | 37 MessageLoop::current()->PostDelayedTask( |
| 39 FROM_HERE, | 38 FROM_HERE, |
| 40 base::Bind(&CloseBalloon, id()), | 39 base::Bind(&CloseBalloon, id()), |
| 41 base::TimeDelta::FromSeconds(kTimeoutSeconds)); | 40 base::TimeDelta::FromSeconds(kTimeoutSeconds)); |
| 42 } | 41 } |
| 43 virtual void Error() OVERRIDE {} | 42 virtual void Error() OVERRIDE {} |
| 44 virtual void Close(bool by_user) OVERRIDE {} | 43 virtual void Close(bool by_user) OVERRIDE {} |
| 45 virtual void Click() OVERRIDE {} | 44 virtual void Click() OVERRIDE {} |
| 46 virtual std::string id() const OVERRIDE { return id_; } | 45 virtual std::string id() const OVERRIDE { return id_; } |
| 47 | 46 |
| 48 private: | 47 private: |
| 48 virtual ~DummyNotificationDelegate() {} |
| 49 |
| 49 std::string id_; | 50 std::string id_; |
| 50 }; | 51 }; |
| 51 | 52 |
| 52 } // anonymous namespace | 53 } // anonymous namespace |
| 53 | 54 |
| 54 int DesktopNotificationBalloon::id_count_ = 1; | 55 int DesktopNotificationBalloon::id_count_ = 1; |
| 55 | 56 |
| 56 DesktopNotificationBalloon::DesktopNotificationBalloon() { | 57 DesktopNotificationBalloon::DesktopNotificationBalloon() { |
| 57 } | 58 } |
| 58 | 59 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 75 GURL(), content_url, string16(), string16(), | 76 GURL(), content_url, string16(), string16(), |
| 76 new DummyNotificationDelegate(base::IntToString(id_count_++)))); | 77 new DummyNotificationDelegate(base::IntToString(id_count_++)))); |
| 77 | 78 |
| 78 // Allowing IO access is required here to cover the corner case where | 79 // Allowing IO access is required here to cover the corner case where |
| 79 // there is no last used profile and the default one is loaded. | 80 // there is no last used profile and the default one is loaded. |
| 80 // IO access won't be required for normal uses. | 81 // IO access won't be required for normal uses. |
| 81 base::ThreadRestrictions::ScopedAllowIO allow_io; | 82 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 82 g_browser_process->notification_ui_manager()->Add( | 83 g_browser_process->notification_ui_manager()->Add( |
| 83 *notification_.get(), ProfileManager::GetLastUsedProfile()); | 84 *notification_.get(), ProfileManager::GetLastUsedProfile()); |
| 84 } | 85 } |
| OLD | NEW |