Add a minor text member to ui::MenuModel.
[chromium-blink-merge.git] / chrome / browser / ui / sync / browser_synced_window_delegate.cc
blob7809aa006af612b6aa1743b45649eb35e046b486
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"
7 #include <set>
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
18 // static
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;
27 // static
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);
47 if (tab == current)
48 return browser_->tab_strip_model()->IsTabPinned(i);
50 NOTREACHED();
51 return false;
54 browser_sync::SyncedTabDelegate* BrowserSyncedWindowDelegate::GetTabAt(
55 int index) const {
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 {
93 return false;