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 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_SYNC_SESSIONS_NOTIFICATION_SERVICE_SESSIONS_ROUTER_H_ 6 #define CHROME_BROWSER_SYNC_SESSIONS_NOTIFICATION_SERVICE_SESSIONS_ROUTER_H_ 7 8 #include "base/memory/weak_ptr.h" 9 #include "chrome/browser/sync/sessions/sessions_sync_manager.h" 10 #include "content/public/browser/notification_observer.h" 11 #include "content/public/browser/notification_registrar.h" 12 13 class Profile; 14 15 namespace content { 16 class WebContents; 17 } 18 19 namespace browser_sync { 20 21 // A SessionsSyncManager::LocalEventRouter that drives session sync via 22 // the NotificationService. 23 class NotificationServiceSessionsRouter 24 : public LocalSessionEventRouter, 25 public content::NotificationObserver { 26 public: 27 NotificationServiceSessionsRouter( 28 Profile* profile, 29 const syncer::SyncableService::StartSyncFlare& flare); 30 virtual ~NotificationServiceSessionsRouter(); 31 32 // content::NotificationObserver implementation. 33 // BrowserSessionProvider -> sync API model change application. 34 virtual void Observe(int type, 35 const content::NotificationSource& source, 36 const content::NotificationDetails& details) OVERRIDE; 37 38 // SessionsSyncManager::LocalEventRouter implementation. 39 virtual void StartRoutingTo(LocalSessionEventHandler* handler) OVERRIDE; 40 virtual void Stop() OVERRIDE; 41 42 private: 43 // Called when the URL visited in |web_contents| was blocked by the 44 // ManagedUserService. We forward this on to our handler_ via the 45 // normal OnLocalTabModified, but pass through here via a WeakPtr 46 // callback from ManagedUserService and to extract the tab delegate 47 // from WebContents. 48 void OnNavigationBlocked(content::WebContents* web_contents); 49 50 LocalSessionEventHandler* handler_; 51 content::NotificationRegistrar registrar_; 52 Profile* const profile_; 53 syncer::SyncableService::StartSyncFlare flare_; 54 base::WeakPtrFactory<NotificationServiceSessionsRouter> weak_ptr_factory_; 55 56 DISALLOW_COPY_AND_ASSIGN(NotificationServiceSessionsRouter); 57 }; 58 59 } // namespace browser_sync 60 61 #endif // CHROME_BROWSER_SYNC_SESSIONS_NOTIFICATION_SERVICE_SESSIONS_ROUTER_H_ 62