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

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

Issue 1477733002: Add ArcNotificationManager for new ARC notification (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix comment Created 5 years 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..782aba5e49d48e094696f207438d7f155cc4160d
--- /dev/null
+++ b/chrome/browser/chromeos/arc/notification/arc_notification_item.cc
@@ -0,0 +1,128 @@
+// 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"
+
+#if defined(USE_ASH)
+#include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
+#include "components/signin/core/account_id/account_id.h"
+#endif
+
+namespace {
+
+// static
+static const char* kNotificationIdPrefix = "ARC_NOTIFICATION_";
+
+// static
+const char kArcNotificationOrigin[] = "chrome://arc";
elijahtaylor1 2015/12/09 06:41:25 what is the implication of using something like th
yoshiki 2015/12/09 17:11:09 As I read the code, empty URL is acceptable. So I
+
+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; }
elijahtaylor1 2015/12/09 06:41:25 what is this for? maybe a comment?
yoshiki 2015/12/09 17:11:09 Done. This changes the cursor on hover. I'll refin
+
+ void Click() override {
+ if (item_)
+ item_->Click();
+ }
+
+ private:
+ // The destractor is private since this classes is ref-counted.
elijahtaylor1 2015/12/09 06:41:25 s/classes/class/
yoshiki 2015/12/09 17:11:09 Done.
+ ~ArcNotificationDelegate() override {}
+
+ base::WeakPtr<chromeos::ArcNotificationItem> item_;
+};
+
+} // anonymous namespace
+
+namespace chromeos {
+
+ArcNotificationItem::ArcNotificationItem(
+ ArcNotificationManager* manager,
+ message_center::MessageCenter* message_center,
+ const arc::ArcNotificationData& data,
+ Profile* profile)
+ : manager_(manager),
+ message_center_(message_center),
+ data_(data),
+ profile_(profile),
+ weak_ptr_factory_(this) {
+ // This must be initialized after ArcBridgeService.
+ DCHECK(arc::ArcBridgeService::Get());
elijahtaylor1 2015/12/09 06:41:25 nothing in this class uses ArcBridgeService, what
yoshiki 2015/12/09 17:11:09 Rdmoved.
+
+ notification_id_ = kNotificationIdPrefix + data_.key;
+
+ std::string icon_data_str(data.icon_data.begin(), data.icon_data.end());
+ ImageDecoder::Start(this, icon_data_str);
+}
+
+ArcNotificationItem::~ArcNotificationItem() {}
+
+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::ArcNotificationType::PROGRESS:
+ type = message_center::NOTIFICATION_TYPE_PROGRESS;
+ rich_data.timestamp = data_.time;
+ rich_data.progress =
+ std::floor(static_cast<float>(data_.progress_current) /
+ data_.progress_max * 100 +
+ 0.5);
elijahtaylor1 2015/12/09 06:41:25 what is the 0.5 for?
yoshiki 2015/12/09 17:11:09 I intended just "round up".
+ break;
+ default:
+ // TODO(yoshiki): Implement other types.
+ break;
+ }
+
+ message_center::NotifierId notifier_id(
+ message_center::NotifierId::SYSTEM_COMPONENT, notification_id_);
+#if defined(USE_ASH)
+ notifier_id.profile_id =
+ multi_user_util::GetAccountIdFromProfile(profile_).GetUserEmail();
+#endif
+
+ 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
+ notifier_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