| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "ui/arc/notification/arc_custom_notification_item.h" | 5 #include "ui/arc/notification/arc_custom_notification_item.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "ui/arc/notification/arc_custom_notification_view.h" | 14 #include "ui/arc/notification/arc_custom_notification_view.h" |
| 15 #include "ui/message_center/notification.h" | 15 #include "ui/message_center/notification.h" |
| 16 #include "ui/message_center/notification_types.h" | 16 #include "ui/message_center/notification_types.h" |
| 17 #include "ui/message_center/views/custom_notification_content_view_delegate.h" | 17 #include "ui/message_center/views/custom_notification_content_view_delegate.h" |
| 18 | 18 |
| 19 namespace arc { | 19 namespace arc { |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 constexpr char kNotifierId[] = "ARC_NOTIFICATION"; | 23 constexpr char kNotifierId[] = "ARC_NOTIFICATION"; |
| 24 | 24 |
| 25 class ArcNotificationDelegate : public message_center::NotificationDelegate { | 25 class ArcNotificationDelegate : public message_center::NotificationDelegate { |
| 26 public: | 26 public: |
| 27 explicit ArcNotificationDelegate(ArcCustomNotificationItem* item) | 27 explicit ArcNotificationDelegate(ArcCustomNotificationItem* item) |
| 28 : item_(item) {} | 28 : item_(item) { |
| 29 DCHECK(item_); |
| 30 } |
| 29 | 31 |
| 30 std::unique_ptr<message_center::CustomContent> CreateCustomContent() | 32 std::unique_ptr<message_center::CustomContent> CreateCustomContent() |
| 31 override { | 33 override { |
| 32 auto view = base::MakeUnique<ArcCustomNotificationView>(item_); | 34 auto view = base::MakeUnique<ArcCustomNotificationView>(item_); |
| 33 auto content_view_delegate = view->CreateContentViewDelegate(); | 35 auto content_view_delegate = view->CreateContentViewDelegate(); |
| 34 return base::MakeUnique<message_center::CustomContent>( | 36 return base::MakeUnique<message_center::CustomContent>( |
| 35 std::move(view), std::move(content_view_delegate)); | 37 std::move(view), std::move(content_view_delegate)); |
| 36 } | 38 } |
| 37 | 39 |
| 40 void Close(bool by_user) override { item_->Close(by_user); } |
| 41 |
| 38 private: | 42 private: |
| 39 // The destructor is private since this class is ref-counted. | 43 // The destructor is private since this class is ref-counted. |
| 40 ~ArcNotificationDelegate() override {} | 44 ~ArcNotificationDelegate() override {} |
| 41 | 45 |
| 42 ArcCustomNotificationItem* const item_; | 46 ArcCustomNotificationItem* const item_; |
| 43 | 47 |
| 44 DISALLOW_COPY_AND_ASSIGN(ArcNotificationDelegate); | 48 DISALLOW_COPY_AND_ASSIGN(ArcNotificationDelegate); |
| 45 }; | 49 }; |
| 46 | 50 |
| 47 } // namespace | 51 } // namespace |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 snapshot_ = gfx::ImageSkia(gfx::ImageSkiaRep( | 106 snapshot_ = gfx::ImageSkia(gfx::ImageSkiaRep( |
| 103 *data->snapshot_image, data->snapshot_image_scale)); | 107 *data->snapshot_image, data->snapshot_image_scale)); |
| 104 } | 108 } |
| 105 | 109 |
| 106 for (auto& observer : observers_) | 110 for (auto& observer : observers_) |
| 107 observer.OnItemUpdated(); | 111 observer.OnItemUpdated(); |
| 108 | 112 |
| 109 AddToMessageCenter(); | 113 AddToMessageCenter(); |
| 110 } | 114 } |
| 111 | 115 |
| 112 void ArcCustomNotificationItem::CloseFromCloseButton() { | |
| 113 // Needs to manually remove notification from MessageCenter because | |
| 114 // the floating close button is not part of MessageCenter. | |
| 115 message_center()->RemoveNotification(notification_id(), true); | |
| 116 Close(true); | |
| 117 } | |
| 118 | |
| 119 void ArcCustomNotificationItem::AddObserver(Observer* observer) { | 116 void ArcCustomNotificationItem::AddObserver(Observer* observer) { |
| 120 observers_.AddObserver(observer); | 117 observers_.AddObserver(observer); |
| 121 } | 118 } |
| 122 | 119 |
| 123 void ArcCustomNotificationItem::RemoveObserver(Observer* observer) { | 120 void ArcCustomNotificationItem::RemoveObserver(Observer* observer) { |
| 124 observers_.RemoveObserver(observer); | 121 observers_.RemoveObserver(observer); |
| 125 } | 122 } |
| 126 | 123 |
| 127 void ArcCustomNotificationItem::IncrementWindowRefCount() { | 124 void ArcCustomNotificationItem::IncrementWindowRefCount() { |
| 128 ++window_ref_count_; | 125 ++window_ref_count_; |
| 129 if (window_ref_count_ == 1) | 126 if (window_ref_count_ == 1) |
| 130 manager()->CreateNotificationWindow(notification_key()); | 127 manager()->CreateNotificationWindow(notification_key()); |
| 131 } | 128 } |
| 132 | 129 |
| 133 void ArcCustomNotificationItem::DecrementWindowRefCount() { | 130 void ArcCustomNotificationItem::DecrementWindowRefCount() { |
| 134 DCHECK_GT(window_ref_count_, 0); | 131 DCHECK_GT(window_ref_count_, 0); |
| 135 --window_ref_count_; | 132 --window_ref_count_; |
| 136 if (window_ref_count_ == 0) | 133 if (window_ref_count_ == 0) |
| 137 manager()->CloseNotificationWindow(notification_key()); | 134 manager()->CloseNotificationWindow(notification_key()); |
| 138 } | 135 } |
| 139 | 136 |
| 140 } // namespace arc | 137 } // namespace arc |
| OLD | NEW |