| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/notification_permission_context.h" | 5 #include "chrome/browser/notifications/notification_permission_context.h" |
| 6 | 6 |
| 7 #include <algorithm> | |
| 8 #include <deque> | 7 #include <deque> |
| 9 | 8 |
| 10 #include "base/callback.h" | 9 #include "base/callback.h" |
| 11 #include "base/location.h" | 10 #include "base/location.h" |
| 12 #include "base/rand_util.h" | 11 #include "base/rand_util.h" |
| 13 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/stl_util.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
| 15 #include "base/timer/timer.h" | 15 #include "base/timer/timer.h" |
| 16 #include "chrome/browser/notifications/desktop_notification_profile_util.h" | 16 #include "chrome/browser/notifications/desktop_notification_profile_util.h" |
| 17 #include "chrome/browser/permissions/permission_request_id.h" | 17 #include "chrome/browser/permissions/permission_request_id.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 19 #include "components/content_settings/core/common/content_settings_pattern.h" | 19 #include "components/content_settings/core/common/content_settings_pattern.h" |
| 20 #include "components/content_settings/core/common/content_settings_types.h" | 20 #include "components/content_settings/core/common/content_settings_types.h" |
| 21 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 22 #include "content/public/browser/render_frame_host.h" | 22 #include "content/public/browser/render_frame_host.h" |
| 23 #include "content/public/browser/web_contents_observer.h" | 23 #include "content/public/browser/web_contents_observer.h" |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 | 115 |
| 116 task_queue_.emplace_back(id, std::move(timer)); | 116 task_queue_.emplace_back(id, std::move(timer)); |
| 117 | 117 |
| 118 if (is_visible_ && task_queue_.size() == 1) | 118 if (is_visible_ && task_queue_.size() == 1) |
| 119 task_queue_.front().timer->Reset(); | 119 task_queue_.front().timer->Reset(); |
| 120 } | 120 } |
| 121 | 121 |
| 122 void VisibilityTimerTabHelper::CancelTask(const PermissionRequestID& id) { | 122 void VisibilityTimerTabHelper::CancelTask(const PermissionRequestID& id) { |
| 123 bool deleting_front = task_queue_.front().id == id; | 123 bool deleting_front = task_queue_.front().id == id; |
| 124 | 124 |
| 125 task_queue_.erase( | 125 base::EraseIf(task_queue_, [id](const Task& task) { return task.id == id; }); |
| 126 std::remove_if(task_queue_.begin(), task_queue_.end(), | |
| 127 [id](const Task& task) { return task.id == id; }), | |
| 128 task_queue_.end()); | |
| 129 | 126 |
| 130 if (!task_queue_.empty() && is_visible_ && deleting_front) | 127 if (!task_queue_.empty() && is_visible_ && deleting_front) |
| 131 task_queue_.front().timer->Reset(); | 128 task_queue_.front().timer->Reset(); |
| 132 } | 129 } |
| 133 | 130 |
| 134 void VisibilityTimerTabHelper::WasShown() { | 131 void VisibilityTimerTabHelper::WasShown() { |
| 135 if (!is_visible_ && !task_queue_.empty()) | 132 if (!is_visible_ && !task_queue_.empty()) |
| 136 task_queue_.front().timer->Reset(); | 133 task_queue_.front().timer->Reset(); |
| 137 is_visible_ = true; | 134 is_visible_ = true; |
| 138 } | 135 } |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 requesting_origin); | 250 requesting_origin); |
| 254 } else { | 251 } else { |
| 255 DesktopNotificationProfileUtil::DenyPermission(profile(), | 252 DesktopNotificationProfileUtil::DenyPermission(profile(), |
| 256 requesting_origin); | 253 requesting_origin); |
| 257 } | 254 } |
| 258 } | 255 } |
| 259 | 256 |
| 260 bool NotificationPermissionContext::IsRestrictedToSecureOrigins() const { | 257 bool NotificationPermissionContext::IsRestrictedToSecureOrigins() const { |
| 261 return content_settings_type() == CONTENT_SETTINGS_TYPE_PUSH_MESSAGING; | 258 return content_settings_type() == CONTENT_SETTINGS_TYPE_PUSH_MESSAGING; |
| 262 } | 259 } |
| OLD | NEW |