15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This file describes a central switchboard for notifications that might 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// happen in various parts of the application, and allows users to register 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// observers for various classes of events that they're interested in. 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef CONTENT_PUBLIC_BROWSER_NOTIFICATION_SERVICE_H_ 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CONTENT_PUBLIC_BROWSER_NOTIFICATION_SERVICE_H_ 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/common/content_export.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_details.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_source.h" 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace content { 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class CONTENT_EXPORT NotificationService { 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the NotificationService object for the current thread, or NULL if 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // none. 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static NotificationService* current(); 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static NotificationService* Create(); 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~NotificationService() {} 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Synchronously posts a notification to all interested observers. 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Source is a reference to a NotificationSource object representing 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the object originating the notification (can be 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // NotificationService::AllSources(), in which case 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // only observers interested in all sources will be notified). 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Details is a reference to an object containing additional data about 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the notification. If no additional data is needed, NoDetails() is used. 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // There is no particular order in which the observers will be notified. 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void Notify(int type, 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const NotificationSource& source, 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const NotificationDetails& details) = 0; 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns a NotificationSource that represents all notification sources 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // (for the purpose of registering an observer for events from all sources). 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static Source<void> AllSources() { return Source<void>(NULL); } 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the same value as AllSources(). This function has semantic 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // differences to the programmer: We have checked that this AllSources() 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // usage is safe in the face of multiple profiles. Objects that were 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // singletons now will always have multiple instances, one per browser 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // context. 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Some usage is safe, where the Source is checked to see if it's a member of 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // a container before use. But, we want the number of AllSources() calls to 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // drop to almost nothing, because most usages are not multiprofile safe and 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // were done because it was easier to listen to everything. 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static Source<void> AllBrowserContextsAndSources() { 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return Source<void>(NULL); 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns a NotificationDetails object that represents a lack of details 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // associated with a notification. (This is effectively a null pointer.) 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static Details<void> NoDetails() { return Details<void>(NULL); } 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace content 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // CONTENT_PUBLIC_BROWSER_NOTIFICATION_SERVICE_H_ 66