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/sync/tab_contents_synced_tab_delegate.h" |
| 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 11 #include "components/history/core/browser/history_service.h" |
| 12 #include "components/sync_sessions/synced_tab_delegate.h" |
| 13 |
| 14 namespace sync_sessions { |
| 15 |
| 16 SyncSessionsWebContentsRouter::SyncSessionsWebContentsRouter(Profile* profile) { |
| 17 history::HistoryService* history_service = |
| 18 HistoryServiceFactory::GetForProfile(profile, |
| 19 ServiceAccessType::EXPLICIT_ACCESS); |
| 20 if (history_service) { |
| 21 favicon_changed_subscription_ = history_service->AddFaviconsChangedCallback( |
| 22 base::Bind(&SyncSessionsWebContentsRouter::OnFaviconsChanged, |
| 23 base::Unretained(this))); |
| 24 } |
| 25 } |
| 26 |
| 27 SyncSessionsWebContentsRouter::~SyncSessionsWebContentsRouter() {} |
| 28 |
| 29 void SyncSessionsWebContentsRouter::NotifyTabModified( |
| 30 content::WebContents* web_contents) { |
| 31 if (handler_ && web_contents) { |
| 32 SyncedTabDelegate* delegate = |
| 33 TabContentsSyncedTabDelegate::FromWebContents(web_contents); |
| 34 if (delegate) |
| 35 handler_->OnLocalTabModified(delegate); |
| 36 } |
| 37 |
| 38 if (!flare_.is_null()) { |
| 39 flare_.Run(syncer::SESSIONS); |
| 40 flare_.Reset(); |
| 41 } |
| 42 } |
| 43 |
| 44 void SyncSessionsWebContentsRouter::InjectStartSyncFlare( |
| 45 syncer::SyncableService::StartSyncFlare flare) { |
| 46 flare_ = flare; |
| 47 } |
| 48 |
| 49 void SyncSessionsWebContentsRouter::StartRoutingTo( |
| 50 LocalSessionEventHandler* handler) { |
| 51 handler_ = handler; |
| 52 } |
| 53 |
| 54 void SyncSessionsWebContentsRouter::Stop() { |
| 55 handler_ = nullptr; |
| 56 } |
| 57 |
| 58 void SyncSessionsWebContentsRouter::OnFaviconsChanged( |
| 59 const std::set<GURL>& page_urls, |
| 60 const GURL& icon_url) { |
| 61 if (handler_) |
| 62 handler_->OnFaviconsChanged(page_urls, icon_url); |
| 63 } |
| 64 |
| 65 void SyncSessionsWebContentsRouter::Shutdown() { |
| 66 favicon_changed_subscription_.reset(); |
| 67 } |
| 68 |
| 69 } // namespace sync_sessions |
OLD | NEW |