| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/shell/browser/layout_test/layout_test_notification_manager.h" | 5 #include "content/shell/browser/layout_test/layout_test_notification_manager.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "content/public/browser/browser_thread.h" | 8 #include "content/public/browser/browser_thread.h" |
| 9 #include "content/public/browser/desktop_notification_delegate.h" | 9 #include "content/public/browser/desktop_notification_delegate.h" |
| 10 #include "content/public/common/show_desktop_notification_params.h" | 10 #include "content/public/common/show_desktop_notification_params.h" |
| 11 | 11 |
| 12 namespace content { | 12 namespace content { |
| 13 | 13 |
| 14 LayoutTestNotificationManager::LayoutTestNotificationManager() | 14 LayoutTestNotificationManager::LayoutTestNotificationManager() |
| 15 : weak_factory_(this) {} | 15 : weak_factory_(this) {} |
| 16 | 16 |
| 17 LayoutTestNotificationManager::~LayoutTestNotificationManager() {} | 17 LayoutTestNotificationManager::~LayoutTestNotificationManager() {} |
| 18 | 18 |
| 19 blink::WebNotificationPermission | 19 blink::WebNotificationPermission |
| 20 LayoutTestNotificationManager::CheckPermission(const GURL& origin) { | 20 LayoutTestNotificationManager::CheckPermission(const GURL& origin) { |
| 21 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 21 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 22 NotificationPermissionMap::iterator iter = | 22 NotificationPermissionMap::iterator iter = |
| 23 permission_map_.find(origin); | 23 permission_map_.find(origin); |
| 24 if (iter == permission_map_.end()) | 24 if (iter == permission_map_.end()) |
| 25 return blink::WebNotificationPermissionDefault; | 25 return blink::WebNotificationPermissionDefault; |
| 26 | 26 |
| 27 return iter->second; | 27 return iter->second; |
| 28 } | 28 } |
| 29 | 29 |
| 30 void LayoutTestNotificationManager::RequestPermission( | 30 bool LayoutTestNotificationManager::RequestPermission(const GURL& origin) { |
| 31 const GURL& origin, | 31 return CheckPermission(origin) == blink::WebNotificationPermissionAllowed; |
| 32 const base::Callback<void(bool)>& callback) { | |
| 33 bool allowed = | |
| 34 CheckPermission(origin) == blink::WebNotificationPermissionAllowed; | |
| 35 callback.Run(allowed); | |
| 36 } | 32 } |
| 37 | 33 |
| 38 void LayoutTestNotificationManager::SetPermission( | 34 void LayoutTestNotificationManager::SetPermission( |
| 39 const GURL& origin, | 35 const GURL& origin, |
| 40 blink::WebNotificationPermission permission) { | 36 blink::WebNotificationPermission permission) { |
| 41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 37 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 42 permission_map_[origin] = permission; | 38 permission_map_[origin] = permission; |
| 43 } | 39 } |
| 44 | 40 |
| 45 void LayoutTestNotificationManager::ClearPermissions() { | 41 void LayoutTestNotificationManager::ClearPermissions() { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 void LayoutTestNotificationManager::Close(const std::string& title) { | 90 void LayoutTestNotificationManager::Close(const std::string& title) { |
| 95 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 91 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 96 auto iterator = notifications_.find(title); | 92 auto iterator = notifications_.find(title); |
| 97 if (iterator == notifications_.end()) | 93 if (iterator == notifications_.end()) |
| 98 return; | 94 return; |
| 99 | 95 |
| 100 iterator->second->NotificationClosed(false); | 96 iterator->second->NotificationClosed(false); |
| 101 } | 97 } |
| 102 | 98 |
| 103 } // namespace content | 99 } // namespace content |
| OLD | NEW |