| 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/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/search_engines/search_terms_data.h" | 10 #include "chrome/browser/search_engines/search_terms_data.h" |
| 11 #include "chrome/browser/sync/glue/synced_tab_delegate.h" |
| 11 #include "chrome/browser/sync/glue/synced_window_delegate_android.h" | 12 #include "chrome/browser/sync/glue/synced_window_delegate_android.h" |
| 12 #include "chrome/browser/ui/toolbar/toolbar_model_impl.h" | 13 #include "chrome/browser/ui/toolbar/toolbar_model_impl.h" |
| 13 #include "chrome/common/chrome_notification_types.h" | 14 #include "chrome/common/chrome_notification_types.h" |
| 14 #include "content/public/browser/notification_service.h" | 15 #include "content/public/browser/notification_service.h" |
| 15 | 16 |
| 16 using content::NotificationService; | 17 using content::NotificationService; |
| 18 using browser_sync::SyncedTabDelegate; |
| 19 using browser_sync::SyncedWindowDelegate; |
| 17 | 20 |
| 18 TabModel::TabModel(Profile* profile) | 21 TabModel::TabModel(Profile* profile) |
| 19 : profile_(profile), | 22 : profile_(profile), |
| 20 synced_window_delegate_( | 23 synced_window_delegate_( |
| 21 new browser_sync::SyncedWindowDelegateAndroid(this)), | 24 new browser_sync::SyncedWindowDelegateAndroid(this)), |
| 22 toolbar_model_(new ToolbarModelImpl(this)) { | 25 toolbar_model_(new ToolbarModelImpl(this)) { |
| 23 | 26 |
| 24 if (profile) { | 27 if (profile) { |
| 25 // A normal Profile creates an OTR profile if it does not exist when | 28 // A normal Profile creates an OTR profile if it does not exist when |
| 26 // GetOffTheRecordProfile() is called, so we guard it with | 29 // GetOffTheRecordProfile() is called, so we guard it with |
| 27 // HasOffTheRecordProfile(). An OTR profile returns itself when you call | 30 // HasOffTheRecordProfile(). An OTR profile returns itself when you call |
| 28 // GetOffTheRecordProfile(). | 31 // GetOffTheRecordProfile(). |
| 29 is_off_the_record_ = (profile->HasOffTheRecordProfile() && | 32 is_off_the_record_ = (profile->HasOffTheRecordProfile() && |
| 30 profile == profile->GetOffTheRecordProfile()); | 33 profile == profile->GetOffTheRecordProfile()); |
| 31 | 34 |
| 32 // A profile can be destroyed, for example in the case of closing all | 35 // A profile can be destroyed, for example in the case of closing all |
| 33 // incognito tabs. We therefore must listen for when this happens, and | 36 // incognito tabs. We therefore must listen for when this happens, and |
| 34 // remove our pointer to the profile accordingly. | 37 // remove our pointer to the profile accordingly. |
| 35 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, | 38 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
| 36 content::Source<Profile>(profile_)); | 39 content::Source<Profile>(profile_)); |
| 37 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CREATED, | 40 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CREATED, |
| 38 content::NotificationService::AllSources()); | 41 content::NotificationService::AllSources()); |
| 42 registrar_.Add(this, |
| 43 chrome::NOTIFICATION_SESSION_SYNC_ID_GENERATED, |
| 44 content::NotificationService::AllSources()); |
| 39 } else { | 45 } else { |
| 40 is_off_the_record_ = false; | 46 is_off_the_record_ = false; |
| 41 } | 47 } |
| 42 } | 48 } |
| 43 | 49 |
| 44 TabModel::TabModel() | 50 TabModel::TabModel() |
| 45 : profile_(NULL), | 51 : profile_(NULL), |
| 46 is_off_the_record_(false), | 52 is_off_the_record_(false), |
| 47 synced_window_delegate_( | 53 synced_window_delegate_( |
| 48 new browser_sync::SyncedWindowDelegateAndroid(this)) { | 54 new browser_sync::SyncedWindowDelegateAndroid(this)) { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 // Our incognito tab model out lives the profile, so we need to recapture | 129 // Our incognito tab model out lives the profile, so we need to recapture |
| 124 // the pointer if ours was previously deleted. | 130 // the pointer if ours was previously deleted. |
| 125 // NOTIFICATION_PROFILE_DESTROYED is not sent for every destruction, so | 131 // NOTIFICATION_PROFILE_DESTROYED is not sent for every destruction, so |
| 126 // we overwrite the pointer regardless of whether it's NULL. | 132 // we overwrite the pointer regardless of whether it's NULL. |
| 127 if (is_off_the_record_) { | 133 if (is_off_the_record_) { |
| 128 Profile* profile = content::Source<Profile>(source).ptr(); | 134 Profile* profile = content::Source<Profile>(source).ptr(); |
| 129 if (profile && profile->IsOffTheRecord()) | 135 if (profile && profile->IsOffTheRecord()) |
| 130 profile_ = profile; | 136 profile_ = profile; |
| 131 } | 137 } |
| 132 break; | 138 break; |
| 139 case chrome::NOTIFICATION_SESSION_SYNC_ID_GENERATED: { |
| 140 content::Details<const SyncedTabDelegate> tab(details); |
| 141 const SyncedWindowDelegate* sync_window_delegate = |
| 142 SyncedWindowDelegate::FindSyncedWindowDelegateWithId( |
| 143 tab->GetWindowId().id()); |
| 144 if (sync_window_delegate) { |
| 145 const int tab_count = sync_window_delegate->GetTabCount(); |
| 146 for (int i = 0; i < tab_count; ++i) { |
| 147 SyncedTabDelegate* sync_tab = sync_window_delegate->GetTabAt(i); |
| 148 // This may seem redundant, but it ensure Sync id is set in java. |
| 149 if (sync_tab && sync_tab->IsTabInMemory() && |
| 150 sync_tab->GetSyncSessionId() == tab->GetSyncSessionId()) { |
| 151 sync_tab->SetSyncSessionId(tab->GetSyncSessionId()); |
| 152 break; |
| 153 } |
| 154 } |
| 155 } |
| 156 } break; |
| 133 default: | 157 default: |
| 134 NOTREACHED(); | 158 NOTREACHED(); |
| 135 } | 159 } |
| 136 } | 160 } |
| OLD | NEW |