Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 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 #include "chrome/browser/sync/sessions/sync_sessions_web_contents_router.h" | |
| 6 | |
| 7 #include "chrome/browser/history/history_service_factory.h" | |
| 8 #include "chrome/browser/profiles/profile.h" | |
| 9 #include "chrome/browser/ui/browser.h" | |
| 10 #include "chrome/browser/ui/browser_list.h" | |
| 11 #include "chrome/browser/ui/sync/tab_contents_synced_tab_delegate.h" | |
| 12 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
| 13 #include "components/history/core/browser/history_service.h" | |
| 14 #include "components/sync_sessions/synced_tab_delegate.h" | |
| 15 | |
| 16 namespace sync_sessions { | |
| 17 | |
| 18 SyncSessionsWebContentsRouter::SyncSessionsWebContentsRouter(Profile* profile) { | |
| 19 handler_ = nullptr; | |
|
Nicolas Zea
2017/03/16 19:57:43
can remove if you initialize in the header
Patrick Noland
2017/03/17 00:20:10
Done.
| |
| 20 | |
| 21 history::HistoryService* history_service = | |
| 22 HistoryServiceFactory::GetForProfile(profile, | |
| 23 ServiceAccessType::EXPLICIT_ACCESS); | |
| 24 if (history_service) { | |
| 25 favicon_changed_subscription_ = history_service->AddFaviconsChangedCallback( | |
| 26 base::Bind(&SyncSessionsWebContentsRouter::OnFaviconsChanged, | |
| 27 base::Unretained(this))); | |
| 28 } | |
| 29 // Android has no BrowserList or TabStripModel, so we exclude code that refers | |
|
Nicolas Zea
2017/03/16 19:57:43
nit: newline above
Patrick Noland
2017/03/17 00:20:10
Done.
| |
| 30 // to those two things. For non-android platforms, this code is used to | |
| 31 // ensure we are notified of tabs being added and moved between tab strips. | |
| 32 #if !defined(OS_ANDROID) | |
| 33 BrowserList* browser_list = BrowserList::GetInstance(); | |
| 34 for (Browser* browser : *browser_list) | |
| 35 browser->tab_strip_model()->AddObserver(this); | |
| 36 browser_list->AddObserver(this); | |
| 37 #endif // !defined(OS_ANDROID) | |
| 38 } | |
| 39 | |
| 40 SyncSessionsWebContentsRouter::~SyncSessionsWebContentsRouter() {} | |
| 41 | |
| 42 void SyncSessionsWebContentsRouter::NotifyTabModified( | |
| 43 content::WebContents* web_contents) { | |
| 44 if (handler_ && web_contents) { | |
| 45 SyncedTabDelegate* delegate = | |
| 46 TabContentsSyncedTabDelegate::FromWebContents(web_contents); | |
| 47 if (delegate) | |
| 48 handler_->OnLocalTabModified(delegate); | |
| 49 } | |
| 50 | |
| 51 if (!flare_.is_null()) { | |
| 52 flare_.Run(syncer::SESSIONS); | |
| 53 flare_.Reset(); | |
| 54 } | |
| 55 } | |
| 56 | |
| 57 void SyncSessionsWebContentsRouter::InjectStartSyncFlare( | |
| 58 syncer::SyncableService::StartSyncFlare flare) { | |
| 59 flare_ = flare; | |
| 60 } | |
| 61 | |
| 62 void SyncSessionsWebContentsRouter::StartRoutingTo( | |
| 63 LocalSessionEventHandler* handler) { | |
| 64 handler_ = handler; | |
| 65 } | |
| 66 | |
| 67 void SyncSessionsWebContentsRouter::Stop() { | |
| 68 handler_ = nullptr; | |
| 69 } | |
| 70 | |
| 71 void SyncSessionsWebContentsRouter::OnFaviconsChanged( | |
| 72 const std::set<GURL>& page_urls, | |
| 73 const GURL& icon_url) { | |
| 74 if (handler_) | |
| 75 handler_->OnFaviconsChanged(page_urls, icon_url); | |
| 76 } | |
| 77 | |
| 78 void SyncSessionsWebContentsRouter::Shutdown() { | |
| 79 favicon_changed_subscription_.reset(); | |
| 80 #if !defined(OS_ANDROID) | |
| 81 BrowserList* browser_list = BrowserList::GetInstance(); | |
| 82 for (Browser* browser : *browser_list) | |
| 83 browser->tab_strip_model()->RemoveObserver(this); | |
| 84 BrowserList::GetInstance()->RemoveObserver(this); | |
| 85 #endif | |
| 86 } | |
| 87 | |
| 88 #if !defined(OS_ANDROID) | |
| 89 void SyncSessionsWebContentsRouter::OnBrowserAdded(Browser* browser) { | |
| 90 browser->tab_strip_model()->AddObserver(this); | |
| 91 } | |
| 92 | |
| 93 void SyncSessionsWebContentsRouter::OnBrowserRemoved(Browser* browser) { | |
| 94 browser->tab_strip_model()->RemoveObserver(this); | |
| 95 } | |
| 96 | |
| 97 void SyncSessionsWebContentsRouter::TabInsertedAt( | |
| 98 TabStripModel* model, | |
| 99 content::WebContents* web_contents, | |
| 100 int index, | |
| 101 bool foreground) { | |
| 102 if (handler_ && web_contents) { | |
| 103 SyncedTabDelegate* delegate = | |
| 104 TabContentsSyncedTabDelegate::FromWebContents(web_contents); | |
| 105 if (delegate) | |
| 106 handler_->OnLocalTabModified(delegate); | |
| 107 } | |
| 108 } | |
| 109 #endif // !defined(OS_ANDROID) | |
| 110 | |
| 111 } // namespace sync_sessions | |
| OLD | NEW |