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