1 // Copyright 2013 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.
5 #include "chrome/browser/sync/glue/synced_tab_delegate_android.h"
7 #include "base/memory/ref_counted.h"
8 #include "chrome/browser/android/tab_android.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/sync/glue/synced_window_delegate.h"
11 #include "chrome/browser/sync/glue/synced_window_delegates_getter_android.h"
12 #include "chrome/browser/ui/sync/tab_contents_synced_tab_delegate.h"
13 #include "content/public/browser/navigation_entry.h"
14 #include "content/public/browser/web_contents.h"
16 using content::NavigationEntry
;
18 namespace browser_sync
{
19 SyncedTabDelegateAndroid::SyncedTabDelegateAndroid(TabAndroid
* tab_android
)
20 : web_contents_(nullptr),
21 tab_android_(tab_android
),
22 tab_contents_delegate_(nullptr) {
23 SetSyncedWindowGetter(
24 make_scoped_ptr(new SyncedWindowDelegatesGetterAndroid()));
27 SyncedTabDelegateAndroid::~SyncedTabDelegateAndroid() {}
29 SessionID::id_type
SyncedTabDelegateAndroid::GetWindowId() const {
30 return tab_contents_delegate_
->GetWindowId();
33 SessionID::id_type
SyncedTabDelegateAndroid::GetSessionId() const {
34 return tab_android_
->session_id().id();
37 bool SyncedTabDelegateAndroid::IsBeingDestroyed() const {
38 return tab_contents_delegate_
->IsBeingDestroyed();
41 Profile
* SyncedTabDelegateAndroid::profile() const {
42 return tab_contents_delegate_
->profile();
45 std::string
SyncedTabDelegateAndroid::GetExtensionAppId() const {
46 return tab_contents_delegate_
->GetExtensionAppId();
49 int SyncedTabDelegateAndroid::GetCurrentEntryIndex() const {
50 return tab_contents_delegate_
->GetCurrentEntryIndex();
53 int SyncedTabDelegateAndroid::GetEntryCount() const {
54 return tab_contents_delegate_
->GetEntryCount();
57 int SyncedTabDelegateAndroid::GetPendingEntryIndex() const {
58 return tab_contents_delegate_
->GetPendingEntryIndex();
61 NavigationEntry
* SyncedTabDelegateAndroid::GetPendingEntry() const {
62 return tab_contents_delegate_
->GetPendingEntry();
65 NavigationEntry
* SyncedTabDelegateAndroid::GetEntryAtIndex(int i
) const {
66 return tab_contents_delegate_
->GetEntryAtIndex(i
);
69 NavigationEntry
* SyncedTabDelegateAndroid::GetActiveEntry() const {
70 return tab_contents_delegate_
->GetActiveEntry();
73 bool SyncedTabDelegateAndroid::IsPinned() const {
74 return tab_contents_delegate_
->IsPinned();
77 bool SyncedTabDelegateAndroid::HasWebContents() const {
78 return web_contents_
!= NULL
;
81 content::WebContents
* SyncedTabDelegateAndroid::GetWebContents() const {
85 void SyncedTabDelegateAndroid::SetWebContents(
86 content::WebContents
* web_contents
) {
87 web_contents_
= web_contents
;
88 TabContentsSyncedTabDelegate::CreateForWebContents(web_contents_
);
89 // Store the TabContentsSyncedTabDelegate object that was created.
90 tab_contents_delegate_
=
91 TabContentsSyncedTabDelegate::FromWebContents(web_contents_
);
92 // Tell it how to get SyncedWindowDelegates or some calls will fail.
93 tab_contents_delegate_
->SetSyncedWindowGetter(
94 make_scoped_ptr(new SyncedWindowDelegatesGetterAndroid()));
97 void SyncedTabDelegateAndroid::ResetWebContents() { web_contents_
= NULL
; }
99 bool SyncedTabDelegateAndroid::ProfileIsSupervised() const {
100 return tab_contents_delegate_
->ProfileIsSupervised();
103 const std::vector
<const content::NavigationEntry
*>*
104 SyncedTabDelegateAndroid::GetBlockedNavigations() const {
105 return tab_contents_delegate_
->GetBlockedNavigations();
108 int SyncedTabDelegateAndroid::GetSyncId() const {
109 return tab_android_
->GetSyncId();
112 void SyncedTabDelegateAndroid::SetSyncId(int sync_id
) {
113 tab_android_
->SetSyncId(sync_id
);
117 SyncedTabDelegate
* SyncedTabDelegate::ImplFromWebContents(
118 content::WebContents
* web_contents
) {
119 TabAndroid
* tab
= TabAndroid::FromWebContents(web_contents
);
120 return tab
? tab
->GetSyncedTabDelegate() : nullptr;
123 } // namespace browser_sync