| 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/sync/glue/session_change_processor.h" | 5 #include "chrome/browser/sync/glue/session_change_processor.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 namespace { | 38 namespace { |
| 39 | 39 |
| 40 // The URL at which the set of synced tabs is displayed. We treat it differently | 40 // The URL at which the set of synced tabs is displayed. We treat it differently |
| 41 // from all other URL's as accessing it triggers a sync refresh of Sessions. | 41 // from all other URL's as accessing it triggers a sync refresh of Sessions. |
| 42 static const char kNTPOpenTabSyncURL[] = "chrome://newtab/#open_tabs"; | 42 static const char kNTPOpenTabSyncURL[] = "chrome://newtab/#open_tabs"; |
| 43 | 43 |
| 44 // Extract the source SyncedTabDelegate from a NotificationSource originating | 44 // Extract the source SyncedTabDelegate from a NotificationSource originating |
| 45 // from a NavigationController, if it exists. Returns |NULL| otherwise. | 45 // from a NavigationController, if it exists. Returns |NULL| otherwise. |
| 46 SyncedTabDelegate* ExtractSyncedTabDelegate( | 46 SyncedTabDelegate* ExtractSyncedTabDelegate( |
| 47 const content::NotificationSource& source) { | 47 const content::NotificationSource& source) { |
| 48 TabContents* tab = TabContents::FromWebContents( | 48 return TabContentsSyncedTabDelegate::FromWebContents( |
| 49 content::Source<NavigationController>(source).ptr()->GetWebContents()); | 49 content::Source<NavigationController>(source).ptr()->GetWebContents()); |
| 50 if (!tab) | |
| 51 return NULL; | |
| 52 return tab->synced_tab_delegate(); | |
| 53 } | 50 } |
| 54 | 51 |
| 55 } // namespace | 52 } // namespace |
| 56 | 53 |
| 57 SessionChangeProcessor::SessionChangeProcessor( | 54 SessionChangeProcessor::SessionChangeProcessor( |
| 58 DataTypeErrorHandler* error_handler, | 55 DataTypeErrorHandler* error_handler, |
| 59 SessionModelAssociator* session_model_associator) | 56 SessionModelAssociator* session_model_associator) |
| 60 : ChangeProcessor(error_handler), | 57 : ChangeProcessor(error_handler), |
| 61 session_model_associator_(session_model_associator), | 58 session_model_associator_(session_model_associator), |
| 62 profile_(NULL), | 59 profile_(NULL), |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 case chrome::NOTIFICATION_BROWSER_OPENED: { | 101 case chrome::NOTIFICATION_BROWSER_OPENED: { |
| 105 Browser* browser = content::Source<Browser>(source).ptr(); | 102 Browser* browser = content::Source<Browser>(source).ptr(); |
| 106 if (!browser || browser->profile() != profile_) { | 103 if (!browser || browser->profile() != profile_) { |
| 107 return; | 104 return; |
| 108 } | 105 } |
| 109 DVLOG(1) << "Received BROWSER_OPENED for profile " << profile_; | 106 DVLOG(1) << "Received BROWSER_OPENED for profile " << profile_; |
| 110 break; | 107 break; |
| 111 } | 108 } |
| 112 | 109 |
| 113 case chrome::NOTIFICATION_TAB_PARENTED: { | 110 case chrome::NOTIFICATION_TAB_PARENTED: { |
| 114 TabContents* tab_contents = TabContents::FromWebContents( | 111 WebContents* web_contents = content::Source<WebContents>(source).ptr(); |
| 115 content::Source<WebContents>(source).ptr()); | 112 SyncedTabDelegate* tab = |
| 116 SyncedTabDelegate* tab = tab_contents->synced_tab_delegate(); | 113 TabContentsSyncedTabDelegate::FromWebContents(web_contents); |
| 117 if (!tab || tab->profile() != profile_) { | 114 if (!tab || tab->profile() != profile_) { |
| 118 return; | 115 return; |
| 119 } | 116 } |
| 120 modified_tabs.push_back(tab); | 117 modified_tabs.push_back(tab); |
| 121 DVLOG(1) << "Received TAB_PARENTED for profile " << profile_; | 118 DVLOG(1) << "Received TAB_PARENTED for profile " << profile_; |
| 122 break; | 119 break; |
| 123 } | 120 } |
| 124 | 121 |
| 125 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: { | 122 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: { |
| 126 TabContents* tab_contents = TabContents::FromWebContents( | 123 WebContents* web_contents = content::Source<WebContents>(source).ptr(); |
| 127 content::Source<WebContents>(source).ptr()); | 124 SyncedTabDelegate* tab = |
| 128 if (!tab_contents) { | 125 TabContentsSyncedTabDelegate::FromWebContents(web_contents); |
| 129 return; | |
| 130 } | |
| 131 SyncedTabDelegate* tab = tab_contents->synced_tab_delegate(); | |
| 132 if (!tab || tab->profile() != profile_) { | 126 if (!tab || tab->profile() != profile_) { |
| 133 return; | 127 return; |
| 134 } | 128 } |
| 135 modified_tabs.push_back(tab); | 129 modified_tabs.push_back(tab); |
| 136 DVLOG(1) << "Received LOAD_COMPLETED_MAIN_FRAME for profile " << profile_; | 130 DVLOG(1) << "Received LOAD_COMPLETED_MAIN_FRAME for profile " << profile_; |
| 137 break; | 131 break; |
| 138 } | 132 } |
| 139 | 133 |
| 140 case chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED: { | 134 case chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED: { |
| 141 TabContents* tab_contents = content::Source<TabContents>(source).ptr(); | 135 TabContents* tab_contents = content::Source<TabContents>(source).ptr(); |
| 142 SyncedTabDelegate* tab = tab_contents->synced_tab_delegate(); | 136 SyncedTabDelegate* tab = TabContentsSyncedTabDelegate::FromWebContents( |
| 137 tab_contents->web_contents()); |
| 143 if (!tab || tab->profile() != profile_) | 138 if (!tab || tab->profile() != profile_) |
| 144 return; | 139 return; |
| 145 modified_tabs.push_back(tab); | 140 modified_tabs.push_back(tab); |
| 146 DVLOG(1) << "Received NOTIFICATION_TAB_CONTENTS_DESTROYED for profile " | 141 DVLOG(1) << "Received NOTIFICATION_TAB_CONTENTS_DESTROYED for profile " |
| 147 << profile_; | 142 << profile_; |
| 148 break; | 143 break; |
| 149 } | 144 } |
| 150 | 145 |
| 151 case content::NOTIFICATION_NAV_LIST_PRUNED: { | 146 case content::NOTIFICATION_NAV_LIST_PRUNED: { |
| 152 SyncedTabDelegate* tab = ExtractSyncedTabDelegate(source); | 147 SyncedTabDelegate* tab = ExtractSyncedTabDelegate(source); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 179 } | 174 } |
| 180 | 175 |
| 181 case chrome::NOTIFICATION_TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED: { | 176 case chrome::NOTIFICATION_TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED: { |
| 182 extensions::TabHelper* extension_tab_helper = | 177 extensions::TabHelper* extension_tab_helper = |
| 183 content::Source<extensions::TabHelper>(source).ptr(); | 178 content::Source<extensions::TabHelper>(source).ptr(); |
| 184 if (extension_tab_helper->web_contents()->GetBrowserContext() != | 179 if (extension_tab_helper->web_contents()->GetBrowserContext() != |
| 185 profile_) { | 180 profile_) { |
| 186 return; | 181 return; |
| 187 } | 182 } |
| 188 if (extension_tab_helper->extension_app()) { | 183 if (extension_tab_helper->extension_app()) { |
| 189 TabContents* tab_contents = | 184 SyncedTabDelegate* tab = TabContentsSyncedTabDelegate::FromWebContents( |
| 190 TabContents::FromWebContents(extension_tab_helper->web_contents()); | 185 extension_tab_helper->web_contents()); |
| 191 modified_tabs.push_back(tab_contents->synced_tab_delegate()); | 186 modified_tabs.push_back(tab); |
| 192 } | 187 } |
| 193 DVLOG(1) << "Received TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED " | 188 DVLOG(1) << "Received TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED " |
| 194 << "for profile " << profile_; | 189 << "for profile " << profile_; |
| 195 break; | 190 break; |
| 196 } | 191 } |
| 197 | 192 |
| 198 default: | 193 default: |
| 199 LOG(ERROR) << "Received unexpected notification of type " | 194 LOG(ERROR) << "Received unexpected notification of type " |
| 200 << type; | 195 << type; |
| 201 break; | 196 break; |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 notification_registrar_.Add(this, chrome::NOTIFICATION_FAVICON_CHANGED, | 351 notification_registrar_.Add(this, chrome::NOTIFICATION_FAVICON_CHANGED, |
| 357 content::Source<Profile>(profile_)); | 352 content::Source<Profile>(profile_)); |
| 358 } | 353 } |
| 359 | 354 |
| 360 void SessionChangeProcessor::StopObserving() { | 355 void SessionChangeProcessor::StopObserving() { |
| 361 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 356 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 362 notification_registrar_.RemoveAll(); | 357 notification_registrar_.RemoveAll(); |
| 363 } | 358 } |
| 364 | 359 |
| 365 } // namespace browser_sync | 360 } // namespace browser_sync |
| OLD | NEW |