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 #ifndef CHROME_BROWSER_SYNC_GLUE_SYNCED_TAB_DELEGATE_H__
6 #define CHROME_BROWSER_SYNC_GLUE_SYNCED_TAB_DELEGATE_H__
11 #include "base/memory/scoped_ptr.h"
12 #include "components/sessions/session_id.h"
13 #include "components/sync_driver/sessions/synced_window_delegates_getter.h"
18 class NavigationEntry
;
22 namespace browser_sync
{
23 class SyncedWindowDelegate
;
25 // A SyncedTabDelegate is used to insulate the sync code from depending
26 // directly on WebContents, NavigationController, and the extensions TabHelper.
27 class SyncedTabDelegate
{
29 virtual ~SyncedTabDelegate();
31 // Methods from TabContents.
33 virtual SessionID::id_type
GetWindowId() const = 0;
34 virtual SessionID::id_type
GetSessionId() const = 0;
35 virtual bool IsBeingDestroyed() const = 0;
36 virtual Profile
* profile() const = 0;
38 // Method derived from extensions TabHelper.
40 virtual std::string
GetExtensionAppId() const = 0;
42 // Methods from NavigationController.
44 virtual int GetCurrentEntryIndex() const = 0;
45 virtual int GetEntryCount() const = 0;
46 virtual int GetPendingEntryIndex() const = 0;
47 virtual content::NavigationEntry
* GetPendingEntry() const = 0;
48 virtual content::NavigationEntry
* GetEntryAtIndex(int i
) const = 0;
49 virtual content::NavigationEntry
* GetActiveEntry() const = 0;
51 // The idea here is that GetEntryAtIndex may not always return the pending
52 // entry when asked for the entry at the pending index. These convinience
53 // methods will check for this case and then call the correct entry accessor.
54 content::NavigationEntry
* GetCurrentEntryMaybePending() const;
55 content::NavigationEntry
* GetEntryAtIndexMaybePending(int i
) const;
57 // Supervised user related methods.
59 virtual bool ProfileIsSupervised() const = 0;
60 virtual const std::vector
<const content::NavigationEntry
*>*
61 GetBlockedNavigations() const = 0;
63 virtual bool IsPinned() const = 0;
64 virtual bool HasWebContents() const = 0;
65 virtual content::WebContents
* GetWebContents() const = 0;
67 // Session sync related methods.
68 virtual int GetSyncId() const = 0;
69 virtual void SetSyncId(int sync_id
) = 0;
71 // Returns true if this tab should be synchronized.
72 bool ShouldSync() const;
74 // Sets the window getter. This must be called before any of the sync or
75 // supervised user methods on this class are called. It is currently set when
76 // the SyncTabDelegate is retrieved from WebContents via ImplFromWebContents.
77 void SetSyncedWindowGetter(scoped_ptr
<SyncedWindowDelegatesGetter
> getter
);
79 // Returns the SyncedTabDelegate associated with WebContents.
80 static SyncedTabDelegate
* ImplFromWebContents(
81 content::WebContents
* web_contents
);
86 // Overridden by the tests to avoid interaction with static state.
87 virtual const SyncedWindowDelegate
* GetSyncedWindowDelegate() const;
90 // A getter for accessing the associated SyncedWindowDelegate.
91 scoped_ptr
<SyncedWindowDelegatesGetter
> synced_window_getter_
;
94 } // namespace browser_sync
96 #endif // CHROME_BROWSER_SYNC_GLUE_SYNCED_TAB_DELEGATE_H__