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