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/ui/sync/browser_synced_window_delegate.h"
9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/browser_finder.h"
11 #include "chrome/browser/ui/browser_iterator.h"
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/sessions/session_id.h"
16 // BrowserSyncedWindowDelegate implementations
18 BrowserSyncedWindowDelegate::BrowserSyncedWindowDelegate(Browser
* browser
)
19 : browser_(browser
) {}
21 BrowserSyncedWindowDelegate::~BrowserSyncedWindowDelegate() {}
23 bool BrowserSyncedWindowDelegate::IsTabPinned(
24 const browser_sync::SyncedTabDelegate
* tab
) const {
25 for (int i
= 0; i
< browser_
->tab_strip_model()->count(); i
++) {
26 browser_sync::SyncedTabDelegate
* current
= GetTabAt(i
);
28 return browser_
->tab_strip_model()->IsTabPinned(i
);
30 // The window and tab are not always updated atomically, so it's possible
31 // one of the values was stale. We'll retry later, just ignore for now.
35 browser_sync::SyncedTabDelegate
* BrowserSyncedWindowDelegate::GetTabAt(
37 return TabContentsSyncedTabDelegate::FromWebContents(
38 browser_
->tab_strip_model()->GetWebContentsAt(index
));
41 SessionID::id_type
BrowserSyncedWindowDelegate::GetTabIdAt(int index
) const {
42 return GetTabAt(index
)->GetSessionId();
45 bool BrowserSyncedWindowDelegate::HasWindow() const {
46 return browser_
->window() != NULL
;
49 SessionID::id_type
BrowserSyncedWindowDelegate::GetSessionId() const {
50 return browser_
->session_id().id();
53 int BrowserSyncedWindowDelegate::GetTabCount() const {
54 return browser_
->tab_strip_model()->count();
57 int BrowserSyncedWindowDelegate::GetActiveIndex() const {
58 return browser_
->tab_strip_model()->active_index();
61 bool BrowserSyncedWindowDelegate::IsApp() const {
62 return browser_
->is_app();
65 bool BrowserSyncedWindowDelegate::IsTypeTabbed() const {
66 return browser_
->is_type_tabbed();
69 bool BrowserSyncedWindowDelegate::IsTypePopup() const {
70 return browser_
->is_type_popup();
73 bool BrowserSyncedWindowDelegate::IsSessionRestoreInProgress() const {
77 bool BrowserSyncedWindowDelegate::ShouldSync() const {
80 return IsTypeTabbed() || IsTypePopup();