From 0ed0b7e7673321d88c2aacdd1034086e138a6688 Mon Sep 17 00:00:00 2001 From: "dtrainor@chromium.org" Date: Wed, 21 Nov 2012 00:30:04 +0000 Subject: Refactor TabModel to not hold a profile. If we close all of the tabs in the incognito profile, the profile goes away. We need to not cache the profile as we have a bad pointer. BUG= NOTRY=true Review URL: https://chromiumcodereview.appspot.com/11417089 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@168930 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/sync/glue/synced_window_delegate_android.cc | 2 +- chrome/browser/ui/android/tab_model/tab_model.cc | 13 ++++++++----- chrome/browser/ui/android/tab_model/tab_model.h | 1 + chrome/browser/ui/android/tab_model/tab_model_list.cc | 7 +++++-- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/chrome/browser/sync/glue/synced_window_delegate_android.cc b/chrome/browser/sync/glue/synced_window_delegate_android.cc index 68ef69a..4d8f4ba 100644 --- a/chrome/browser/sync/glue/synced_window_delegate_android.cc +++ b/chrome/browser/sync/glue/synced_window_delegate_android.cc @@ -44,7 +44,7 @@ SyncedWindowDelegateAndroid::SyncedWindowDelegateAndroid( SyncedWindowDelegateAndroid::~SyncedWindowDelegateAndroid() {} bool SyncedWindowDelegateAndroid::HasWindow() const { - return !tab_model_->GetProfile()->IsOffTheRecord(); + return !tab_model_->IsOffTheRecord(); } SessionID::id_type SyncedWindowDelegateAndroid::GetSessionId() const { diff --git a/chrome/browser/ui/android/tab_model/tab_model.cc b/chrome/browser/ui/android/tab_model/tab_model.cc index 57f6fff..5bf6a80 100644 --- a/chrome/browser/ui/android/tab_model/tab_model.cc +++ b/chrome/browser/ui/android/tab_model/tab_model.cc @@ -23,9 +23,12 @@ TabModel::~TabModel() { } void TabModel::BroadcastSessionRestoreComplete() { - DCHECK(GetProfile()); - NotificationService::current()->Notify( - chrome::NOTIFICATION_SESSION_RESTORE_COMPLETE, - content::Source(GetProfile()), - NotificationService::NoDetails()); + if (GetProfile()) { + NotificationService::current()->Notify( + chrome::NOTIFICATION_SESSION_RESTORE_COMPLETE, + content::Source(GetProfile()), + NotificationService::NoDetails()); + } else { + NOTREACHED(); + } } diff --git a/chrome/browser/ui/android/tab_model/tab_model.h b/chrome/browser/ui/android/tab_model/tab_model.h index 9c8dc7d..e1e40ee 100644 --- a/chrome/browser/ui/android/tab_model/tab_model.h +++ b/chrome/browser/ui/android/tab_model/tab_model.h @@ -39,6 +39,7 @@ class TabModel { virtual void OpenClearBrowsingData() const = 0; virtual Profile* GetProfile() const = 0; + virtual bool IsOffTheRecord() const = 0; virtual browser_sync::SyncedWindowDelegate* GetSyncedWindowDelegate() = 0; diff --git a/chrome/browser/ui/android/tab_model/tab_model_list.cc b/chrome/browser/ui/android/tab_model/tab_model_list.cc index 7afce2e..aecd9e4 100644 --- a/chrome/browser/ui/android/tab_model/tab_model_list.cc +++ b/chrome/browser/ui/android/tab_model/tab_model_list.cc @@ -34,9 +34,12 @@ void TabModelList::RemoveTabModel(TabModel* tab_model) { TabModel* TabModelList::GetTabModelWithProfile( Profile* profile) { + if (!profile) + return NULL; + for (TabModelList::const_iterator i = TabModelList::begin(); i != TabModelList::end(); ++i) { - if ((*i)->GetProfile()->IsSameProfile(profile)) + if (profile->IsSameProfile((*i)->GetProfile())) return *i; } @@ -57,7 +60,7 @@ TabModel* TabModelList::FindTabModelWithId( bool TabModelList::IsOffTheRecordSessionActive() { for (TabModelList::const_iterator i = TabModelList::begin(); i != TabModelList::end(); i++) { - if ((*i)->GetProfile()->IsOffTheRecord() && (*i)->GetTabCount() > 0) + if ((*i)->IsOffTheRecord() && (*i)->GetTabCount() > 0) return true; } -- cgit v1.1