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

Side by Side Diff: chrome/browser/notifications/platform_notification_service_impl.cc

Issue 1509923002: Implement native web notifications for mac (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months 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 unified diff | Download patch
OLDNEW
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 "chrome/browser/notifications/platform_notification_service_impl.h" 5 #include "chrome/browser/notifications/platform_notification_service_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
11 #include "base/metrics/user_metrics_action.h" 11 #include "base/metrics/user_metrics_action.h"
12 #include "base/prefs/pref_service.h" 12 #include "base/prefs/pref_service.h"
13 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
14 #include "build/build_config.h" 15 #include "build/build_config.h"
15 #include "chrome/browser/browser_process.h" 16 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 17 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
17 #include "chrome/browser/notifications/desktop_notification_profile_util.h" 18 #include "chrome/browser/notifications/desktop_notification_profile_util.h"
18 #include "chrome/browser/notifications/notification_object_proxy.h" 19 #include "chrome/browser/notifications/notification_object_proxy.h"
19 #include "chrome/browser/notifications/notification_ui_manager.h" 20 #include "chrome/browser/notifications/notification_ui_manager.h"
20 #include "chrome/browser/notifications/persistent_notification_delegate.h" 21 #include "chrome/browser/notifications/persistent_notification_delegate.h"
21 #include "chrome/browser/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/profiles/profile_io_data.h" 23 #include "chrome/browser/profiles/profile_io_data.h"
(...skipping 24 matching lines...) Expand all
47 #if defined(ENABLE_EXTENSIONS) 48 #if defined(ENABLE_EXTENSIONS)
48 #include "chrome/browser/notifications/notifier_state_tracker.h" 49 #include "chrome/browser/notifications/notifier_state_tracker.h"
49 #include "chrome/browser/notifications/notifier_state_tracker_factory.h" 50 #include "chrome/browser/notifications/notifier_state_tracker_factory.h"
50 #include "extensions/browser/extension_registry.h" 51 #include "extensions/browser/extension_registry.h"
51 #include "extensions/browser/info_map.h" 52 #include "extensions/browser/info_map.h"
52 #include "extensions/common/constants.h" 53 #include "extensions/common/constants.h"
53 #include "extensions/common/permissions/api_permission.h" 54 #include "extensions/common/permissions/api_permission.h"
54 #include "extensions/common/permissions/permissions_data.h" 55 #include "extensions/common/permissions/permissions_data.h"
55 #endif 56 #endif
56 57
57 #if defined(OS_ANDROID)
58 #include "base/strings/string_number_conversions.h"
59 #endif
60
61 using content::BrowserContext; 58 using content::BrowserContext;
62 using content::BrowserThread; 59 using content::BrowserThread;
63 using content::PlatformNotificationContext; 60 using content::PlatformNotificationContext;
64 using message_center::NotifierId; 61 using message_center::NotifierId;
65 62
66 namespace { 63 namespace {
67 64
68 // Invalid id for a renderer process. Used in cases where we need to check for 65 // Invalid id for a renderer process. Used in cases where we need to check for
69 // permission without having an associated renderer process yet. 66 // permission without having an associated renderer process yet.
70 const int kInvalidRenderProcessId = -1; 67 const int kInvalidRenderProcessId = -1;
(...skipping 21 matching lines...) Expand all
92 89
93 } // namespace 90 } // namespace
94 91
95 // static 92 // static
96 PlatformNotificationServiceImpl* 93 PlatformNotificationServiceImpl*
97 PlatformNotificationServiceImpl::GetInstance() { 94 PlatformNotificationServiceImpl::GetInstance() {
98 return base::Singleton<PlatformNotificationServiceImpl>::get(); 95 return base::Singleton<PlatformNotificationServiceImpl>::get();
99 } 96 }
100 97
101 PlatformNotificationServiceImpl::PlatformNotificationServiceImpl() 98 PlatformNotificationServiceImpl::PlatformNotificationServiceImpl()
102 : notification_ui_manager_for_tests_(nullptr) {} 99 : native_notification_ui_manager_(
100 NotificationUIManager::CreateNativeNotificationManager()),
101 notification_ui_manager_for_tests_(nullptr) {}
103 102
104 PlatformNotificationServiceImpl::~PlatformNotificationServiceImpl() {} 103 PlatformNotificationServiceImpl::~PlatformNotificationServiceImpl() {}
105 104
106 void PlatformNotificationServiceImpl::OnPersistentNotificationClick( 105 void PlatformNotificationServiceImpl::OnPersistentNotificationClick(
107 BrowserContext* browser_context, 106 BrowserContext* browser_context,
108 int64_t persistent_notification_id, 107 int64_t persistent_notification_id,
109 const GURL& origin, 108 const GURL& origin,
110 int action_index) { 109 int action_index) {
111 DCHECK_CURRENTLY_ON(BrowserThread::UI); 110 DCHECK_CURRENTLY_ON(BrowserThread::UI);
112 blink::WebNotificationPermission permission = 111 blink::WebNotificationPermission permission =
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 326
328 void PlatformNotificationServiceImpl::ClosePersistentNotification( 327 void PlatformNotificationServiceImpl::ClosePersistentNotification(
329 BrowserContext* browser_context, 328 BrowserContext* browser_context,
330 int64_t persistent_notification_id) { 329 int64_t persistent_notification_id) {
331 DCHECK_CURRENTLY_ON(BrowserThread::UI); 330 DCHECK_CURRENTLY_ON(BrowserThread::UI);
332 331
333 Profile* profile = Profile::FromBrowserContext(browser_context); 332 Profile* profile = Profile::FromBrowserContext(browser_context);
334 DCHECK(profile); 333 DCHECK(profile);
335 334
336 #if defined(OS_ANDROID) 335 #if defined(OS_ANDROID)
337 // TODO(peter): Remove this conversion when the notification ids are being 336 bool cancel_by_persistent_id = true;
338 // generated by the caller of this method.
339 std::string textual_persistent_notification_id =
340 base::Int64ToString(persistent_notification_id);
341 GetNotificationUIManager()->CancelById(
342 textual_persistent_notification_id,
343 NotificationUIManager::GetProfileID(profile));
344 #else 337 #else
338 bool cancel_by_persistent_id = (native_notification_ui_manager_ != nullptr);
339 #endif
340
341 if (cancel_by_persistent_id) {
342 // TODO(peter): Remove this conversion when the notification ids are being
343 // generated by the caller of this method.
344 GetNotificationUIManager()->CancelById(
345 base::Int64ToString(persistent_notification_id),
346 NotificationUIManager::GetProfileID(profile));
347 }
348
345 auto iter = persistent_notifications_.find(persistent_notification_id); 349 auto iter = persistent_notifications_.find(persistent_notification_id);
346 if (iter == persistent_notifications_.end()) 350 if (iter == persistent_notifications_.end())
347 return; 351 return;
348 352
349 GetNotificationUIManager()->CancelById( 353 GetNotificationUIManager()->CancelById(
350 iter->second, NotificationUIManager::GetProfileID(profile)); 354 iter->second, NotificationUIManager::GetProfileID(profile));
351 355
352 persistent_notifications_.erase(iter); 356 persistent_notifications_.erase(iter);
353 #endif
354 } 357 }
355 358
356 bool PlatformNotificationServiceImpl::GetDisplayedPersistentNotifications( 359 bool PlatformNotificationServiceImpl::GetDisplayedPersistentNotifications(
357 BrowserContext* browser_context, 360 BrowserContext* browser_context,
358 std::set<std::string>* displayed_notifications) { 361 std::set<std::string>* displayed_notifications) {
359 DCHECK(displayed_notifications); 362 DCHECK(displayed_notifications);
360 363
361 #if !defined(OS_ANDROID) 364 #if !defined(OS_ANDROID)
362 Profile* profile = Profile::FromBrowserContext(browser_context); 365 Profile* profile = Profile::FromBrowserContext(browser_context);
363 if (!profile || profile->AsTestingProfile()) 366 if (!profile || profile->AsTestingProfile())
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 notification.set_never_timeout(true); 422 notification.set_never_timeout(true);
420 423
421 return notification; 424 return notification;
422 } 425 }
423 426
424 NotificationUIManager* 427 NotificationUIManager*
425 PlatformNotificationServiceImpl::GetNotificationUIManager() const { 428 PlatformNotificationServiceImpl::GetNotificationUIManager() const {
426 if (notification_ui_manager_for_tests_) 429 if (notification_ui_manager_for_tests_)
427 return notification_ui_manager_for_tests_; 430 return notification_ui_manager_for_tests_;
428 431
432 if (native_notification_ui_manager_) {
433 return native_notification_ui_manager_.get();
434 }
435
429 return g_browser_process->notification_ui_manager(); 436 return g_browser_process->notification_ui_manager();
430 } 437 }
431 438
432 void PlatformNotificationServiceImpl::OpenNotificationSettings( 439 void PlatformNotificationServiceImpl::OpenNotificationSettings(
433 BrowserContext* browser_context) { 440 BrowserContext* browser_context) {
434 #if defined(OS_ANDROID) 441 #if defined(OS_ANDROID)
435 NOTIMPLEMENTED(); 442 NOTIMPLEMENTED();
436 #else 443 #else
437 444
438 Profile* profile = Profile::FromBrowserContext(browser_context); 445 Profile* profile = Profile::FromBrowserContext(browser_context);
(...skipping 27 matching lines...) Expand all
466 extensions::ExtensionRegistry::Get(profile)->GetExtensionById( 473 extensions::ExtensionRegistry::Get(profile)->GetExtensionById(
467 origin.host(), extensions::ExtensionRegistry::EVERYTHING); 474 origin.host(), extensions::ExtensionRegistry::EVERYTHING);
468 DCHECK(extension); 475 DCHECK(extension);
469 476
470 return base::UTF8ToUTF16(extension->name()); 477 return base::UTF8ToUTF16(extension->name());
471 } 478 }
472 #endif 479 #endif
473 480
474 return base::string16(); 481 return base::string16();
475 } 482 }
OLDNEW
« no previous file with comments | « chrome/browser/notifications/platform_notification_service_impl.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698