- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / sync / glue / synced_window_delegate_android.cc
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.
4
5 #include "chrome/browser/sync/glue/synced_window_delegate_android.h"
6
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"
13
14 namespace browser_sync {
15
16 // SyncedWindowDelegate implementations
17
18 const std::set<SyncedWindowDelegate*>
19     SyncedWindowDelegate::GetSyncedWindowDelegates() {
20   std::set<SyncedWindowDelegate*> synced_window_delegates;
21   for (TabModelList::const_iterator i = TabModelList::begin();
22       i != TabModelList::end(); ++i) {
23     synced_window_delegates.insert((*i)->GetSyncedWindowDelegate());
24   }
25   return synced_window_delegates;
26 }
27
28 const SyncedWindowDelegate*
29     SyncedWindowDelegate::FindSyncedWindowDelegateWithId(
30         SessionID::id_type session_id) {
31   TabModel* tab_model = TabModelList::FindTabModelWithId(
32       session_id);
33
34   // In case we don't find the browser (e.g. for Developer Tools).
35   return tab_model ? tab_model->GetSyncedWindowDelegate() : NULL;
36 }
37
38 // SyncedWindowDelegateAndroid implementations
39
40 SyncedWindowDelegateAndroid::SyncedWindowDelegateAndroid(
41     TabModel* tab_model)
42     : tab_model_(tab_model) {}
43
44 SyncedWindowDelegateAndroid::~SyncedWindowDelegateAndroid() {}
45
46 bool SyncedWindowDelegateAndroid::HasWindow() const {
47   return !tab_model_->IsOffTheRecord();
48 }
49
50 SessionID::id_type SyncedWindowDelegateAndroid::GetSessionId() const {
51   return tab_model_->GetSessionId();
52 }
53
54 int SyncedWindowDelegateAndroid::GetTabCount() const {
55   return tab_model_->GetTabCount();
56 }
57
58 int SyncedWindowDelegateAndroid::GetActiveIndex() const {
59   return tab_model_->GetActiveIndex();
60 }
61
62 bool SyncedWindowDelegateAndroid::IsApp() const {
63   return false;
64 }
65
66 bool SyncedWindowDelegateAndroid::IsTypeTabbed() const {
67   return true;
68 }
69
70 bool SyncedWindowDelegateAndroid::IsTypePopup() const {
71   return false;
72 }
73
74 bool SyncedWindowDelegateAndroid::IsTabPinned(
75     const SyncedTabDelegate* tab) const {
76   return false;
77 }
78
79 SyncedTabDelegate* SyncedWindowDelegateAndroid::GetTabAt(int index) const {
80   // After a restart, it is possible for the Tab to be null during startup.
81   TabAndroid* tab = tab_model_->GetTabAt(index);
82   return tab ? tab->GetSyncedTabDelegate() : NULL;
83 }
84
85 SessionID::id_type SyncedWindowDelegateAndroid::GetTabIdAt(int index) const {
86   SyncedTabDelegate* tab = GetTabAt(index);
87   return tab ? tab->GetSessionId() : -1;
88 }
89
90 bool SyncedWindowDelegateAndroid::IsSessionRestoreInProgress() const {
91   return tab_model_->IsSessionRestoreInProgress();
92 }
93
94 }  // namespace browser_sync