tab_model.h revision 58537e28ecd584eab876aee8be7156509866d23a
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#ifndef CHROME_BROWSER_UI_ANDROID_TAB_MODEL_TAB_MODEL_H_
6#define CHROME_BROWSER_UI_ANDROID_TAB_MODEL_TAB_MODEL_H_
7
8#include "base/memory/scoped_ptr.h"
9#include "chrome/browser/sessions/session_id.h"
10#include "chrome/browser/sync/glue/synced_tab_delegate.h"
11#include "chrome/browser/ui/toolbar/toolbar_model.h"
12#include "chrome/browser/ui/toolbar/toolbar_model_delegate.h"
13#include "content/public/browser/notification_observer.h"
14#include "content/public/browser/notification_registrar.h"
15
16namespace browser_sync {
17class SyncedWindowDelegate;
18class SyncedWindowDelegateAndroid;
19class SyncedTabDelegate;
20}
21
22namespace content {
23class WebContents;
24}
25
26class Profile;
27
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.
31class TabModel : public content::NotificationObserver,
32                 public ToolbarModelDelegate {
33 public:
34  explicit TabModel(Profile* profile);
35  virtual ~TabModel();
36
37  // Implementation of ToolbarDelegate
38  virtual content::WebContents* GetActiveWebContents() const OVERRIDE;
39
40  virtual Profile* GetProfile() const;
41  virtual bool IsOffTheRecord() const;
42  virtual browser_sync::SyncedWindowDelegate* GetSyncedWindowDelegate() const;
43  virtual SessionID::id_type GetSessionId() const;
44
45  virtual int GetTabCount() const = 0;
46  virtual int GetActiveIndex() const = 0;
47  virtual content::WebContents* GetWebContentsAt(int index) const = 0;
48  virtual browser_sync::SyncedTabDelegate* GetTabAt(int index) const = 0;
49
50  // Used for restoring tabs from synced foreign sessions.
51  virtual void CreateTab(content::WebContents* web_contents) = 0;
52
53  // Used for creating a new tab with a given URL.
54  virtual content::WebContents* CreateTabForTesting(const GURL& url) = 0;
55
56  // Return true if we are currently restoring sessions asynchronously.
57  virtual bool IsSessionRestoreInProgress() const = 0;
58
59  virtual void OpenClearBrowsingData() const = 0;
60
61  // Returns search terms extracted from the current url if possible.
62  string16 GetSearchTermsForCurrentTab();
63
64  // Returns the parameter that is used to trigger query extraction.
65  std::string GetQueryExtractionParam();
66
67  // Calls through to the ToolbarModel's GetCorpusNameForMobile -- see
68  // comments in toolbar_model.h.
69  string16 GetCorpusNameForCurrentTab();
70
71 protected:
72  // Instructs the TabModel to broadcast a notification that all tabs are now
73  // loaded from storage.
74  void BroadcastSessionRestoreComplete();
75
76  ToolbarModel* GetToolbarModel();
77
78 private:
79  // Determines how TabModel will interact with the profile.
80  virtual void Observe(int type,
81                       const content::NotificationSource& source,
82                       const content::NotificationDetails& details) OVERRIDE;
83
84  // The profile associated with this TabModel.
85  Profile* profile_;
86
87  // Describes if this TabModel contains an off-the-record profile.
88  bool is_off_the_record_;
89
90  // The SyncedWindowDelegate associated with this TabModel.
91  scoped_ptr<browser_sync::SyncedWindowDelegateAndroid> synced_window_delegate_;
92
93  scoped_ptr<ToolbarModel> toolbar_model_;
94
95  // Unique identifier of this TabModel for session restore. This id is only
96  // unique within the current session, and is not guaranteed to be unique
97  // across sessions.
98  SessionID session_id_;
99
100  // The Registrar used to register TabModel for notifications.
101  content::NotificationRegistrar registrar_;
102
103  DISALLOW_COPY_AND_ASSIGN(TabModel);
104};
105
106#endif  // CHROME_BROWSER_UI_ANDROID_TAB_MODEL_TAB_MODEL_H_
107