| 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 "chrome/browser/notifications/native_notification_display_service.h" | 5 #include "chrome/browser/notifications/native_notification_display_service.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/strings/nullable_string16.h" | 8 #include "base/strings/nullable_string16.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/notifications/non_persistent_notification_handler.h" | 10 #include "chrome/browser/notifications/non_persistent_notification_handler.h" |
| 11 #include "chrome/browser/notifications/notification.h" | 11 #include "chrome/browser/notifications/notification.h" |
| 12 #include "chrome/browser/notifications/notification_delegate.h" | 12 #include "chrome/browser/notifications/notification_delegate.h" |
| 13 #include "chrome/browser/notifications/notification_handler.h" | 13 #include "chrome/browser/notifications/notification_handler.h" |
| 14 #include "chrome/browser/notifications/notification_platform_bridge.h" | 14 #include "chrome/browser/notifications/notification_platform_bridge.h" |
| 15 #include "chrome/browser/notifications/persistent_notification_handler.h" | 15 #include "chrome/browser/notifications/persistent_notification_handler.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 | 17 |
| 18 #include "content/public/browser/browser_thread.h" |
| 19 |
| 18 namespace { | 20 namespace { |
| 19 | 21 |
| 20 std::string GetProfileId(Profile* profile) { | 22 std::string GetProfileId(Profile* profile) { |
| 21 #if defined(OS_WIN) | 23 #if defined(OS_WIN) |
| 22 std::string profile_id = | 24 std::string profile_id = |
| 23 base::WideToUTF8(profile->GetPath().BaseName().value()); | 25 base::WideToUTF8(profile->GetPath().BaseName().value()); |
| 24 #elif defined(OS_POSIX) | 26 #elif defined(OS_POSIX) |
| 25 std::string profile_id = profile->GetPath().BaseName().value(); | 27 std::string profile_id = profile->GetPath().BaseName().value(); |
| 26 #endif | 28 #endif |
| 27 return profile_id; | 29 return profile_id; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 // the origin. | 70 // the origin. |
| 69 handler->OnClose(profile_, "", notification_id, false /* by user */); | 71 handler->OnClose(profile_, "", notification_id, false /* by user */); |
| 70 } | 72 } |
| 71 | 73 |
| 72 bool NativeNotificationDisplayService::GetDisplayed( | 74 bool NativeNotificationDisplayService::GetDisplayed( |
| 73 std::set<std::string>* notifications) const { | 75 std::set<std::string>* notifications) const { |
| 74 return notification_bridge_->GetDisplayed( | 76 return notification_bridge_->GetDisplayed( |
| 75 GetProfileId(profile_), profile_->IsOffTheRecord(), notifications); | 77 GetProfileId(profile_), profile_->IsOffTheRecord(), notifications); |
| 76 } | 78 } |
| 77 | 79 |
| 80 void NativeNotificationDisplayService::GetDisplayedAsync( |
| 81 const NotificationCommon::NotificationResultCallback& callback) const { |
| 82 return notification_bridge_->GetDisplayedAsync( |
| 83 GetProfileId(profile_), profile_->IsOffTheRecord(), callback); |
| 84 } |
| 85 |
| 78 void NativeNotificationDisplayService::ProcessNotificationOperation( | 86 void NativeNotificationDisplayService::ProcessNotificationOperation( |
| 79 NotificationCommon::Operation operation, | 87 NotificationCommon::Operation operation, |
| 80 NotificationCommon::Type notification_type, | 88 NotificationCommon::Type notification_type, |
| 81 const std::string& origin, | 89 const std::string& origin, |
| 82 const std::string& notification_id, | 90 const std::string& notification_id, |
| 83 int action_index, | 91 int action_index, |
| 84 const base::NullableString16& reply) { | 92 const base::NullableString16& reply) { |
| 85 NotificationHandler* handler = GetNotificationHandler(notification_type); | 93 NotificationHandler* handler = GetNotificationHandler(notification_type); |
| 86 CHECK(handler); | 94 CHECK(handler); |
| 87 switch (operation) { | 95 switch (operation) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 110 notification_handlers_.erase(notification_type); | 118 notification_handlers_.erase(notification_type); |
| 111 } | 119 } |
| 112 | 120 |
| 113 NotificationHandler* NativeNotificationDisplayService::GetNotificationHandler( | 121 NotificationHandler* NativeNotificationDisplayService::GetNotificationHandler( |
| 114 NotificationCommon::Type notification_type) { | 122 NotificationCommon::Type notification_type) { |
| 115 DCHECK(notification_handlers_.find(notification_type) != | 123 DCHECK(notification_handlers_.find(notification_type) != |
| 116 notification_handlers_.end()) | 124 notification_handlers_.end()) |
| 117 << notification_type << " is not registered."; | 125 << notification_type << " is not registered."; |
| 118 return notification_handlers_[notification_type].get(); | 126 return notification_handlers_[notification_type].get(); |
| 119 } | 127 } |
| OLD | NEW |