| 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/location.h" |
| 9 #include "base/single_thread_task_runner.h" |
| 8 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/thread_task_runner_handle.h" |
| 9 #include "base/threading/thread_restrictions.h" | 12 #include "base/threading/thread_restrictions.h" |
| 10 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/notifications/desktop_notification_service.h" | 14 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 12 #include "chrome/browser/notifications/notification.h" | 15 #include "chrome/browser/notifications/notification.h" |
| 13 #include "chrome/browser/notifications/notification_delegate.h" | 16 #include "chrome/browser/notifications/notification_delegate.h" |
| 14 #include "chrome/browser/notifications/notification_ui_manager.h" | 17 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 15 #include "chrome/browser/profiles/profile_manager.h" | 18 #include "chrome/browser/profiles/profile_manager.h" |
| 16 #include "third_party/skia/include/core/SkBitmap.h" | 19 #include "third_party/skia/include/core/SkBitmap.h" |
| 17 #include "ui/gfx/image/image_skia.h" | 20 #include "ui/gfx/image/image_skia.h" |
| 18 | 21 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 32 | 35 |
| 33 // Timeout for automatically dismissing the notification balloon. | 36 // Timeout for automatically dismissing the notification balloon. |
| 34 const size_t kTimeoutSeconds = 6; | 37 const size_t kTimeoutSeconds = 6; |
| 35 | 38 |
| 36 class DummyNotificationDelegate : public NotificationDelegate { | 39 class DummyNotificationDelegate : public NotificationDelegate { |
| 37 public: | 40 public: |
| 38 explicit DummyNotificationDelegate(const std::string& id, Profile* profile) | 41 explicit DummyNotificationDelegate(const std::string& id, Profile* profile) |
| 39 : id_(kNotificationPrefix + id), profile_(profile) {} | 42 : id_(kNotificationPrefix + id), profile_(profile) {} |
| 40 | 43 |
| 41 void Display() override { | 44 void Display() override { |
| 42 base::MessageLoop::current()->PostDelayedTask( | 45 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 43 FROM_HERE, | 46 FROM_HERE, base::Bind(&CloseBalloon, id(), |
| 44 base::Bind( | 47 NotificationUIManager::GetProfileID(profile_)), |
| 45 &CloseBalloon, id(), NotificationUIManager::GetProfileID(profile_)), | |
| 46 base::TimeDelta::FromSeconds(kTimeoutSeconds)); | 48 base::TimeDelta::FromSeconds(kTimeoutSeconds)); |
| 47 } | 49 } |
| 48 std::string id() const override { return id_; } | 50 std::string id() const override { return id_; } |
| 49 | 51 |
| 50 private: | 52 private: |
| 51 ~DummyNotificationDelegate() override {} | 53 ~DummyNotificationDelegate() override {} |
| 52 | 54 |
| 53 std::string id_; | 55 std::string id_; |
| 54 Profile* profile_; | 56 Profile* profile_; |
| 55 }; | 57 }; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 83 NotificationDelegate* delegate = | 85 NotificationDelegate* delegate = |
| 84 new DummyNotificationDelegate(base::IntToString(id_count_++), profile_); | 86 new DummyNotificationDelegate(base::IntToString(id_count_++), profile_); |
| 85 Notification notification(GURL(), title, contents, gfx::Image(icon), | 87 Notification notification(GURL(), title, contents, gfx::Image(icon), |
| 86 base::string16(), std::string(), delegate); | 88 base::string16(), std::string(), delegate); |
| 87 | 89 |
| 88 g_browser_process->notification_ui_manager()->Add(notification, profile); | 90 g_browser_process->notification_ui_manager()->Add(notification, profile); |
| 89 | 91 |
| 90 notification_id_ = notification.delegate_id(); | 92 notification_id_ = notification.delegate_id(); |
| 91 profile_ = profile; | 93 profile_ = profile; |
| 92 } | 94 } |
| OLD | NEW |