Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: chrome/browser/ui/sync/tab_contents_synced_tab_delegate.cc

Issue 11030004: Switch TabContentsSyncedTabDelegate to use WebContentsUserData. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase, added TODO Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/sync/tab_contents_synced_tab_delegate.h" 5 #include "chrome/browser/ui/sync/tab_contents_synced_tab_delegate.h"
6 6
7 #include "base/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "chrome/browser/extensions/tab_helper.h" 8 #include "chrome/browser/extensions/tab_helper.h"
9 #include "chrome/browser/sessions/session_tab_helper.h" 9 #include "chrome/browser/sessions/session_tab_helper.h"
10 #include "chrome/browser/sync/glue/synced_window_delegate.h" 10 #include "chrome/browser/sync/glue/synced_window_delegate.h"
11 #include "chrome/browser/ui/tab_contents/tab_contents.h" 11 #include "chrome/browser/ui/tab_contents/tab_contents.h"
12 #include "chrome/common/extensions/extension.h" 12 #include "chrome/common/extensions/extension.h"
13 #include "content/public/browser/navigation_controller.h" 13 #include "content/public/browser/navigation_controller.h"
14 #include "content/public/browser/navigation_entry.h" 14 #include "content/public/browser/navigation_entry.h"
15 #include "content/public/browser/web_contents.h" 15 #include "content/public/browser/web_contents.h"
16 16
17 using content::NavigationEntry; 17 using content::NavigationEntry;
18 18
19 DEFINE_WEB_CONTENTS_USER_DATA_KEY(TabContentsSyncedTabDelegate)
20
19 TabContentsSyncedTabDelegate::TabContentsSyncedTabDelegate( 21 TabContentsSyncedTabDelegate::TabContentsSyncedTabDelegate(
20 TabContents* tab_contents) 22 content::WebContents* web_contents)
21 : tab_contents_(tab_contents) {} 23 : web_contents_(web_contents) {}
22 24
23 TabContentsSyncedTabDelegate::~TabContentsSyncedTabDelegate() {} 25 TabContentsSyncedTabDelegate::~TabContentsSyncedTabDelegate() {}
24 26
25 SessionID::id_type TabContentsSyncedTabDelegate::GetWindowId() const { 27 SessionID::id_type TabContentsSyncedTabDelegate::GetWindowId() const {
26 return SessionTabHelper::FromWebContents(tab_contents_->web_contents())-> 28 return SessionTabHelper::FromWebContents(web_contents_)->window_id().id();
27 window_id().id();
28 } 29 }
29 30
30 SessionID::id_type TabContentsSyncedTabDelegate::GetSessionId() const { 31 SessionID::id_type TabContentsSyncedTabDelegate::GetSessionId() const {
31 return SessionTabHelper::FromWebContents(tab_contents_->web_contents())-> 32 return SessionTabHelper::FromWebContents(web_contents_)->session_id().id();
32 session_id().id();
33 } 33 }
34 34
35 bool TabContentsSyncedTabDelegate::IsBeingDestroyed() const { 35 bool TabContentsSyncedTabDelegate::IsBeingDestroyed() const {
36 return tab_contents_->in_destructor(); 36 // TODO(avi): Switch to just the web contents call when the
37 // SessionChangeProcessor is switched to NOTIFICATION_WEB_CONTENTS_DESTROYED
38 // from NOTIFICATION_TAB_CONTENTS_DESTROYED.
39 TabContents* tab_contents = TabContents::FromWebContents(web_contents_);
40 return tab_contents->in_destructor() || web_contents_->IsBeingDestroyed();
37 } 41 }
38 42
39 Profile* TabContentsSyncedTabDelegate::profile() const { 43 Profile* TabContentsSyncedTabDelegate::profile() const {
40 return tab_contents_->profile(); 44 return Profile::FromBrowserContext(web_contents_->GetBrowserContext());
41 } 45 }
42 46
43 std::string TabContentsSyncedTabDelegate::GetExtensionAppId() const { 47 std::string TabContentsSyncedTabDelegate::GetExtensionAppId() const {
44 const scoped_refptr<const extensions::Extension> extension_app( 48 const scoped_refptr<const extensions::Extension> extension_app(
45 extensions::TabHelper::FromWebContents( 49 extensions::TabHelper::FromWebContents(web_contents_)->extension_app());
46 tab_contents_->web_contents())->extension_app());
47 return (extension_app.get() ? extension_app->id() : ""); 50 return (extension_app.get() ? extension_app->id() : "");
48 } 51 }
49 52
50 int TabContentsSyncedTabDelegate::GetCurrentEntryIndex() const { 53 int TabContentsSyncedTabDelegate::GetCurrentEntryIndex() const {
51 return tab_contents_->web_contents()->GetController().GetCurrentEntryIndex(); 54 return web_contents_->GetController().GetCurrentEntryIndex();
52 } 55 }
53 56
54 int TabContentsSyncedTabDelegate::GetEntryCount() const { 57 int TabContentsSyncedTabDelegate::GetEntryCount() const {
55 return tab_contents_->web_contents()->GetController().GetEntryCount(); 58 return web_contents_->GetController().GetEntryCount();
56 } 59 }
57 60
58 int TabContentsSyncedTabDelegate::GetPendingEntryIndex() const { 61 int TabContentsSyncedTabDelegate::GetPendingEntryIndex() const {
59 return tab_contents_->web_contents()->GetController().GetPendingEntryIndex(); 62 return web_contents_->GetController().GetPendingEntryIndex();
60 } 63 }
61 64
62 NavigationEntry* TabContentsSyncedTabDelegate::GetPendingEntry() const { 65 NavigationEntry* TabContentsSyncedTabDelegate::GetPendingEntry() const {
63 return 66 return web_contents_->GetController().GetPendingEntry();
64 tab_contents_->web_contents()->GetController().GetPendingEntry();
65 } 67 }
66 68
67 NavigationEntry* TabContentsSyncedTabDelegate::GetEntryAtIndex(int i) 69 NavigationEntry* TabContentsSyncedTabDelegate::GetEntryAtIndex(int i) const {
68 const { 70 return web_contents_->GetController().GetEntryAtIndex(i);
69 return tab_contents_->web_contents()->GetController().GetEntryAtIndex(i);
70 } 71 }
71 72
72 NavigationEntry* TabContentsSyncedTabDelegate::GetActiveEntry() const { 73 NavigationEntry* TabContentsSyncedTabDelegate::GetActiveEntry() const {
73 return tab_contents_->web_contents()->GetController().GetActiveEntry(); 74 return web_contents_->GetController().GetActiveEntry();
74 } 75 }
75 76
76 bool TabContentsSyncedTabDelegate::IsPinned() const { 77 bool TabContentsSyncedTabDelegate::IsPinned() const {
77 const browser_sync::SyncedWindowDelegate* window = 78 const browser_sync::SyncedWindowDelegate* window =
78 browser_sync::SyncedWindowDelegate::FindSyncedWindowDelegateWithId( 79 browser_sync::SyncedWindowDelegate::FindSyncedWindowDelegateWithId(
79 GetWindowId()); 80 GetWindowId());
80 // We might not have a parent window, e.g. Developer Tools. 81 // We might not have a parent window, e.g. Developer Tools.
81 return window ? window->IsTabPinned(this) : false; 82 return window ? window->IsTabPinned(this) : false;
82 } 83 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/sync/tab_contents_synced_tab_delegate.h ('k') | chrome/browser/ui/tab_contents/tab_contents.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698