| 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/ui/toolbar/toolbar_model_impl.h" | 12 #include "chrome/browser/ui/toolbar/toolbar_model_impl.h" |
| 13 #include "content/public/browser/notification_service.h" | 13 #include "content/public/browser/notification_service.h" |
| 14 | 14 |
| 15 using content::NotificationService; | 15 using content::NotificationService; |
| 16 | 16 |
| 17 // Keep this in sync with |
| 18 // chrome/android/java/src/org/chromium/chrome/browser/tabmodel/TabList.java |
| 19 static int INVALID_TAB_INDEX = -1; |
| 20 |
| 17 TabModel::TabModel(Profile* profile) | 21 TabModel::TabModel(Profile* profile) |
| 18 : profile_(profile), | 22 : profile_(profile), |
| 19 synced_window_delegate_( | 23 synced_window_delegate_( |
| 20 new browser_sync::SyncedWindowDelegateAndroid(this)) { | 24 new browser_sync::SyncedWindowDelegateAndroid(this)) { |
| 21 | 25 |
| 22 if (profile) { | 26 if (profile) { |
| 23 // A normal Profile creates an OTR profile if it does not exist when | 27 // A normal Profile creates an OTR profile if it does not exist when |
| 24 // GetOffTheRecordProfile() is called, so we guard it with | 28 // GetOffTheRecordProfile() is called, so we guard it with |
| 25 // HasOffTheRecordProfile(). An OTR profile returns itself when you call | 29 // HasOffTheRecordProfile(). An OTR profile returns itself when you call |
| 26 // GetOffTheRecordProfile(). | 30 // GetOffTheRecordProfile(). |
| (...skipping 24 matching lines...) Expand all Loading... |
| 51 } | 55 } |
| 52 | 56 |
| 53 browser_sync::SyncedWindowDelegate* TabModel::GetSyncedWindowDelegate() const { | 57 browser_sync::SyncedWindowDelegate* TabModel::GetSyncedWindowDelegate() const { |
| 54 return synced_window_delegate_.get(); | 58 return synced_window_delegate_.get(); |
| 55 } | 59 } |
| 56 | 60 |
| 57 SessionID::id_type TabModel::GetSessionId() const { | 61 SessionID::id_type TabModel::GetSessionId() const { |
| 58 return session_id_.id(); | 62 return session_id_.id(); |
| 59 } | 63 } |
| 60 | 64 |
| 65 content::WebContents* TabModel::GetActiveWebContents() const { |
| 66 int active_index = GetActiveIndex(); |
| 67 if (active_index == INVALID_TAB_INDEX) |
| 68 return nullptr; |
| 69 return GetWebContentsAt(active_index); |
| 70 } |
| 71 |
| 61 void TabModel::BroadcastSessionRestoreComplete() { | 72 void TabModel::BroadcastSessionRestoreComplete() { |
| 62 if (profile_) { | 73 if (profile_) { |
| 63 NotificationService::current()->Notify( | 74 NotificationService::current()->Notify( |
| 64 chrome::NOTIFICATION_SESSION_RESTORE_COMPLETE, | 75 chrome::NOTIFICATION_SESSION_RESTORE_COMPLETE, |
| 65 content::Source<Profile>(profile_), | 76 content::Source<Profile>(profile_), |
| 66 NotificationService::NoDetails()); | 77 NotificationService::NoDetails()); |
| 67 } else { | 78 } else { |
| 68 // TODO(nyquist): Uncomment this once downstream Android uses new | 79 // TODO(nyquist): Uncomment this once downstream Android uses new |
| 69 // constructor that takes a Profile* argument. See crbug.com/159704. | 80 // constructor that takes a Profile* argument. See crbug.com/159704. |
| 70 // NOTREACHED(); | 81 // NOTREACHED(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 88 if (is_off_the_record_) { | 99 if (is_off_the_record_) { |
| 89 Profile* profile = content::Source<Profile>(source).ptr(); | 100 Profile* profile = content::Source<Profile>(source).ptr(); |
| 90 if (profile && profile->IsOffTheRecord()) | 101 if (profile && profile->IsOffTheRecord()) |
| 91 profile_ = profile; | 102 profile_ = profile; |
| 92 } | 103 } |
| 93 break; | 104 break; |
| 94 default: | 105 default: |
| 95 NOTREACHED(); | 106 NOTREACHED(); |
| 96 } | 107 } |
| 97 } | 108 } |
| OLD | NEW |