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_UI_ANDROID_TAB_MODEL_TAB_MODEL_H_
6 #define CHROME_BROWSER_UI_ANDROID_TAB_MODEL_TAB_MODEL_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "chrome/browser/ui/toolbar/toolbar_model_delegate.h"
10 #include "components/sessions/session_id.h"
11 #include "components/sync_driver/glue/synced_window_delegate.h"
12 #include "components/toolbar/toolbar_model.h"
13 #include "content/public/browser/notification_observer.h"
14 #include "content/public/browser/notification_registrar.h"
16 namespace browser_sync
{
17 class SyncedWindowDelegate
;
18 class SyncedWindowDelegateAndroid
;
28 // Abstract representation of a Tab Model for Android. Since Android does
29 // not use Browser/BrowserList, this is required to allow Chrome to interact
30 // with Android's Tabs and Tab Model.
31 class TabModel
: public content::NotificationObserver
{
33 virtual Profile
* GetProfile() const;
34 virtual bool IsOffTheRecord() const;
35 virtual browser_sync::SyncedWindowDelegate
* GetSyncedWindowDelegate() const;
36 virtual SessionID::id_type
GetSessionId() const;
38 virtual int GetTabCount() const = 0;
39 virtual int GetActiveIndex() const = 0;
40 virtual content::WebContents
* GetActiveWebContents() const;
41 virtual content::WebContents
* GetWebContentsAt(int index
) const = 0;
42 // This will return NULL if the tab has not yet been initialized.
43 virtual TabAndroid
* GetTabAt(int index
) const = 0;
45 virtual void SetActiveIndex(int index
) = 0;
46 virtual void CloseTabAt(int index
) = 0;
48 // Used for restoring tabs from synced foreign sessions.
49 virtual void CreateTab(content::WebContents
* web_contents
,
50 int parent_tab_id
) = 0;
52 // Used by Developer Tools to create a new tab with a given URL.
53 // Replaces CreateTabForTesting.
54 virtual content::WebContents
* CreateNewTabForDevTools(const GURL
& url
) = 0;
56 // Return true if we are currently restoring sessions asynchronously.
57 virtual bool IsSessionRestoreInProgress() const = 0;
60 explicit TabModel(Profile
* profile
);
63 // Instructs the TabModel to broadcast a notification that all tabs are now
64 // loaded from storage.
65 void BroadcastSessionRestoreComplete();
67 ToolbarModel
* GetToolbarModel();
70 // Determines how TabModel will interact with the profile.
71 void Observe(int type
,
72 const content::NotificationSource
& source
,
73 const content::NotificationDetails
& details
) override
;
75 // The profile associated with this TabModel.
78 // Describes if this TabModel contains an off-the-record profile.
79 bool is_off_the_record_
;
81 // The SyncedWindowDelegate associated with this TabModel.
82 scoped_ptr
<browser_sync::SyncedWindowDelegateAndroid
> synced_window_delegate_
;
84 // Unique identifier of this TabModel for session restore. This id is only
85 // unique within the current session, and is not guaranteed to be unique
87 SessionID session_id_
;
89 // The Registrar used to register TabModel for notifications.
90 content::NotificationRegistrar registrar_
;
92 DISALLOW_COPY_AND_ASSIGN(TabModel
);
95 #endif // CHROME_BROWSER_UI_ANDROID_TAB_MODEL_TAB_MODEL_H_