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

Side by Side Diff: ui/arc/notification/arc_custom_notification_item.cc

Issue 2668583005: Not Remove Non-Closable Arc Popup When Close Button is Pressed (Closed)
Patch Set: Created 3 years, 10 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 unified diff | Download patch
OLDNEW
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 message_center::MessageView* parent) override {
32 auto view = base::MakeUnique<ArcCustomNotificationView>(item_); 34 auto view = base::MakeUnique<ArcCustomNotificationView>(item_, parent);
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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 snapshot_ = gfx::ImageSkia(gfx::ImageSkiaRep( 104 snapshot_ = gfx::ImageSkia(gfx::ImageSkiaRep(
101 *data->snapshot_image, data->snapshot_image_scale)); 105 *data->snapshot_image, data->snapshot_image_scale));
102 } 106 }
103 107
104 for (auto& observer : observers_) 108 for (auto& observer : observers_)
105 observer.OnItemUpdated(); 109 observer.OnItemUpdated();
106 110
107 AddToMessageCenter(); 111 AddToMessageCenter();
108 } 112 }
109 113
110 void ArcCustomNotificationItem::CloseFromCloseButton() {
111 // Needs to manually remove notification from MessageCenter because
yoshiki 2017/02/06 22:22:22 This comment was wrong. We didn't need to call "Cl
112 // the floating close button is not part of MessageCenter.
113 message_center()->RemoveNotification(notification_id(), true);
114 Close(true);
115 }
116
117 void ArcCustomNotificationItem::AddObserver(Observer* observer) { 114 void ArcCustomNotificationItem::AddObserver(Observer* observer) {
118 observers_.AddObserver(observer); 115 observers_.AddObserver(observer);
119 } 116 }
120 117
121 void ArcCustomNotificationItem::RemoveObserver(Observer* observer) { 118 void ArcCustomNotificationItem::RemoveObserver(Observer* observer) {
122 observers_.RemoveObserver(observer); 119 observers_.RemoveObserver(observer);
123 } 120 }
124 121
125 void ArcCustomNotificationItem::IncrementWindowRefCount() { 122 void ArcCustomNotificationItem::IncrementWindowRefCount() {
126 ++window_ref_count_; 123 ++window_ref_count_;
127 if (window_ref_count_ == 1) 124 if (window_ref_count_ == 1)
128 manager()->CreateNotificationWindow(notification_key()); 125 manager()->CreateNotificationWindow(notification_key());
129 } 126 }
130 127
131 void ArcCustomNotificationItem::DecrementWindowRefCount() { 128 void ArcCustomNotificationItem::DecrementWindowRefCount() {
132 DCHECK_GT(window_ref_count_, 0); 129 DCHECK_GT(window_ref_count_, 0);
133 --window_ref_count_; 130 --window_ref_count_;
134 if (window_ref_count_ == 0) 131 if (window_ref_count_ == 0)
135 manager()->CloseNotificationWindow(notification_key()); 132 manager()->CloseNotificationWindow(notification_key());
136 } 133 }
137 134
138 } // namespace arc 135 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698