| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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/sync_sessions_web_contents_router.h" | 5 #include "chrome/browser/sync/sessions/sync_sessions_web_contents_router.h" |
| 6 | 6 |
| 7 #include "chrome/browser/history/history_service_factory.h" | 7 #include "chrome/browser/history/history_service_factory.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #if !defined(OS_ANDROID) | 9 #if !defined(OS_ANDROID) |
| 10 #include "chrome/browser/sync/sessions/browser_list_router_helper.h" | 10 #include "chrome/browser/sync/sessions/browser_list_router_helper.h" |
| 11 #else |
| 12 #include "chrome/browser/android/tab_android.h" |
| 11 #endif // !defined(OS_ANDROID) | 13 #endif // !defined(OS_ANDROID) |
| 12 #include "chrome/browser/ui/sync/tab_contents_synced_tab_delegate.h" | 14 #include "chrome/browser/ui/sync/tab_contents_synced_tab_delegate.h" |
| 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 14 #include "components/history/core/browser/history_service.h" | 16 #include "components/history/core/browser/history_service.h" |
| 15 #include "components/sync_sessions/synced_tab_delegate.h" | 17 #include "components/sync_sessions/synced_tab_delegate.h" |
| 16 | 18 |
| 17 namespace sync_sessions { | 19 namespace sync_sessions { |
| 18 | 20 |
| 21 namespace { |
| 22 |
| 23 SyncedTabDelegate* GetSyncedTabDelegateFromWebContents( |
| 24 content::WebContents* web_contents) { |
| 25 #if defined(OS_ANDROID) |
| 26 TabAndroid* tab = TabAndroid::FromWebContents(web_contents); |
| 27 return tab ? tab->GetSyncedTabDelegate() : nullptr; |
| 28 #else |
| 29 SyncedTabDelegate* delegate = |
| 30 TabContentsSyncedTabDelegate::FromWebContents(web_contents); |
| 31 return delegate; |
| 32 #endif |
| 33 } |
| 34 |
| 35 } // namespace |
| 36 |
| 19 SyncSessionsWebContentsRouter::SyncSessionsWebContentsRouter(Profile* profile) { | 37 SyncSessionsWebContentsRouter::SyncSessionsWebContentsRouter(Profile* profile) { |
| 20 history::HistoryService* history_service = | 38 history::HistoryService* history_service = |
| 21 HistoryServiceFactory::GetForProfile(profile, | 39 HistoryServiceFactory::GetForProfile(profile, |
| 22 ServiceAccessType::EXPLICIT_ACCESS); | 40 ServiceAccessType::EXPLICIT_ACCESS); |
| 23 if (history_service) { | 41 if (history_service) { |
| 24 favicon_changed_subscription_ = history_service->AddFaviconsChangedCallback( | 42 favicon_changed_subscription_ = history_service->AddFaviconsChangedCallback( |
| 25 base::Bind(&SyncSessionsWebContentsRouter::OnFaviconsChanged, | 43 base::Bind(&SyncSessionsWebContentsRouter::OnFaviconsChanged, |
| 26 base::Unretained(this))); | 44 base::Unretained(this))); |
| 27 } | 45 } |
| 28 | 46 |
| 29 #if !defined(OS_ANDROID) | 47 #if !defined(OS_ANDROID) |
| 30 browser_list_helper_ = base::MakeUnique<BrowserListRouterHelper>(this); | 48 browser_list_helper_ = base::MakeUnique<BrowserListRouterHelper>(this); |
| 31 #endif // !defined(OS_ANDROID) | 49 #endif // !defined(OS_ANDROID) |
| 32 } | 50 } |
| 33 | 51 |
| 34 SyncSessionsWebContentsRouter::~SyncSessionsWebContentsRouter() {} | 52 SyncSessionsWebContentsRouter::~SyncSessionsWebContentsRouter() {} |
| 35 | 53 |
| 36 void SyncSessionsWebContentsRouter::NotifyTabModified( | 54 void SyncSessionsWebContentsRouter::NotifyTabModified( |
| 37 content::WebContents* web_contents) { | 55 content::WebContents* web_contents) { |
| 38 if (handler_ && web_contents) { | 56 if (handler_ && web_contents) { |
| 39 SyncedTabDelegate* delegate = | 57 SyncedTabDelegate* delegate = |
| 40 TabContentsSyncedTabDelegate::FromWebContents(web_contents); | 58 GetSyncedTabDelegateFromWebContents(web_contents); |
| 41 if (delegate) | 59 if (delegate) |
| 42 handler_->OnLocalTabModified(delegate); | 60 handler_->OnLocalTabModified(delegate); |
| 43 } | 61 } |
| 44 | 62 |
| 45 if (!flare_.is_null()) { | 63 if (!flare_.is_null()) { |
| 46 flare_.Run(syncer::SESSIONS); | 64 flare_.Run(syncer::SESSIONS); |
| 47 flare_.Reset(); | 65 flare_.Reset(); |
| 48 } | 66 } |
| 49 } | 67 } |
| 50 | 68 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 71 | 89 |
| 72 void SyncSessionsWebContentsRouter::Shutdown() { | 90 void SyncSessionsWebContentsRouter::Shutdown() { |
| 73 favicon_changed_subscription_.reset(); | 91 favicon_changed_subscription_.reset(); |
| 74 | 92 |
| 75 #if !defined(OS_ANDROID) | 93 #if !defined(OS_ANDROID) |
| 76 browser_list_helper_.reset(); | 94 browser_list_helper_.reset(); |
| 77 #endif // !defined(OS_ANDROID) | 95 #endif // !defined(OS_ANDROID) |
| 78 } | 96 } |
| 79 | 97 |
| 80 } // namespace sync_sessions | 98 } // namespace sync_sessions |
| OLD | NEW |