| 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_notification_item.h" | 5 #include "ui/arc/notification/arc_notification_item.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 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 "base/task_runner.h" | 14 #include "base/task_runner.h" |
| 15 #include "base/task_runner_util.h" | 15 #include "base/task_scheduler/post_task.h" |
| 16 #include "base/threading/worker_pool.h" | |
| 17 #include "third_party/skia/include/core/SkCanvas.h" | 16 #include "third_party/skia/include/core/SkCanvas.h" |
| 18 #include "third_party/skia/include/core/SkPaint.h" | 17 #include "third_party/skia/include/core/SkPaint.h" |
| 19 #include "ui/gfx/codec/png_codec.h" | 18 #include "ui/gfx/codec/png_codec.h" |
| 20 #include "ui/gfx/geometry/size.h" | 19 #include "ui/gfx/geometry/size.h" |
| 21 #include "ui/gfx/image/image.h" | 20 #include "ui/gfx/image/image.h" |
| 22 #include "ui/gfx/text_elider.h" | 21 #include "ui/gfx/text_elider.h" |
| 23 #include "ui/message_center/message_center_style.h" | 22 #include "ui/message_center/message_center_style.h" |
| 24 #include "ui/message_center/notification.h" | 23 #include "ui/message_center/notification.h" |
| 25 #include "ui/message_center/notification_types.h" | 24 #include "ui/message_center/notification_types.h" |
| 26 #include "ui/message_center/notifier_settings.h" | 25 #include "ui/message_center/notifier_settings.h" |
| 27 | 26 |
| 28 namespace arc { | 27 namespace arc { |
| 29 | 28 |
| 30 namespace { | 29 namespace { |
| 31 | 30 |
| 32 constexpr char kNotifierId[] = "ARC_NOTIFICATION"; | 31 constexpr char kNotifierId[] = "ARC_NOTIFICATION"; |
| 33 constexpr char kNotificationIdPrefix[] = "ARC_NOTIFICATION_"; | 32 constexpr char kNotificationIdPrefix[] = "ARC_NOTIFICATION_"; |
| 34 | 33 |
| 35 SkBitmap DecodeImage(const std::vector<uint8_t>& data) { | 34 SkBitmap DecodeImage(const std::vector<uint8_t>& data) { |
| 36 DCHECK(base::WorkerPool::RunsTasksOnCurrentThread()); | |
| 37 DCHECK(!data.empty()); // empty string should be handled in caller. | 35 DCHECK(!data.empty()); // empty string should be handled in caller. |
| 38 | 36 |
| 39 // We may decode an image in the browser process since it has been generated | 37 // We may decode an image in the browser process since it has been generated |
| 40 // in NotificationListerService in Android and should be safe. | 38 // in NotificationListerService in Android and should be safe. |
| 41 SkBitmap bitmap; | 39 SkBitmap bitmap; |
| 42 gfx::PNGCodec::Decode(&data[0], data.size(), &bitmap); | 40 gfx::PNGCodec::Decode(&data[0], data.size(), &bitmap); |
| 43 return bitmap; | 41 return bitmap; |
| 44 } | 42 } |
| 45 | 43 |
| 46 // Crops the image to proper size for Chrome Notification. It accepts only | 44 // Crops the image to proper size for Chrome Notification. It accepts only |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 GURL(), // empty origin url, for system component | 228 GURL(), // empty origin url, for system component |
| 231 notifier_id, rich_data, | 229 notifier_id, rich_data, |
| 232 new ArcNotificationDelegate(weak_ptr_factory_.GetWeakPtr()))); | 230 new ArcNotificationDelegate(weak_ptr_factory_.GetWeakPtr()))); |
| 233 | 231 |
| 234 if (data->icon_data.size() == 0) { | 232 if (data->icon_data.size() == 0) { |
| 235 OnImageDecoded(SkBitmap()); // Pass an empty bitmap. | 233 OnImageDecoded(SkBitmap()); // Pass an empty bitmap. |
| 236 return; | 234 return; |
| 237 } | 235 } |
| 238 | 236 |
| 239 // TODO(yoshiki): Remove decoding by passing a bitmap directly from Android. | 237 // TODO(yoshiki): Remove decoding by passing a bitmap directly from Android. |
| 240 base::PostTaskAndReplyWithResult( | 238 base::PostTaskWithTraitsAndReplyWithResult( |
| 241 base::WorkerPool::GetTaskRunner(true).get(), FROM_HERE, | 239 FROM_HERE, base::TaskTraits().WithShutdownBehavior( |
| 240 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN), |
| 242 base::Bind(&DecodeImage, data->icon_data), | 241 base::Bind(&DecodeImage, data->icon_data), |
| 243 base::Bind(&ArcNotificationItem::OnImageDecoded, | 242 base::Bind(&ArcNotificationItem::OnImageDecoded, |
| 244 weak_ptr_factory_.GetWeakPtr())); | 243 weak_ptr_factory_.GetWeakPtr())); |
| 245 } | 244 } |
| 246 | 245 |
| 247 ArcNotificationItem::~ArcNotificationItem() {} | 246 ArcNotificationItem::~ArcNotificationItem() {} |
| 248 | 247 |
| 249 void ArcNotificationItem::OnClosedFromAndroid() { | 248 void ArcNotificationItem::OnClosedFromAndroid() { |
| 250 being_removed_by_manager_ = true; // Closing is initiated by the manager. | 249 being_removed_by_manager_ = true; // Closing is initiated by the manager. |
| 251 message_center_->RemoveNotification(notification_id_, false /* by_user */); | 250 message_center_->RemoveNotification(notification_id_, false /* by_user */); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 | 325 |
| 327 void ArcNotificationItem::OnImageDecoded(const SkBitmap& bitmap) { | 326 void ArcNotificationItem::OnImageDecoded(const SkBitmap& bitmap) { |
| 328 DCHECK(thread_checker_.CalledOnValidThread()); | 327 DCHECK(thread_checker_.CalledOnValidThread()); |
| 329 | 328 |
| 330 gfx::Image image = gfx::Image::CreateFrom1xBitmap(bitmap); | 329 gfx::Image image = gfx::Image::CreateFrom1xBitmap(bitmap); |
| 331 notification_->set_icon(image); | 330 notification_->set_icon(image); |
| 332 AddToMessageCenter(); | 331 AddToMessageCenter(); |
| 333 } | 332 } |
| 334 | 333 |
| 335 } // namespace arc | 334 } // namespace arc |
| OLD | NEW |