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

Unified Diff: chrome/browser/chromeos/arc/notification/arc_notification_item.cc

Issue 1475583002: Add IPC messages for ARC notification (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/arc/notification/arc_notification_item.cc
diff --git a/chrome/browser/chromeos/arc/notification/arc_notification_item.cc b/chrome/browser/chromeos/arc/notification/arc_notification_item.cc
new file mode 100644
index 0000000000000000000000000000000000000000..16de196008a49a23d25177072e77caa3be5113ab
--- /dev/null
+++ b/chrome/browser/chromeos/arc/notification/arc_notification_item.cc
@@ -0,0 +1,119 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/arc/notification/arc_notification_item.h"
+
+#include "base/strings/string16.h"
+#include "base/strings/utf_string_conversions.h"
+#include "ui/gfx/image/image.h"
+#include "ui/message_center/notification.h"
+#include "ui/message_center/notification_types.h"
+#include "ui/message_center/notifier_settings.h"
+
+namespace {
+
+// static
+static const char* kNotificationIdPrefix = "ARC_NOTIFICATION_";
+
+// static
+const char kArcNotificationOrigin[] = "chrome://arc";
+
+class ArcNotificationDelegate : public message_center::NotificationDelegate {
+ public:
+ explicit ArcNotificationDelegate(
+ base::WeakPtr<chromeos::ArcNotificationItem> item)
+ : item_(item) {}
+
+ void Close(bool by_user) override {
+ if (item_)
+ item_->Close(by_user);
+ }
+
+ bool HasClickedListener() override { return true; }
+
+ void Click() override {
+ if (item_)
+ item_->Click();
+ }
+
+ private:
+ // The destractor is private since this classes is ref-counted.
+ ~ArcNotificationDelegate() override {}
+
+ base::WeakPtr<chromeos::ArcNotificationItem> item_;
+};
+
+} // anonymous namespace
+
+namespace chromeos {
+
+ArcNotificationItem::ArcNotificationItem(
+ ArcNotificationManager* manager,
+ message_center::MessageCenter* message_center,
+ const arc::ArcNotificationData& data)
+ : manager_(manager),
+ message_center_(message_center),
+ data_(data),
+ weak_ptr_factory_(this) {
+ // This must be initialized after ArcBridgeService.
+ DCHECK(arc::ArcBridgeService::Get());
+
+ notification_id_ = kNotificationIdPrefix + data_.key;
+
+ data_ = data;
+ std::string icon_data_str(data.icon_data.begin(), data.icon_data.end());
+ ImageDecoder::Start(this, icon_data_str);
+}
+
+ArcNotificationItem::~ArcNotificationItem() {
+ ImageDecoder::Cancel(this); // just in case
khmel1 2015/11/25 00:30:10 It is automatically canceled on DTOR
yoshiki 2015/11/25 09:40:34 Done.
+}
+
+void ArcNotificationItem::OnClosedFromAndroid() {
+ message_center_->RemoveNotification(notification_id_, true /* by_user */);
+}
+
+void ArcNotificationItem::Close(bool by_user) {
+ manager_->NotifyNotificationRemovedFromChrome(data_.key);
+}
+
+void ArcNotificationItem::Click() {
+ manager_->NotifyNotificationClickedFromChrome(data_.key);
+}
+
+void ArcNotificationItem::OnImageDecoded(const SkBitmap& bitmap) {
+ gfx::Image image = gfx::Image::CreateFrom1xBitmap(bitmap);
+
+ message_center::RichNotificationData rich_data;
+
+ message_center::NotificationType type =
+ message_center::NOTIFICATION_TYPE_SIMPLE;
+ switch (data_.type) {
+ case arc::NOTIFICATION_TYPE_PROGRESS:
+ type = message_center::NOTIFICATION_TYPE_PROGRESS;
+ rich_data.timestamp = data_.timestamp;
+ rich_data.progress =
+ std::floor(static_cast<float>(data_.progress_current) /
+ data_.progress_max * 100 +
+ 0.5);
+ break;
+ default:
+ // TODO(yoshiki): Implement other types.
+ break;
+ }
+
+ scoped_ptr<message_center::Notification> notification(
+ new message_center::Notification(
+ type, notification_id_, base::UTF8ToUTF16(data_.title),
+ base::UTF8ToUTF16(data_.message), image,
+ base::UTF8ToUTF16("arc"), // display source
+ GURL(kArcNotificationOrigin), // origin url
+ message_center::NotifierId(
+ message_center::NotifierId::SYSTEM_COMPONENT, notification_id_),
+ rich_data,
+ new ArcNotificationDelegate(weak_ptr_factory_.GetWeakPtr())));
+ message_center_->AddNotification(notification.Pass());
+}
+
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698