| OLD | NEW |
| 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/android/tab_model/tab_model.h" | 5 #include "chrome/browser/ui/android/tab_model/tab_model.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/sync/glue/synced_window_delegate_android.h" | 11 #include "chrome/browser/sync/glue/synced_window_delegate_android.h" |
| 12 #include "chrome/browser/sync/profile_sync_service_factory.h" | 12 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 13 #include "components/browser_sync/browser/profile_sync_service.h" | 13 #include "components/browser_sync/browser/profile_sync_service.h" |
| 14 #include "components/toolbar/toolbar_model_impl.h" | 14 #include "components/toolbar/toolbar_model_impl.h" |
| 15 #include "content/public/browser/notification_service.h" | 15 #include "content/public/browser/notification_service.h" |
| 16 | 16 |
| 17 using content::NotificationService; | 17 using content::NotificationService; |
| 18 | 18 |
| 19 // Keep this in sync with | 19 // Keep this in sync with |
| 20 // chrome/android/java/src/org/chromium/chrome/browser/tabmodel/TabList.java | 20 // chrome/android/java/src/org/chromium/chrome/browser/tabmodel/TabList.java |
| 21 static int INVALID_TAB_INDEX = -1; | 21 static int INVALID_TAB_INDEX = -1; |
| 22 | 22 |
| 23 TabModel::TabModel(Profile* profile) | 23 TabModel::TabModel(Profile* profile) |
| 24 : profile_(profile), | 24 : profile_(profile), |
| 25 live_tab_context_(new AndroidLiveTabContext(this)), | 25 live_tab_context_(new AndroidLiveTabContext(this)), |
| 26 synced_window_delegate_( | 26 synced_window_delegate_( |
| 27 new browser_sync::SyncedWindowDelegateAndroid(this)) { | 27 new browser_sync::SyncedWindowDelegateAndroid(this)) { |
| 28 | |
| 29 if (profile) { | 28 if (profile) { |
| 30 // A normal Profile creates an OTR profile if it does not exist when | 29 // A normal Profile creates an OTR profile if it does not exist when |
| 31 // GetOffTheRecordProfile() is called, so we guard it with | 30 // GetOffTheRecordProfile() is called, so we guard it with |
| 32 // HasOffTheRecordProfile(). An OTR profile returns itself when you call | 31 // HasOffTheRecordProfile(). An OTR profile returns itself when you call |
| 33 // GetOffTheRecordProfile(). | 32 // GetOffTheRecordProfile(). |
| 34 is_off_the_record_ = (profile->HasOffTheRecordProfile() && | 33 is_off_the_record_ = (profile->HasOffTheRecordProfile() && |
| 35 profile == profile->GetOffTheRecordProfile()); | 34 profile == profile->GetOffTheRecordProfile()); |
| 36 | 35 |
| 37 // A profile can be destroyed, for example in the case of closing all | 36 // A profile can be destroyed, for example in the case of closing all |
| 38 // incognito tabs. We therefore must listen for when this happens, and | 37 // incognito tabs. We therefore must listen for when this happens, and |
| (...skipping 11 matching lines...) Expand all Loading... |
| 50 } | 49 } |
| 51 | 50 |
| 52 Profile* TabModel::GetProfile() const { | 51 Profile* TabModel::GetProfile() const { |
| 53 return profile_; | 52 return profile_; |
| 54 } | 53 } |
| 55 | 54 |
| 56 bool TabModel::IsOffTheRecord() const { | 55 bool TabModel::IsOffTheRecord() const { |
| 57 return is_off_the_record_; | 56 return is_off_the_record_; |
| 58 } | 57 } |
| 59 | 58 |
| 60 browser_sync::SyncedWindowDelegate* TabModel::GetSyncedWindowDelegate() const { | 59 sync_sessions::SyncedWindowDelegate* TabModel::GetSyncedWindowDelegate() const { |
| 61 return synced_window_delegate_.get(); | 60 return synced_window_delegate_.get(); |
| 62 } | 61 } |
| 63 | 62 |
| 64 SessionID::id_type TabModel::GetSessionId() const { | 63 SessionID::id_type TabModel::GetSessionId() const { |
| 65 return session_id_.id(); | 64 return session_id_.id(); |
| 66 } | 65 } |
| 67 | 66 |
| 68 const SessionID& TabModel::SessionId() const { | 67 const SessionID& TabModel::SessionId() const { |
| 69 return session_id_; | 68 return session_id_; |
| 70 } | 69 } |
| 71 | 70 |
| 72 sessions::LiveTabContext* TabModel::GetLiveTabContext() const{ | 71 sessions::LiveTabContext* TabModel::GetLiveTabContext() const { |
| 73 return live_tab_context_.get(); | 72 return live_tab_context_.get(); |
| 74 } | 73 } |
| 75 | 74 |
| 76 content::WebContents* TabModel::GetActiveWebContents() const { | 75 content::WebContents* TabModel::GetActiveWebContents() const { |
| 77 int active_index = GetActiveIndex(); | 76 int active_index = GetActiveIndex(); |
| 78 if (active_index == INVALID_TAB_INDEX) | 77 if (active_index == INVALID_TAB_INDEX) |
| 79 return nullptr; | 78 return nullptr; |
| 80 return GetWebContentsAt(active_index); | 79 return GetWebContentsAt(active_index); |
| 81 } | 80 } |
| 82 | 81 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 110 if (is_off_the_record_) { | 109 if (is_off_the_record_) { |
| 111 Profile* profile = content::Source<Profile>(source).ptr(); | 110 Profile* profile = content::Source<Profile>(source).ptr(); |
| 112 if (profile && profile->IsOffTheRecord()) | 111 if (profile && profile->IsOffTheRecord()) |
| 113 profile_ = profile; | 112 profile_ = profile; |
| 114 } | 113 } |
| 115 break; | 114 break; |
| 116 default: | 115 default: |
| 117 NOTREACHED(); | 116 NOTREACHED(); |
| 118 } | 117 } |
| 119 } | 118 } |
| OLD | NEW |