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/sessions/session_id.h"
10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/browser_finder.h"
12 #include "chrome/browser/ui/browser_iterator.h"
13 #include "chrome/browser/ui/sync/tab_contents_synced_tab_delegate.h"
14 #include "chrome/browser/ui/tabs/tab_strip_model.h"
16 // static SyncedWindowDelegate implementations
19 const std::set
<browser_sync::SyncedWindowDelegate
*>
20 browser_sync::SyncedWindowDelegate::GetSyncedWindowDelegates() {
21 std::set
<browser_sync::SyncedWindowDelegate
*> synced_window_delegates
;
22 for (chrome::BrowserIterator it
; !it
.done(); it
.Next())
23 synced_window_delegates
.insert(it
->synced_window_delegate());
24 return synced_window_delegates
;
28 const browser_sync::SyncedWindowDelegate
*
29 browser_sync::SyncedWindowDelegate::FindSyncedWindowDelegateWithId(
30 SessionID::id_type id
) {
31 Browser
* browser
= chrome::FindBrowserWithID(id
);
32 // In case we don't find the browser (e.g. for Developer Tools).
33 return browser
? browser
->synced_window_delegate() : NULL
;
36 // BrowserSyncedWindowDelegate implementations
38 BrowserSyncedWindowDelegate::BrowserSyncedWindowDelegate(Browser
* browser
)
39 : browser_(browser
) {}
41 BrowserSyncedWindowDelegate::~BrowserSyncedWindowDelegate() {}
43 bool BrowserSyncedWindowDelegate::IsTabPinned(
44 const browser_sync::SyncedTabDelegate
* tab
) const {
45 for (int i
= 0; i
< browser_
->tab_strip_model()->count(); i
++) {
46 browser_sync::SyncedTabDelegate
* current
= GetTabAt(i
);
48 return browser_
->tab_strip_model()->IsTabPinned(i
);
54 browser_sync::SyncedTabDelegate
* BrowserSyncedWindowDelegate::GetTabAt(
56 return TabContentsSyncedTabDelegate::FromWebContents(
57 browser_
->tab_strip_model()->GetWebContentsAt(index
));
60 SessionID::id_type
BrowserSyncedWindowDelegate::GetTabIdAt(int index
) const {
61 return GetTabAt(index
)->GetSessionId();
64 bool BrowserSyncedWindowDelegate::HasWindow() const {
65 return browser_
->window() != NULL
;
68 SessionID::id_type
BrowserSyncedWindowDelegate::GetSessionId() const {
69 return browser_
->session_id().id();
72 int BrowserSyncedWindowDelegate::GetTabCount() const {
73 return browser_
->tab_strip_model()->count();
76 int BrowserSyncedWindowDelegate::GetActiveIndex() const {
77 return browser_
->tab_strip_model()->active_index();
80 bool BrowserSyncedWindowDelegate::IsApp() const {
81 return browser_
->is_app();
84 bool BrowserSyncedWindowDelegate::IsTypeTabbed() const {
85 return browser_
->is_type_tabbed();
88 bool BrowserSyncedWindowDelegate::IsTypePopup() const {
89 return browser_
->is_type_popup();
92 bool BrowserSyncedWindowDelegate::IsSessionRestoreInProgress() const {