summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorqsr@google.com <qsr@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-28 10:21:16 +0000
committerqsr@google.com <qsr@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-28 10:21:16 +0000
commit4a3d1a0a4aeed9023ec7fcf4672205e986d16596 (patch)
tree7c7fc44d24a2c5c2bd98406db67c978b3c5b0d80
parentea3029b858c8d8e080e6d324e5c8fd58bb18b770 (diff)
downloadchromium_src-4a3d1a0a4aeed9023ec7fcf4672205e986d16596.zip
chromium_src-4a3d1a0a4aeed9023ec7fcf4672205e986d16596.tar.gz
chromium_src-4a3d1a0a4aeed9023ec7fcf4672205e986d16596.tar.bz2
Abstract TabContentsWrapper in sync.
BUG= TEST= Review URL: http://codereview.chromium.org/7491040 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@94438 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/sync/glue/session_change_processor.cc31
-rw-r--r--chrome/browser/sync/glue/session_model_associator.cc57
-rw-r--r--chrome/browser/sync/glue/session_model_associator.h23
-rw-r--r--chrome/browser/sync/glue/synced_tab_delegate.h49
-rw-r--r--chrome/browser/sync/glue/synced_window_delegate.h19
-rw-r--r--chrome/browser/sync/profile_sync_service_session_unittest.cc12
-rw-r--r--chrome/browser/ui/browser_synced_window_delegate.cc19
-rw-r--r--chrome/browser/ui/browser_synced_window_delegate.h11
-rw-r--r--chrome/browser/ui/tab_contents/tab_contents_wrapper.cc3
-rw-r--r--chrome/browser/ui/tab_contents/tab_contents_wrapper.h8
-rw-r--r--chrome/browser/ui/tab_contents/tab_contents_wrapper_synced_tab_delegate.cc70
-rw-r--r--chrome/browser/ui/tab_contents/tab_contents_wrapper_synced_tab_delegate.h42
-rw-r--r--chrome/chrome_browser.gypi2
13 files changed, 265 insertions, 81 deletions
diff --git a/chrome/browser/sync/glue/session_change_processor.cc b/chrome/browser/sync/glue/session_change_processor.cc
index 61abbd7..4e70725 100644
--- a/chrome/browser/sync/glue/session_change_processor.cc
+++ b/chrome/browser/sync/glue/session_change_processor.cc
@@ -62,7 +62,7 @@ void SessionChangeProcessor::Observe(int type,
DCHECK(profile_);
// Track which windows and/or tabs are modified.
- std::vector<TabContentsWrapper*> modified_tabs;
+ std::vector<SyncedTabDelegate*> modified_tabs;
switch (type) {
case chrome::NOTIFICATION_BROWSER_OPENED: {
Browser* browser = Source<Browser>(source).ptr();
@@ -74,7 +74,7 @@ void SessionChangeProcessor::Observe(int type,
}
case content::NOTIFICATION_TAB_PARENTED: {
- TabContentsWrapper* tab = Source<TabContentsWrapper>(source).ptr();
+ SyncedTabDelegate* tab = Source<SyncedTabDelegate>(source).ptr();
if (tab->profile() != profile_) {
return;
}
@@ -84,9 +84,9 @@ void SessionChangeProcessor::Observe(int type,
}
case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: {
- TabContentsWrapper* tab =
+ SyncedTabDelegate* tab =
TabContentsWrapper::GetCurrentWrapperForContents(
- Source<TabContents>(source).ptr());
+ Source<TabContents>(source).ptr())->synced_tab_delegate();
if (tab->profile() != profile_) {
return;
}
@@ -96,9 +96,10 @@ void SessionChangeProcessor::Observe(int type,
}
case content::NOTIFICATION_TAB_CLOSED: {
- TabContentsWrapper* tab =
+ SyncedTabDelegate* tab =
TabContentsWrapper::GetCurrentWrapperForContents(
- Source<NavigationController>(source).ptr()->tab_contents());
+ Source<NavigationController>(source).ptr()->tab_contents())->
+ synced_tab_delegate();
if (!tab || tab->profile() != profile_) {
return;
}
@@ -108,9 +109,10 @@ void SessionChangeProcessor::Observe(int type,
}
case content::NOTIFICATION_NAV_LIST_PRUNED: {
- TabContentsWrapper* tab =
+ SyncedTabDelegate* tab =
TabContentsWrapper::GetCurrentWrapperForContents(
- Source<NavigationController>(source).ptr()->tab_contents());
+ Source<NavigationController>(source).ptr()->tab_contents())->
+ synced_tab_delegate();
if (!tab || tab->profile() != profile_) {
return;
}
@@ -120,9 +122,10 @@ void SessionChangeProcessor::Observe(int type,
}
case content::NOTIFICATION_NAV_ENTRY_CHANGED: {
- TabContentsWrapper* tab =
+ SyncedTabDelegate* tab =
TabContentsWrapper::GetCurrentWrapperForContents(
- Source<NavigationController>(source).ptr()->tab_contents());
+ Source<NavigationController>(source).ptr()->tab_contents())->
+ synced_tab_delegate();
if (!tab || tab->profile() != profile_) {
return;
}
@@ -132,9 +135,10 @@ void SessionChangeProcessor::Observe(int type,
}
case content::NOTIFICATION_NAV_ENTRY_COMMITTED: {
- TabContentsWrapper* tab =
+ SyncedTabDelegate* tab =
TabContentsWrapper::GetCurrentWrapperForContents(
- Source<NavigationController>(source).ptr()->tab_contents());
+ Source<NavigationController>(source).ptr()->tab_contents())->
+ synced_tab_delegate();
if (!tab || tab->profile() != profile_) {
return;
}
@@ -150,7 +154,8 @@ void SessionChangeProcessor::Observe(int type,
return;
}
if (extension_tab_helper->extension_app()) {
- modified_tabs.push_back(extension_tab_helper->tab_contents_wrapper());
+ modified_tabs.push_back(extension_tab_helper->tab_contents_wrapper()->
+ synced_tab_delegate());
}
VLOG(1) << "Received TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED "
<< "for profile " << profile_;
diff --git a/chrome/browser/sync/glue/session_model_associator.cc b/chrome/browser/sync/glue/session_model_associator.cc
index 5811049..8ba5e61 100644
--- a/chrome/browser/sync/glue/session_model_associator.cc
+++ b/chrome/browser/sync/glue/session_model_associator.cc
@@ -10,19 +10,15 @@
#include "base/logging.h"
#include "base/tracked.h"
-#include "chrome/browser/extensions/extension_tab_helper.h"
#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/sessions/restore_tab_helper.h"
#include "chrome/browser/sessions/session_service_factory.h"
#include "chrome/browser/sync/api/sync_error.h"
+#include "chrome/browser/sync/glue/synced_tab_delegate.h"
#include "chrome/browser/sync/glue/synced_window_delegate.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/syncable/syncable.h"
-#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
#include "chrome/common/chrome_notification_types.h"
-#include "chrome/common/extensions/extension.h"
#include "chrome/common/url_constants.h"
-#include "content/browser/tab_contents/navigation_controller.h"
#include "content/browser/tab_contents/navigation_entry.h"
#include "content/common/notification_details.h"
#include "content/common/notification_service.h"
@@ -102,7 +98,7 @@ int64 SessionModelAssociator::GetSyncIdFromSessionTag(const std::string& tag) {
return node.GetId();
}
-const TabContentsWrapper*
+const SyncedTabDelegate*
SessionModelAssociator::GetChromeNodeFromSyncId(int64 sync_id) {
NOTREACHED();
return NULL;
@@ -155,11 +151,11 @@ void SessionModelAssociator::ReassociateWindows(bool reload_tabs) {
// Store the order of tabs.
bool found_tabs = false;
for (int j = 0; j < (*i)->GetTabCount(); ++j) {
- TabContentsWrapper* tab = (*i)->GetTabContentsWrapperAt(j);
+ SyncedTabDelegate* tab = (*i)->GetTabAt(j);
DCHECK(tab);
if (IsValidTab(*tab)) {
found_tabs = true;
- window_s.add_tab(tab->restore_tab_helper()->session_id().id());
+ window_s.add_tab(tab->GetSessionId().id());
if (reload_tabs) {
ReassociateTab(*tab);
}
@@ -204,9 +200,9 @@ bool SessionModelAssociator::ShouldSyncWindow(
}
void SessionModelAssociator::ReassociateTabs(
- const std::vector<TabContentsWrapper*>& tabs) {
+ const std::vector<SyncedTabDelegate*>& tabs) {
DCHECK(CalledOnValidThread());
- for (std::vector<TabContentsWrapper*>::const_iterator i = tabs.begin();
+ for (std::vector<SyncedTabDelegate*>::const_iterator i = tabs.begin();
i != tabs.end();
++i) {
ReassociateTab(**i);
@@ -214,14 +210,14 @@ void SessionModelAssociator::ReassociateTabs(
if (waiting_for_change_) QuitLoopForTest();
}
-void SessionModelAssociator::ReassociateTab(const TabContentsWrapper& tab) {
+void SessionModelAssociator::ReassociateTab(const SyncedTabDelegate& tab) {
DCHECK(CalledOnValidThread());
if (!IsValidTab(tab))
return;
int64 sync_id;
- SessionID::id_type id = tab.restore_tab_helper()->session_id().id();
- if (tab.tab_contents()->is_being_destroyed()) {
+ SessionID::id_type id = tab.GetSessionId().id();
+ if (tab.IsBeingDestroyed()) {
// This tab is closing.
TabLinksMap::iterator tab_iter = tab_map_.find(id);
if (tab_iter == tab_map_.end()) {
@@ -244,13 +240,13 @@ void SessionModelAssociator::ReassociateTab(const TabContentsWrapper& tab) {
Associate(&tab, sync_id);
}
-void SessionModelAssociator::Associate(const TabContentsWrapper* tab,
+void SessionModelAssociator::Associate(const SyncedTabDelegate* tab,
int64 sync_id) {
DCHECK(CalledOnValidThread());
- SessionID::id_type session_id = tab->restore_tab_helper()->session_id().id();
+ SessionID::id_type session_id = tab->GetSessionId().id();
const SyncedWindowDelegate* window =
SyncedWindowDelegate::FindSyncedWindowDelegateWithId(
- tab->restore_tab_helper()->window_id().id());
+ tab->GetWindowId().id());
if (!window) { // Can happen for weird things like developer console.
tab_pool_.FreeTabNode(sync_id);
return;
@@ -265,9 +261,10 @@ void SessionModelAssociator::Associate(const TabContentsWrapper* tab,
bool SessionModelAssociator::WriteTabContentsToSyncModel(
const SyncedWindowDelegate& window,
- const TabContentsWrapper& tab,
+ const SyncedTabDelegate& tab,
int64 sync_id,
sync_api::WriteTransaction* trans) {
+
DCHECK(CalledOnValidThread());
sync_api::WriteNode tab_node(trans);
if (!tab_node.InitByIdLookup(sync_id)) {
@@ -279,24 +276,22 @@ bool SessionModelAssociator::WriteTabContentsToSyncModel(
session_s.set_session_tag(GetCurrentMachineTag());
sync_pb::SessionTab* tab_s = session_s.mutable_tab();
- SessionID::id_type tab_id = tab.restore_tab_helper()->session_id().id();
+ SessionID::id_type tab_id = tab.GetSessionId().id();
tab_s->set_tab_id(tab_id);
- tab_s->set_window_id(tab.restore_tab_helper()->window_id().id());
- const int current_index = tab.controller().GetCurrentEntryIndex();
+ tab_s->set_window_id(tab.GetWindowId().id());
+ const int current_index = tab.GetCurrentEntryIndex();
const int min_index = std::max(0,
current_index - max_sync_navigation_count);
const int max_index = std::min(current_index + max_sync_navigation_count,
- tab.controller().entry_count());
- const int pending_index = tab.controller().pending_entry_index();
- tab_s->set_pinned(window.IsTabContentsWrapperPinned(&tab));
- if (tab.extension_tab_helper() &&
- tab.extension_tab_helper()->extension_app()) {
- tab_s->set_extension_app_id(
- tab.extension_tab_helper()->extension_app()->id());
+ tab.GetEntryCount());
+ const int pending_index = tab.GetPendingEntryIndex();
+ tab_s->set_pinned(window.IsTabPinned(&tab));
+ if (tab.HasExtensionAppId()) {
+ tab_s->set_extension_app_id(tab.GetExtensionAppId());
}
for (int i = min_index; i < max_index; ++i) {
const NavigationEntry* entry = (i == pending_index) ?
- tab.controller().pending_entry() : tab.controller().GetEntryAtIndex(i);
+ tab.GetPendingEntry() : tab.GetEntryAtIndex(i);
DCHECK(entry);
if (entry->virtual_url().is_valid()) {
if (i == max_index - 1) {
@@ -846,16 +841,16 @@ bool SessionModelAssociator::SessionWindowHasNoTabsToSync(
}
// Valid local tab?
-bool SessionModelAssociator::IsValidTab(const TabContentsWrapper& tab) {
+bool SessionModelAssociator::IsValidTab(const SyncedTabDelegate& tab) {
DCHECK(CalledOnValidThread());
if ((tab.profile() == sync_service_->profile() ||
sync_service_->profile() == NULL)) {
- const NavigationEntry* entry = tab.controller().GetActiveEntry();
+ const NavigationEntry* entry = tab.GetActiveEntry();
if (!entry)
return false;
if (entry->virtual_url().is_valid() &&
(entry->virtual_url() != GURL(chrome::kChromeUINewTabURL) ||
- tab.controller().entry_count() > 1)) {
+ tab.GetEntryCount() > 1)) {
return true;
}
}
diff --git a/chrome/browser/sync/glue/session_model_associator.h b/chrome/browser/sync/glue/session_model_associator.h
index 486b49f..006a3b6 100644
--- a/chrome/browser/sync/glue/session_model_associator.h
+++ b/chrome/browser/sync/glue/session_model_associator.h
@@ -23,6 +23,7 @@
#include "chrome/browser/sessions/session_types.h"
#include "chrome/browser/sync/engine/syncapi.h"
#include "chrome/browser/sync/glue/synced_session_tracker.h"
+#include "chrome/browser/sync/glue/synced_tab_delegate.h"
#include "chrome/browser/sync/glue/synced_window_delegate.h"
#include "chrome/browser/sync/glue/model_associator.h"
#include "chrome/browser/sync/protocol/session_specifics.pb.h"
@@ -49,7 +50,7 @@ static const char kSessionsTag[] = "google_chrome_sessions";
// Contains all logic for associating the Chrome sessions model and
// the sync sessions model.
class SessionModelAssociator
- : public PerDataTypeAssociatorInterface<TabContentsWrapper, size_t>,
+ : public PerDataTypeAssociatorInterface<SyncedTabDelegate, size_t>,
public base::NonThreadSafe {
public:
// Does not take ownership of sync_service.
@@ -82,7 +83,7 @@ class SessionModelAssociator
virtual int64 GetSyncIdFromSessionTag(const std::string& tag);
// Not used.
- virtual const TabContentsWrapper* GetChromeNodeFromSyncId(int64 sync_id);
+ virtual const SyncedTabDelegate* GetChromeNodeFromSyncId(int64 sync_id);
// Not used.
virtual bool InitSyncNodeFromChromeId(const size_t& id,
@@ -98,15 +99,15 @@ class SessionModelAssociator
void ReassociateWindows(bool reload_tabs);
// Loads and reassociates the local tabs referenced in |tabs|.
- void ReassociateTabs(const std::vector<TabContentsWrapper*>& tabs);
+ void ReassociateTabs(const std::vector<SyncedTabDelegate*>& tabs);
// Reassociates a single tab with the sync model. Will check if the tab
// already is associated with a sync node and allocate one if necessary.
- void ReassociateTab(const TabContentsWrapper& tab);
+ void ReassociateTab(const SyncedTabDelegate& tab);
// Associate a local tab and it's sync node. Will overwrite the contents of
// the sync node with new specifics built from the tab.
- virtual void Associate(const TabContentsWrapper* tab, int64 sync_id);
+ virtual void Associate(const SyncedTabDelegate* tab, int64 sync_id);
// Looks up the specified sync node, and marks that tab as closed, then marks
// the node as free and deletes association.
@@ -169,7 +170,7 @@ class SessionModelAssociator
// Control which local tabs we're interested in syncing.
// Ensures the profile matches sync's profile and that the tab has at least
// one navigation entry and is not an empty tab.
- bool IsValidTab(const TabContentsWrapper& tab);
+ bool IsValidTab(const SyncedTabDelegate& tab);
// Control which foreign tabs we're interested in displaying.
// Checks that the tab has navigations and is not a new tab.
@@ -206,10 +207,10 @@ class SessionModelAssociator
// We only ever have either a SessionTab (for foreign tabs), or a
// TabContents (for local tabs).
- TabLinks(int64 sync_id, const TabContentsWrapper* tab)
+ TabLinks(int64 sync_id, const SyncedTabDelegate* tab)
: sync_id_(sync_id),
session_tab_(NULL) {
- tab_ = const_cast<TabContentsWrapper*>(tab);
+ tab_ = const_cast<SyncedTabDelegate*>(tab);
}
TabLinks(int64 sync_id, const SessionTab* session_tab)
: sync_id_(sync_id),
@@ -219,11 +220,11 @@ class SessionModelAssociator
inline int64 sync_id() const { return sync_id_; }
inline const SessionTab* session_tab() const { return session_tab_; }
- inline const TabContentsWrapper* tab() const { return tab_; }
+ inline const SyncedTabDelegate* tab() const { return tab_; }
private:
int64 sync_id_;
SessionTab* session_tab_;
- TabContentsWrapper* tab_;
+ SyncedTabDelegate* tab_;
};
// A pool for managing free/used tab sync nodes. Performs lazy creation
@@ -334,7 +335,7 @@ class SessionModelAssociator
// Fills a tab sync node with data from a TabContents object.
// (from a local navigation event)
bool WriteTabContentsToSyncModel(const SyncedWindowDelegate& window,
- const TabContentsWrapper& tab,
+ const SyncedTabDelegate& tab,
const int64 sync_id,
sync_api::WriteTransaction* trans);
diff --git a/chrome/browser/sync/glue/synced_tab_delegate.h b/chrome/browser/sync/glue/synced_tab_delegate.h
new file mode 100644
index 0000000..9c0263c
--- /dev/null
+++ b/chrome/browser/sync/glue/synced_tab_delegate.h
@@ -0,0 +1,49 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_SYNC_GLUE_SYNCED_TAB_DELEGATE_H__
+#define CHROME_BROWSER_SYNC_GLUE_SYNCED_TAB_DELEGATE_H__
+#pragma once
+
+#include <string>
+
+#include "chrome/browser/sessions/session_id.h"
+
+class NavigationEntry;
+class Profile;
+
+namespace browser_sync {
+
+// A SyncedTabDelegate is used to insulate the sync code from depending
+// directly on TabContents, TabContentsWrapper and NavigationController.
+class SyncedTabDelegate {
+ public:
+ // Method from TabContentsWrapper.
+
+ virtual const SessionID& GetWindowId() const = 0;
+ virtual const SessionID& GetSessionId() const = 0;
+ virtual bool IsBeingDestroyed() const = 0;
+ virtual Profile* profile() const = 0;
+
+ // Method derived from TabContentsWrapper.
+
+ virtual bool HasExtensionAppId() const = 0;
+ virtual const std::string& GetExtensionAppId() const = 0;
+
+ // Method from NavigationController
+
+ virtual int GetCurrentEntryIndex() const = 0;
+ virtual int GetEntryCount() const = 0;
+ virtual int GetPendingEntryIndex() const = 0;
+ virtual NavigationEntry* GetPendingEntry() const = 0;
+ virtual NavigationEntry* GetEntryAtIndex(int i) const = 0;
+ virtual NavigationEntry* GetActiveEntry() const = 0;
+
+ protected:
+ virtual ~SyncedTabDelegate() {}
+};
+
+} // namespace browser_sync
+
+#endif // CHROME_BROWSER_SYNC_GLUE_SYNCED_TAB_DELEGATE_H__
diff --git a/chrome/browser/sync/glue/synced_window_delegate.h b/chrome/browser/sync/glue/synced_window_delegate.h
index 6ef948e..e847784 100644
--- a/chrome/browser/sync/glue/synced_window_delegate.h
+++ b/chrome/browser/sync/glue/synced_window_delegate.h
@@ -10,10 +10,10 @@
#include "chrome/browser/sessions/session_id.h"
-class TabContentsWrapper;
-
namespace browser_sync {
+class SyncedTabDelegate;
+
// A SyncedWindowDelegate is used to insulate the sync code from depending
// directly on Browser and BrowserList.
class SyncedWindowDelegate {
@@ -29,13 +29,6 @@ class SyncedWindowDelegate {
// Methods originating from Browser.
- // Returns true iff the provided tab is currently "pinned" in the tab strip.
- virtual bool IsTabContentsWrapperPinned(
- const TabContentsWrapper* tab) const = 0;
-
- // see Browser::GetTabContentsWrapperAt
- virtual TabContentsWrapper* GetTabContentsWrapperAt(int index) const = 0;
-
// Returns true iff this browser has a visible window representation
// associated with it. Sometimes, if a window is being created/removed the
// model object may exist without its UI counterpart.
@@ -59,6 +52,14 @@ class SyncedWindowDelegate {
// see Browser::is_type_popup
virtual bool IsTypePopup() const = 0;
+ // Methods derivated from Browser
+
+ // Returns true iff the provided tab is currently "pinned" in the tab strip.
+ virtual bool IsTabPinned(const SyncedTabDelegate* tab) const = 0;
+
+ // see Browser::GetTabContentsWrapperAt
+ virtual SyncedTabDelegate* GetTabAt(int index) const = 0;
+
protected:
virtual ~SyncedWindowDelegate() {}
};
diff --git a/chrome/browser/sync/profile_sync_service_session_unittest.cc b/chrome/browser/sync/profile_sync_service_session_unittest.cc
index 5065ac8..6d87e54 100644
--- a/chrome/browser/sync/profile_sync_service_session_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_session_unittest.cc
@@ -244,16 +244,16 @@ TEST_F(ProfileSyncServiceSessionTest, MAYBE_WriteFilledSessionToNode) {
// Tabs are ordered by sessionid in tab_map, so should be able to traverse
// the tree based on order of tabs created
SessionModelAssociator::TabLinksMap::iterator iter = tab_map.begin();
- ASSERT_EQ(2, iter->second.tab()->controller().entry_count());
- ASSERT_EQ(GURL("http://foo/1"), iter->second.tab()->controller().
+ ASSERT_EQ(2, iter->second.tab()->GetEntryCount());
+ ASSERT_EQ(GURL("http://foo/1"), iter->second.tab()->
GetEntryAtIndex(0)->virtual_url());
- ASSERT_EQ(GURL("http://foo/2"), iter->second.tab()->controller().
+ ASSERT_EQ(GURL("http://foo/2"), iter->second.tab()->
GetEntryAtIndex(1)->virtual_url());
iter++;
- ASSERT_EQ(2, iter->second.tab()->controller().entry_count());
- ASSERT_EQ(GURL("http://bar/1"), iter->second.tab()->controller().
+ ASSERT_EQ(2, iter->second.tab()->GetEntryCount());
+ ASSERT_EQ(GURL("http://bar/1"), iter->second.tab()->
GetEntryAtIndex(0)->virtual_url());
- ASSERT_EQ(GURL("http://bar/2"), iter->second.tab()->controller().
+ ASSERT_EQ(GURL("http://bar/2"), iter->second.tab()->
GetEntryAtIndex(1)->virtual_url());
}
diff --git a/chrome/browser/ui/browser_synced_window_delegate.cc b/chrome/browser/ui/browser_synced_window_delegate.cc
index d9a0947..2db073b 100644
--- a/chrome/browser/ui/browser_synced_window_delegate.cc
+++ b/chrome/browser/ui/browser_synced_window_delegate.cc
@@ -39,16 +39,21 @@ BrowserSyncedWindowDelegate::BrowserSyncedWindowDelegate(Browser* browser)
BrowserSyncedWindowDelegate::~BrowserSyncedWindowDelegate() {}
-bool BrowserSyncedWindowDelegate::IsTabContentsWrapperPinned(
- const TabContentsWrapper* tab) const {
- int index = browser_->GetIndexOfController(&tab->controller());
- DCHECK(index != TabStripModel::kNoTab);
- return browser_->tabstrip_model()->IsTabPinned(index);
+bool BrowserSyncedWindowDelegate::IsTabPinned(
+ const browser_sync::SyncedTabDelegate* tab) const {
+ for (int i = 0; i < browser_->tabstrip_model()->count(); i++) {
+ browser_sync::SyncedTabDelegate* current =
+ browser_->tabstrip_model()->GetTabContentsAt(i)->synced_tab_delegate();
+ if (tab == current)
+ return browser_->tabstrip_model()->IsTabPinned(i);
+ }
+ NOTREACHED();
+ return false;
}
-TabContentsWrapper* BrowserSyncedWindowDelegate::GetTabContentsWrapperAt(
+browser_sync::SyncedTabDelegate* BrowserSyncedWindowDelegate::GetTabAt(
int index) const {
- return browser_->GetTabContentsWrapperAt(index);
+ return browser_->GetTabContentsWrapperAt(index)->synced_tab_delegate();
}
bool BrowserSyncedWindowDelegate::HasWindow() const {
diff --git a/chrome/browser/ui/browser_synced_window_delegate.h b/chrome/browser/ui/browser_synced_window_delegate.h
index b23e211..d598b97 100644
--- a/chrome/browser/ui/browser_synced_window_delegate.h
+++ b/chrome/browser/ui/browser_synced_window_delegate.h
@@ -11,7 +11,10 @@
#include "chrome/browser/sync/glue/synced_window_delegate.h"
class Browser;
-class TabContentsWrapper;
+
+namespace browser_sync {
+class SyncedTabDelegate;
+}
// A BrowserSyncedWindowDelegate is the Browser-based implementation of
// SyncedWindowDelegate.
@@ -21,9 +24,6 @@ class BrowserSyncedWindowDelegate : public browser_sync::SyncedWindowDelegate {
virtual ~BrowserSyncedWindowDelegate();
// SyncedWindowDelegate:
- virtual bool IsTabContentsWrapperPinned(
- const TabContentsWrapper* tab) const OVERRIDE;
- virtual TabContentsWrapper* GetTabContentsWrapperAt(int index) const OVERRIDE;
virtual bool HasWindow() const OVERRIDE;
virtual const SessionID& GetSessionId() const OVERRIDE;
virtual int GetTabCount() const OVERRIDE;
@@ -31,6 +31,9 @@ class BrowserSyncedWindowDelegate : public browser_sync::SyncedWindowDelegate {
virtual bool IsApp() const OVERRIDE;
virtual bool IsTypeTabbed() const OVERRIDE;
virtual bool IsTypePopup() const OVERRIDE;
+ virtual bool IsTabPinned(
+ const browser_sync::SyncedTabDelegate* tab) const OVERRIDE;
+ virtual browser_sync::SyncedTabDelegate* GetTabAt(int index) const OVERRIDE;
private:
Browser* browser_;
diff --git a/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc b/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc
index 3f05b60..8479a5e 100644
--- a/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc
+++ b/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc
@@ -34,6 +34,7 @@
#include "chrome/browser/renderer_preferences_util.h"
#include "chrome/browser/sessions/restore_tab_helper.h"
#include "chrome/browser/safe_browsing/client_side_detection_host.h"
+#include "chrome/browser/sync/glue/synced_tab_delegate.h"
#include "chrome/browser/tab_contents/infobar.h"
#include "chrome/browser/tab_contents/infobar_delegate.h"
#include "chrome/browser/tab_contents/insecure_content_infobar_delegate.h"
@@ -107,6 +108,8 @@ TabContentsWrapper::TabContentsWrapper(TabContents* contents)
: TabContentsObserver(contents),
delegate_(NULL),
infobars_enabled_(true),
+ ALLOW_THIS_IN_INITIALIZER_LIST(
+ synced_tab_delegate_(new TabContentsWrapperSyncedTabDelegate(this))),
in_destructor_(false),
tab_contents_(contents) {
DCHECK(contents);
diff --git a/chrome/browser/ui/tab_contents/tab_contents_wrapper.h b/chrome/browser/ui/tab_contents/tab_contents_wrapper.h
index 59245b8..e027200 100644
--- a/chrome/browser/ui/tab_contents/tab_contents_wrapper.h
+++ b/chrome/browser/ui/tab_contents/tab_contents_wrapper.h
@@ -16,6 +16,7 @@
#include "chrome/browser/printing/print_view_manager.h"
#include "content/browser/tab_contents/tab_contents.h"
#include "content/browser/tab_contents/tab_contents_observer.h"
+#include "chrome/browser/ui/tab_contents/tab_contents_wrapper_synced_tab_delegate.h"
#include "content/common/notification_registrar.h"
namespace prerender {
@@ -104,6 +105,10 @@ class TabContentsWrapper : public TabContentsObserver,
TabContentsWrapperDelegate* delegate() const { return delegate_; }
void set_delegate(TabContentsWrapperDelegate* d) { delegate_ = d; }
+ browser_sync::SyncedTabDelegate* synced_tab_delegate() const {
+ return synced_tab_delegate_.get();
+ }
+
TabContents* tab_contents() const { return tab_contents_.get(); }
NavigationController& controller() const {
return tab_contents()->controller();
@@ -273,6 +278,9 @@ class TabContentsWrapper : public TabContentsObserver,
NotificationRegistrar registrar_;
PrefChangeRegistrar pref_change_registrar_;
+ // Helper which implements the SyncedTabDelegate interface.
+ scoped_ptr<TabContentsWrapperSyncedTabDelegate> synced_tab_delegate_;
+
// Data for current page -----------------------------------------------------
// Shows an info-bar to users when they search from a known search engine and
diff --git a/chrome/browser/ui/tab_contents/tab_contents_wrapper_synced_tab_delegate.cc b/chrome/browser/ui/tab_contents/tab_contents_wrapper_synced_tab_delegate.cc
new file mode 100644
index 0000000..72304f8
--- /dev/null
+++ b/chrome/browser/ui/tab_contents/tab_contents_wrapper_synced_tab_delegate.cc
@@ -0,0 +1,70 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/tab_contents/tab_contents_wrapper_synced_tab_delegate.h"
+
+#include "content/browser/tab_contents/navigation_controller.h"
+#include "content/browser/tab_contents/tab_contents.h"
+#include "chrome/browser/extensions/extension_tab_helper.h"
+#include "chrome/browser/sessions/restore_tab_helper.h"
+#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
+
+
+TabContentsWrapperSyncedTabDelegate::TabContentsWrapperSyncedTabDelegate(
+ TabContentsWrapper* tab_contents_wrapper)
+ : tab_contents_wrapper_(tab_contents_wrapper) {}
+
+TabContentsWrapperSyncedTabDelegate::~TabContentsWrapperSyncedTabDelegate() {}
+
+const SessionID& TabContentsWrapperSyncedTabDelegate::GetWindowId() const {
+ return tab_contents_wrapper_->restore_tab_helper()->window_id();
+}
+
+const SessionID& TabContentsWrapperSyncedTabDelegate::GetSessionId() const {
+ return tab_contents_wrapper_->restore_tab_helper()->session_id();
+}
+
+bool TabContentsWrapperSyncedTabDelegate::IsBeingDestroyed() const {
+ return tab_contents_wrapper_->tab_contents()->is_being_destroyed();
+}
+
+Profile* TabContentsWrapperSyncedTabDelegate::profile() const {
+ return tab_contents_wrapper_->profile();
+}
+
+bool TabContentsWrapperSyncedTabDelegate::HasExtensionAppId() const {
+ return (tab_contents_wrapper_->extension_tab_helper() &&
+ tab_contents_wrapper_->extension_tab_helper()->extension_app());
+}
+
+const std::string& TabContentsWrapperSyncedTabDelegate::GetExtensionAppId()
+ const {
+ DCHECK(HasExtensionAppId());
+ return tab_contents_wrapper_->extension_tab_helper()->extension_app()->id();
+}
+
+int TabContentsWrapperSyncedTabDelegate::GetCurrentEntryIndex() const {
+ return tab_contents_wrapper_->controller().GetCurrentEntryIndex();
+}
+
+int TabContentsWrapperSyncedTabDelegate::GetEntryCount() const {
+ return tab_contents_wrapper_->controller().entry_count();
+}
+
+int TabContentsWrapperSyncedTabDelegate::GetPendingEntryIndex() const {
+ return tab_contents_wrapper_->controller().pending_entry_index();
+}
+
+NavigationEntry* TabContentsWrapperSyncedTabDelegate::GetPendingEntry() const {
+ return tab_contents_wrapper_->controller().pending_entry();
+}
+
+NavigationEntry* TabContentsWrapperSyncedTabDelegate::GetEntryAtIndex(int i)
+ const {
+ return tab_contents_wrapper_->controller().GetEntryAtIndex(i);
+}
+
+NavigationEntry* TabContentsWrapperSyncedTabDelegate::GetActiveEntry() const {
+ return tab_contents_wrapper_->controller().GetActiveEntry();
+}
diff --git a/chrome/browser/ui/tab_contents/tab_contents_wrapper_synced_tab_delegate.h b/chrome/browser/ui/tab_contents/tab_contents_wrapper_synced_tab_delegate.h
new file mode 100644
index 0000000..b3e8416
--- /dev/null
+++ b/chrome/browser/ui/tab_contents/tab_contents_wrapper_synced_tab_delegate.h
@@ -0,0 +1,42 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_UI_TAB_CONTENTS_TAB_CONTENTS_WRAPPER_SYNCED_TAB_DELEGATE_H_
+#define CHROME_BROWSER_UI_TAB_CONTENTS_TAB_CONTENTS_WRAPPER_SYNCED_TAB_DELEGATE_H_
+#pragma once
+
+#include "base/compiler_specific.h"
+#include "chrome/browser/sessions/session_id.h"
+#include "chrome/browser/sync/glue/synced_tab_delegate.h"
+
+class TabContentsWrapper;
+
+class TabContentsWrapperSyncedTabDelegate
+ : public browser_sync::SyncedTabDelegate {
+ public:
+ explicit TabContentsWrapperSyncedTabDelegate(
+ TabContentsWrapper* tab_contents_wrapper);
+ virtual ~TabContentsWrapperSyncedTabDelegate();
+
+ // Methods from SyncedTabDelegate.
+ virtual const SessionID& GetWindowId() const OVERRIDE;
+ virtual const SessionID& GetSessionId() const OVERRIDE;
+ virtual bool IsBeingDestroyed() const OVERRIDE;
+ virtual Profile* profile() const OVERRIDE;
+ virtual bool HasExtensionAppId() const OVERRIDE;
+ virtual const std::string& GetExtensionAppId() const OVERRIDE;
+ virtual int GetCurrentEntryIndex() const OVERRIDE;
+ virtual int GetEntryCount() const OVERRIDE;
+ virtual int GetPendingEntryIndex() const OVERRIDE;
+ virtual NavigationEntry* GetPendingEntry() const OVERRIDE;
+ virtual NavigationEntry* GetEntryAtIndex(int i) const OVERRIDE;
+ virtual NavigationEntry* GetActiveEntry() const OVERRIDE;
+
+ private:
+ TabContentsWrapper* tab_contents_wrapper_;
+
+ DISALLOW_COPY_AND_ASSIGN(TabContentsWrapperSyncedTabDelegate);
+};
+
+#endif // CHROME_BROWSER_UI_TAB_CONTENTS_TAB_CONTENTS_WRAPPER_SYNCED_TAB_DELEGATE_H_
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index cccb2a4..76b6c58 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -2973,6 +2973,8 @@
'browser/ui/tab_contents/tab_contents_wrapper.h',
'browser/ui/tab_contents/tab_contents_wrapper_delegate.cc',
'browser/ui/tab_contents/tab_contents_wrapper_delegate.h',
+ 'browser/ui/tab_contents/tab_contents_wrapper_synced_tab_delegate.cc',
+ 'browser/ui/tab_contents/tab_contents_wrapper_synced_tab_delegate.h',
'browser/ui/tabs/dock_info.cc',
'browser/ui/tabs/dock_info.h',
'browser/ui/tabs/dock_info_gtk.cc',