| 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 "chrome/browser/sync/sessions/notification_service_sessions_router.h" | 5 #include "chrome/browser/sync/sessions/notification_service_sessions_router.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
| 9 #include "chrome/browser/history/history_service_factory.h" | 9 #include "chrome/browser/history/history_service_factory.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/sync/glue/sync_start_util.h" | 11 #include "chrome/browser/sync/glue/sync_start_util.h" |
| 12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/browser_finder.h" |
| 13 #include "chrome/browser/ui/sync/browser_synced_window_delegates_getter.h" | 14 #include "chrome/browser/ui/sync/browser_synced_window_delegates_getter.h" |
| 14 #include "chrome/browser/ui/sync/tab_contents_synced_tab_delegate.h" | 15 #include "chrome/browser/ui/sync/tab_contents_synced_tab_delegate.h" |
| 15 #include "chrome/common/features.h" | 16 #include "chrome/common/features.h" |
| 16 #include "components/history/core/browser/history_service.h" | 17 #include "components/history/core/browser/history_service.h" |
| 17 #include "components/sync_sessions/sync_sessions_client.h" | 18 #include "components/sync_sessions/sync_sessions_client.h" |
| 18 #include "components/sync_sessions/synced_tab_delegate.h" | 19 #include "components/sync_sessions/synced_tab_delegate.h" |
| 19 #include "content/public/browser/navigation_controller.h" | 20 #include "content/public/browser/navigation_controller.h" |
| 20 #include "content/public/browser/navigation_entry.h" | 21 #include "content/public/browser/navigation_entry.h" |
| 21 #include "content/public/browser/notification_details.h" | 22 #include "content/public/browser/notification_details.h" |
| 22 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 registrar_.Add(this, chrome::NOTIFICATION_TAB_PARENTED, | 71 registrar_.Add(this, chrome::NOTIFICATION_TAB_PARENTED, |
| 71 content::NotificationService::AllSources()); | 72 content::NotificationService::AllSources()); |
| 72 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 73 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 73 content::NotificationService::AllSources()); | 74 content::NotificationService::AllSources()); |
| 74 registrar_.Add(this, content::NOTIFICATION_NAV_LIST_PRUNED, | 75 registrar_.Add(this, content::NOTIFICATION_NAV_LIST_PRUNED, |
| 75 content::NotificationService::AllSources()); | 76 content::NotificationService::AllSources()); |
| 76 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_CHANGED, | 77 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_CHANGED, |
| 77 content::NotificationService::AllSources()); | 78 content::NotificationService::AllSources()); |
| 78 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 79 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 79 content::NotificationService::AllSources()); | 80 content::NotificationService::AllSources()); |
| 81 registrar_.Add(this, chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST, |
| 82 content::NotificationService::AllBrowserContextsAndSources()); |
| 83 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, |
| 84 content::NotificationService::AllBrowserContextsAndSources()); |
| 85 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_CLOSING, |
| 86 content::NotificationService::AllSources()); |
| 87 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_OPENED, |
| 88 content::NotificationService::AllSources()); |
| 80 #if BUILDFLAG(ENABLE_EXTENSIONS) | 89 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 81 registrar_.Add(this, | 90 registrar_.Add(this, |
| 82 chrome::NOTIFICATION_TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED, | 91 chrome::NOTIFICATION_TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED, |
| 83 content::NotificationService::AllSources()); | 92 content::NotificationService::AllSources()); |
| 84 #endif | 93 #endif |
| 85 registrar_.Add(this, | 94 registrar_.Add(this, |
| 86 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 95 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| 87 content::NotificationService::AllBrowserContextsAndSources()); | 96 content::NotificationService::AllBrowserContextsAndSources()); |
| 88 history::HistoryService* history_service = | 97 history::HistoryService* history_service = |
| 89 HistoryServiceFactory::GetForProfile(profile, | 98 HistoryServiceFactory::GetForProfile(profile, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 SyncedTabDelegate* tab = | 131 SyncedTabDelegate* tab = |
| 123 GetSyncedTabDelegateFromWebContents(web_contents); | 132 GetSyncedTabDelegateFromWebContents(web_contents); |
| 124 if (!tab) | 133 if (!tab) |
| 125 return; | 134 return; |
| 126 if (handler_) | 135 if (handler_) |
| 127 handler_->OnLocalTabModified(tab); | 136 handler_->OnLocalTabModified(tab); |
| 128 if (!tab->ShouldSync(sessions_client_)) | 137 if (!tab->ShouldSync(sessions_client_)) |
| 129 return; | 138 return; |
| 130 break; | 139 break; |
| 131 } | 140 } |
| 141 case chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST: { |
| 142 if (handler_) |
| 143 handler_->SetAllBrowsersClosing(true); |
| 144 break; |
| 145 } |
| 146 #if !defined(OS_IOS) |
| 147 case chrome::NOTIFICATION_BROWSER_CLOSING: { |
| 148 Browser* browser = content::Source<Browser>(source).ptr(); |
| 149 if (!browser || browser->profile() != profile_) |
| 150 return; |
| 151 if (handler_ && chrome::GetBrowserCount(profile_) == 1U) { |
| 152 handler_->SetAllBrowsersClosing(true); |
| 153 } |
| 154 break; |
| 155 } |
| 156 #endif // !defined(OS_IOS) |
| 157 case chrome::NOTIFICATION_BROWSER_OPENED: |
| 158 case chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED: { |
| 159 if (handler_) |
| 160 handler_->SetAllBrowsersClosing(false); |
| 161 break; |
| 162 } |
| 132 // Source<NavigationController>. | 163 // Source<NavigationController>. |
| 133 case content::NOTIFICATION_NAV_LIST_PRUNED: | 164 case content::NOTIFICATION_NAV_LIST_PRUNED: |
| 134 case content::NOTIFICATION_NAV_ENTRY_CHANGED: | 165 case content::NOTIFICATION_NAV_ENTRY_CHANGED: |
| 135 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: { | 166 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: { |
| 136 WebContents* web_contents = | 167 WebContents* web_contents = |
| 137 content::Source<NavigationController>(source).ptr()->GetWebContents(); | 168 content::Source<NavigationController>(source).ptr()->GetWebContents(); |
| 138 if (Profile::FromBrowserContext(web_contents->GetBrowserContext()) != | 169 if (Profile::FromBrowserContext(web_contents->GetBrowserContext()) != |
| 139 profile_) | 170 profile_) |
| 140 return; | 171 return; |
| 141 SyncedTabDelegate* tab = | 172 SyncedTabDelegate* tab = |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 DCHECK(!handler_); | 236 DCHECK(!handler_); |
| 206 handler_ = handler; | 237 handler_ = handler; |
| 207 } | 238 } |
| 208 | 239 |
| 209 void NotificationServiceSessionsRouter::Stop() { | 240 void NotificationServiceSessionsRouter::Stop() { |
| 210 weak_ptr_factory_.InvalidateWeakPtrs(); | 241 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 211 handler_ = nullptr; | 242 handler_ = nullptr; |
| 212 } | 243 } |
| 213 | 244 |
| 214 } // namespace sync_sessions | 245 } // namespace sync_sessions |
| OLD | NEW |