1 // Copyright (c) 2012 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_window_delegate_android.h"
7 #include "chrome/browser/android/tab_android.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/sync/glue/synced_tab_delegate_android.h"
10 #include "chrome/browser/ui/android/tab_model/tab_model.h"
11 #include "chrome/browser/ui/android/tab_model/tab_model_list.h"
12 #include "content/public/browser/web_contents.h"
14 namespace browser_sync
{
16 // SyncedWindowDelegate implementations
18 std::set
<SyncedWindowDelegate
const*> SyncedWindowDelegate::GetAll() {
19 std::set
<SyncedWindowDelegate
const*> synced_window_delegates
;
20 for (TabModelList::const_iterator i
= TabModelList::begin();
21 i
!= TabModelList::end(); ++i
) {
22 synced_window_delegates
.insert((*i
)->GetSyncedWindowDelegate());
24 return synced_window_delegates
;
27 const SyncedWindowDelegate
* SyncedWindowDelegate::FindById(
28 SessionID::id_type session_id
) {
29 TabModel
* tab_model
= TabModelList::FindTabModelWithId(session_id
);
31 // In case we don't find the browser (e.g. for Developer Tools).
32 return tab_model
? tab_model
->GetSyncedWindowDelegate() : NULL
;
35 // SyncedWindowDelegateAndroid implementations
37 SyncedWindowDelegateAndroid::SyncedWindowDelegateAndroid(
39 : tab_model_(tab_model
) {}
41 SyncedWindowDelegateAndroid::~SyncedWindowDelegateAndroid() {}
43 bool SyncedWindowDelegateAndroid::HasWindow() const {
44 return !tab_model_
->IsOffTheRecord();
47 SessionID::id_type
SyncedWindowDelegateAndroid::GetSessionId() const {
48 return tab_model_
->GetSessionId();
51 int SyncedWindowDelegateAndroid::GetTabCount() const {
52 return tab_model_
->GetTabCount();
55 int SyncedWindowDelegateAndroid::GetActiveIndex() const {
56 return tab_model_
->GetActiveIndex();
59 bool SyncedWindowDelegateAndroid::IsApp() const {
63 bool SyncedWindowDelegateAndroid::IsTypeTabbed() const {
67 bool SyncedWindowDelegateAndroid::IsTypePopup() const {
71 bool SyncedWindowDelegateAndroid::IsTabPinned(
72 const SyncedTabDelegate
* tab
) const {
76 SyncedTabDelegate
* SyncedWindowDelegateAndroid::GetTabAt(int index
) const {
77 // After a restart, it is possible for the Tab to be null during startup.
78 TabAndroid
* tab
= tab_model_
->GetTabAt(index
);
79 return tab
? tab
->GetSyncedTabDelegate() : NULL
;
82 SessionID::id_type
SyncedWindowDelegateAndroid::GetTabIdAt(int index
) const {
83 SyncedTabDelegate
* tab
= GetTabAt(index
);
84 return tab
? tab
->GetSessionId() : -1;
87 bool SyncedWindowDelegateAndroid::IsSessionRestoreInProgress() const {
88 return tab_model_
->IsSessionRestoreInProgress();
91 bool SyncedWindowDelegateAndroid::ShouldSync() const {
95 } // namespace browser_sync