OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/glue/synced_tab_delegate_android.h" | 5 #include "chrome/browser/sync/glue/synced_tab_delegate_android.h" |
6 | 6 |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "chrome/browser/android/tab_android.h" | 8 #include "chrome/browser/android/tab_android.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/sync/glue/synced_window_delegate.h" | 10 #include "chrome/browser/sync/glue/synced_window_delegate.h" |
| 11 #include "chrome/browser/sync/glue/synced_window_delegates_getter_android.h" |
11 #include "chrome/browser/ui/sync/tab_contents_synced_tab_delegate.h" | 12 #include "chrome/browser/ui/sync/tab_contents_synced_tab_delegate.h" |
12 #include "content/public/browser/navigation_entry.h" | 13 #include "content/public/browser/navigation_entry.h" |
13 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
14 | 15 |
15 using content::NavigationEntry; | 16 using content::NavigationEntry; |
16 | 17 |
17 namespace browser_sync { | 18 namespace browser_sync { |
18 SyncedTabDelegateAndroid::SyncedTabDelegateAndroid(TabAndroid* tab_android) | 19 SyncedTabDelegateAndroid::SyncedTabDelegateAndroid(TabAndroid* tab_android) |
19 : web_contents_(NULL), tab_android_(tab_android) {} | 20 : web_contents_(nullptr), |
| 21 tab_android_(tab_android), |
| 22 tab_contents_delegate_(nullptr) { |
| 23 SetSyncedWindowGetter( |
| 24 make_scoped_ptr(new SyncedWindowDelegatesGetterAndroid())); |
| 25 } |
20 | 26 |
21 SyncedTabDelegateAndroid::~SyncedTabDelegateAndroid() {} | 27 SyncedTabDelegateAndroid::~SyncedTabDelegateAndroid() {} |
22 | 28 |
23 SessionID::id_type SyncedTabDelegateAndroid::GetWindowId() const { | 29 SessionID::id_type SyncedTabDelegateAndroid::GetWindowId() const { |
24 return TabContentsSyncedTabDelegate::FromWebContents(web_contents_) | 30 return tab_contents_delegate_->GetWindowId(); |
25 ->GetWindowId(); | |
26 } | 31 } |
27 | 32 |
28 SessionID::id_type SyncedTabDelegateAndroid::GetSessionId() const { | 33 SessionID::id_type SyncedTabDelegateAndroid::GetSessionId() const { |
29 return tab_android_->session_id().id(); | 34 return tab_android_->session_id().id(); |
30 } | 35 } |
31 | 36 |
32 bool SyncedTabDelegateAndroid::IsBeingDestroyed() const { | 37 bool SyncedTabDelegateAndroid::IsBeingDestroyed() const { |
33 return TabContentsSyncedTabDelegate::FromWebContents(web_contents_) | 38 return tab_contents_delegate_->IsBeingDestroyed(); |
34 ->IsBeingDestroyed(); | |
35 } | 39 } |
36 | 40 |
37 Profile* SyncedTabDelegateAndroid::profile() const { | 41 Profile* SyncedTabDelegateAndroid::profile() const { |
38 return TabContentsSyncedTabDelegate::FromWebContents(web_contents_) | 42 return tab_contents_delegate_->profile(); |
39 ->profile(); | |
40 } | 43 } |
41 | 44 |
42 std::string SyncedTabDelegateAndroid::GetExtensionAppId() const { | 45 std::string SyncedTabDelegateAndroid::GetExtensionAppId() const { |
43 return TabContentsSyncedTabDelegate::FromWebContents(web_contents_) | 46 return tab_contents_delegate_->GetExtensionAppId(); |
44 ->GetExtensionAppId(); | |
45 } | 47 } |
46 | 48 |
47 int SyncedTabDelegateAndroid::GetCurrentEntryIndex() const { | 49 int SyncedTabDelegateAndroid::GetCurrentEntryIndex() const { |
48 return TabContentsSyncedTabDelegate::FromWebContents(web_contents_) | 50 return tab_contents_delegate_->GetCurrentEntryIndex(); |
49 ->GetCurrentEntryIndex(); | |
50 } | 51 } |
51 | 52 |
52 int SyncedTabDelegateAndroid::GetEntryCount() const { | 53 int SyncedTabDelegateAndroid::GetEntryCount() const { |
53 return TabContentsSyncedTabDelegate::FromWebContents(web_contents_) | 54 return tab_contents_delegate_->GetEntryCount(); |
54 ->GetEntryCount(); | |
55 } | 55 } |
56 | 56 |
57 int SyncedTabDelegateAndroid::GetPendingEntryIndex() const { | 57 int SyncedTabDelegateAndroid::GetPendingEntryIndex() const { |
58 return TabContentsSyncedTabDelegate::FromWebContents(web_contents_) | 58 return tab_contents_delegate_->GetPendingEntryIndex(); |
59 ->GetPendingEntryIndex(); | |
60 } | 59 } |
61 | 60 |
62 NavigationEntry* SyncedTabDelegateAndroid::GetPendingEntry() const { | 61 NavigationEntry* SyncedTabDelegateAndroid::GetPendingEntry() const { |
63 return TabContentsSyncedTabDelegate::FromWebContents(web_contents_) | 62 return tab_contents_delegate_->GetPendingEntry(); |
64 ->GetPendingEntry(); | |
65 } | 63 } |
66 | 64 |
67 NavigationEntry* SyncedTabDelegateAndroid::GetEntryAtIndex(int i) const { | 65 NavigationEntry* SyncedTabDelegateAndroid::GetEntryAtIndex(int i) const { |
68 return TabContentsSyncedTabDelegate::FromWebContents(web_contents_) | 66 return tab_contents_delegate_->GetEntryAtIndex(i); |
69 ->GetEntryAtIndex(i); | |
70 } | 67 } |
71 | 68 |
72 NavigationEntry* SyncedTabDelegateAndroid::GetActiveEntry() const { | 69 NavigationEntry* SyncedTabDelegateAndroid::GetActiveEntry() const { |
73 return TabContentsSyncedTabDelegate::FromWebContents(web_contents_) | 70 return tab_contents_delegate_->GetActiveEntry(); |
74 ->GetActiveEntry(); | |
75 } | 71 } |
76 | 72 |
77 bool SyncedTabDelegateAndroid::IsPinned() const { | 73 bool SyncedTabDelegateAndroid::IsPinned() const { |
78 return TabContentsSyncedTabDelegate::FromWebContents(web_contents_) | 74 return tab_contents_delegate_->IsPinned(); |
79 ->IsPinned(); | |
80 } | 75 } |
81 | 76 |
82 bool SyncedTabDelegateAndroid::HasWebContents() const { | 77 bool SyncedTabDelegateAndroid::HasWebContents() const { |
83 return web_contents_ != NULL; | 78 return web_contents_ != NULL; |
84 } | 79 } |
85 | 80 |
86 content::WebContents* SyncedTabDelegateAndroid::GetWebContents() const { | 81 content::WebContents* SyncedTabDelegateAndroid::GetWebContents() const { |
87 return web_contents_; | 82 return web_contents_; |
88 } | 83 } |
89 | 84 |
90 void SyncedTabDelegateAndroid::SetWebContents( | 85 void SyncedTabDelegateAndroid::SetWebContents( |
91 content::WebContents* web_contents) { | 86 content::WebContents* web_contents) { |
92 web_contents_ = web_contents; | 87 web_contents_ = web_contents; |
93 TabContentsSyncedTabDelegate::CreateForWebContents(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())); |
94 } | 95 } |
95 | 96 |
96 void SyncedTabDelegateAndroid::ResetWebContents() { web_contents_ = NULL; } | 97 void SyncedTabDelegateAndroid::ResetWebContents() { web_contents_ = NULL; } |
97 | 98 |
98 bool SyncedTabDelegateAndroid::ProfileIsSupervised() const { | 99 bool SyncedTabDelegateAndroid::ProfileIsSupervised() const { |
99 return TabContentsSyncedTabDelegate::FromWebContents(web_contents_) | 100 return tab_contents_delegate_->ProfileIsSupervised(); |
100 ->ProfileIsSupervised(); | |
101 } | 101 } |
102 | 102 |
103 const std::vector<const content::NavigationEntry*>* | 103 const std::vector<const content::NavigationEntry*>* |
104 SyncedTabDelegateAndroid::GetBlockedNavigations() const { | 104 SyncedTabDelegateAndroid::GetBlockedNavigations() const { |
105 return TabContentsSyncedTabDelegate::FromWebContents(web_contents_) | 105 return tab_contents_delegate_->GetBlockedNavigations(); |
106 ->GetBlockedNavigations(); | |
107 } | 106 } |
108 | 107 |
109 int SyncedTabDelegateAndroid::GetSyncId() const { | 108 int SyncedTabDelegateAndroid::GetSyncId() const { |
110 return tab_android_->GetSyncId(); | 109 return tab_android_->GetSyncId(); |
111 } | 110 } |
112 | 111 |
113 void SyncedTabDelegateAndroid::SetSyncId(int sync_id) { | 112 void SyncedTabDelegateAndroid::SetSyncId(int sync_id) { |
114 tab_android_->SetSyncId(sync_id); | 113 tab_android_->SetSyncId(sync_id); |
115 } | 114 } |
116 | 115 |
117 // static | 116 // static |
118 SyncedTabDelegate* SyncedTabDelegate::ImplFromWebContents( | 117 SyncedTabDelegate* SyncedTabDelegate::ImplFromWebContents( |
119 content::WebContents* web_contents) { | 118 content::WebContents* web_contents) { |
120 TabAndroid* tab = TabAndroid::FromWebContents(web_contents); | 119 TabAndroid* tab = TabAndroid::FromWebContents(web_contents); |
121 return tab ? tab->GetSyncedTabDelegate() : NULL; | 120 return tab ? tab->GetSyncedTabDelegate() : nullptr; |
122 } | 121 } |
123 | 122 |
124 } // namespace browser_sync | 123 } // namespace browser_sync |
OLD | NEW |