Update mojo surfaces bindings and mojo/cc/ glue
[chromium-blink-merge.git] / chrome / browser / notifications / sync_notifier / chrome_notifier_service.cc
blobc85fa07830561974947023c5edc27c1cc08db21c
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // The ChromeNotifierService works together with sync to maintain the state of
6 // user notifications, which can then be presented in the notification center,
7 // via the Notification UI Manager.
9 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h"
11 #include "chrome/browser/chrome_notification_types.h"
12 #include "chrome/browser/extensions/api/synced_notifications_private/synced_notifications_shim.h"
13 #include "chrome/browser/profiles/profile.h"
14 #include "content/public/browser/notification_service.h"
15 #include "extensions/browser/event_router.h"
17 namespace notifier {
19 ChromeNotifierService::ChromeNotifierService(Profile* profile)
20 : profile_(profile),
21 weak_ptr_factory_(this) {
22 synced_notifications_shim_.reset(new SyncedNotificationsShim(
23 base::Bind(&ChromeNotifierService::FireSyncJSEvent,
24 weak_ptr_factory_.GetWeakPtr()),
25 base::Bind(&ChromeNotifierService::NotifyRefreshNeeded,
26 weak_ptr_factory_.GetWeakPtr())));
29 ChromeNotifierService::~ChromeNotifierService() {
32 // Methods from KeyedService.
33 void ChromeNotifierService::Shutdown() {}
35 SyncedNotificationsShim* ChromeNotifierService::GetSyncedNotificationsShim() {
36 return synced_notifications_shim_.get();
39 void ChromeNotifierService::FireSyncJSEvent(
40 scoped_ptr<extensions::Event> event) {
41 event->restrict_to_browser_context = profile_;
42 // TODO(synced notifications): consider broadcasting to a specific extension
43 // id.
44 extensions::EventRouter::Get(profile_)->BroadcastEvent(event.Pass());
47 void ChromeNotifierService::NotifyRefreshNeeded() {
48 const syncer::ModelTypeSet types(syncer::SYNCED_NOTIFICATIONS);
49 content::NotificationService::current()->Notify(
50 chrome::NOTIFICATION_SYNC_REFRESH_LOCAL,
51 content::Source<Profile>(profile_),
52 content::Details<const syncer::ModelTypeSet>(&types));
55 } // namespace notifier