| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/sessions/sessions_sync_manager.h" | 5 #include "chrome/browser/sync/sessions/sessions_sync_manager.h" |
| 6 | 6 |
| 7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
| 8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
| 9 #include "chrome/browser/sessions/session_tab_helper.h" | 9 #include "chrome/browser/sessions/session_tab_helper.h" |
| 10 #include "chrome/browser/sessions/session_types.h" | 10 #include "chrome/browser/sessions/session_types.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 | 43 |
| 44 namespace browser_sync { | 44 namespace browser_sync { |
| 45 | 45 |
| 46 namespace { | 46 namespace { |
| 47 | 47 |
| 48 class SyncedWindowDelegateOverride : public SyncedWindowDelegate { | 48 class SyncedWindowDelegateOverride : public SyncedWindowDelegate { |
| 49 public: | 49 public: |
| 50 explicit SyncedWindowDelegateOverride(SyncedWindowDelegate* wrapped) | 50 explicit SyncedWindowDelegateOverride(SyncedWindowDelegate* wrapped) |
| 51 : wrapped_(wrapped) { | 51 : wrapped_(wrapped) { |
| 52 } | 52 } |
| 53 virtual ~SyncedWindowDelegateOverride() {} | 53 ~SyncedWindowDelegateOverride() override {} |
| 54 | 54 |
| 55 virtual bool HasWindow() const override { | 55 bool HasWindow() const override { return wrapped_->HasWindow(); } |
| 56 return wrapped_->HasWindow(); | |
| 57 } | |
| 58 | 56 |
| 59 virtual SessionID::id_type GetSessionId() const override { | 57 SessionID::id_type GetSessionId() const override { |
| 60 return wrapped_->GetSessionId(); | 58 return wrapped_->GetSessionId(); |
| 61 } | 59 } |
| 62 | 60 |
| 63 virtual int GetTabCount() const override { | 61 int GetTabCount() const override { return wrapped_->GetTabCount(); } |
| 64 return wrapped_->GetTabCount(); | |
| 65 } | |
| 66 | 62 |
| 67 virtual int GetActiveIndex() const override { | 63 int GetActiveIndex() const override { return wrapped_->GetActiveIndex(); } |
| 68 return wrapped_->GetActiveIndex(); | |
| 69 } | |
| 70 | 64 |
| 71 virtual bool IsApp() const override { | 65 bool IsApp() const override { return wrapped_->IsApp(); } |
| 72 return wrapped_->IsApp(); | |
| 73 } | |
| 74 | 66 |
| 75 virtual bool IsTypeTabbed() const override { | 67 bool IsTypeTabbed() const override { return wrapped_->IsTypeTabbed(); } |
| 76 return wrapped_->IsTypeTabbed(); | |
| 77 } | |
| 78 | 68 |
| 79 virtual bool IsTypePopup() const override { | 69 bool IsTypePopup() const override { return wrapped_->IsTypePopup(); } |
| 80 return wrapped_->IsTypePopup(); | |
| 81 } | |
| 82 | 70 |
| 83 virtual bool IsTabPinned(const SyncedTabDelegate* tab) const override { | 71 bool IsTabPinned(const SyncedTabDelegate* tab) const override { |
| 84 return wrapped_->IsTabPinned(tab); | 72 return wrapped_->IsTabPinned(tab); |
| 85 } | 73 } |
| 86 | 74 |
| 87 virtual SyncedTabDelegate* GetTabAt(int index) const override { | 75 SyncedTabDelegate* GetTabAt(int index) const override { |
| 88 if (tab_overrides_.find(index) != tab_overrides_.end()) | 76 if (tab_overrides_.find(index) != tab_overrides_.end()) |
| 89 return tab_overrides_.find(index)->second; | 77 return tab_overrides_.find(index)->second; |
| 90 | 78 |
| 91 return wrapped_->GetTabAt(index); | 79 return wrapped_->GetTabAt(index); |
| 92 } | 80 } |
| 93 | 81 |
| 94 void OverrideTabAt(int index, | 82 void OverrideTabAt(int index, |
| 95 SyncedTabDelegate* delegate, | 83 SyncedTabDelegate* delegate, |
| 96 SessionID::id_type tab_id) { | 84 SessionID::id_type tab_id) { |
| 97 tab_overrides_[index] = delegate; | 85 tab_overrides_[index] = delegate; |
| 98 tab_id_overrides_[index] = tab_id; | 86 tab_id_overrides_[index] = tab_id; |
| 99 } | 87 } |
| 100 | 88 |
| 101 virtual SessionID::id_type GetTabIdAt(int index) const override { | 89 SessionID::id_type GetTabIdAt(int index) const override { |
| 102 if (tab_id_overrides_.find(index) != tab_id_overrides_.end()) | 90 if (tab_id_overrides_.find(index) != tab_id_overrides_.end()) |
| 103 return tab_id_overrides_.find(index)->second; | 91 return tab_id_overrides_.find(index)->second; |
| 104 return wrapped_->GetTabIdAt(index); | 92 return wrapped_->GetTabIdAt(index); |
| 105 } | 93 } |
| 106 | 94 |
| 107 virtual bool IsSessionRestoreInProgress() const override { | 95 bool IsSessionRestoreInProgress() const override { |
| 108 return wrapped_->IsSessionRestoreInProgress(); | 96 return wrapped_->IsSessionRestoreInProgress(); |
| 109 } | 97 } |
| 110 | 98 |
| 111 private: | 99 private: |
| 112 std::map<int, SyncedTabDelegate*> tab_overrides_; | 100 std::map<int, SyncedTabDelegate*> tab_overrides_; |
| 113 std::map<int, SessionID::id_type> tab_id_overrides_; | 101 std::map<int, SessionID::id_type> tab_id_overrides_; |
| 114 SyncedWindowDelegate* wrapped_; | 102 SyncedWindowDelegate* wrapped_; |
| 115 }; | 103 }; |
| 116 | 104 |
| 117 class TestSyncedWindowDelegatesGetter : public SyncedWindowDelegatesGetter { | 105 class TestSyncedWindowDelegatesGetter : public SyncedWindowDelegatesGetter { |
| 118 public: | 106 public: |
| 119 TestSyncedWindowDelegatesGetter( | 107 TestSyncedWindowDelegatesGetter( |
| 120 const std::set<SyncedWindowDelegate*>& delegates) | 108 const std::set<SyncedWindowDelegate*>& delegates) |
| 121 : delegates_(delegates) {} | 109 : delegates_(delegates) {} |
| 122 | 110 |
| 123 virtual const std::set<SyncedWindowDelegate*> GetSyncedWindowDelegates() | 111 const std::set<SyncedWindowDelegate*> GetSyncedWindowDelegates() override { |
| 124 override { | |
| 125 return delegates_; | 112 return delegates_; |
| 126 } | 113 } |
| 127 private: | 114 private: |
| 128 const std::set<SyncedWindowDelegate*> delegates_; | 115 const std::set<SyncedWindowDelegate*> delegates_; |
| 129 }; | 116 }; |
| 130 | 117 |
| 131 class TestSyncProcessorStub : public syncer::SyncChangeProcessor { | 118 class TestSyncProcessorStub : public syncer::SyncChangeProcessor { |
| 132 public: | 119 public: |
| 133 explicit TestSyncProcessorStub(syncer::SyncChangeList* output) | 120 explicit TestSyncProcessorStub(syncer::SyncChangeList* output) |
| 134 : output_(output) {} | 121 : output_(output) {} |
| 135 virtual syncer::SyncError ProcessSyncChanges( | 122 syncer::SyncError ProcessSyncChanges( |
| 136 const tracked_objects::Location& from_here, | 123 const tracked_objects::Location& from_here, |
| 137 const syncer::SyncChangeList& change_list) override { | 124 const syncer::SyncChangeList& change_list) override { |
| 138 if (error_.IsSet()) { | 125 if (error_.IsSet()) { |
| 139 syncer::SyncError error = error_; | 126 syncer::SyncError error = error_; |
| 140 error_ = syncer::SyncError(); | 127 error_ = syncer::SyncError(); |
| 141 return error; | 128 return error; |
| 142 } | 129 } |
| 143 | 130 |
| 144 if (output_) | 131 if (output_) |
| 145 output_->insert(output_->end(), change_list.begin(), change_list.end()); | 132 output_->insert(output_->end(), change_list.begin(), change_list.end()); |
| 146 | 133 |
| 147 return syncer::SyncError(); | 134 return syncer::SyncError(); |
| 148 } | 135 } |
| 149 | 136 |
| 150 virtual syncer::SyncDataList GetAllSyncData(syncer::ModelType type) | 137 syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const override { |
| 151 const override { | |
| 152 return sync_data_to_return_; | 138 return sync_data_to_return_; |
| 153 } | 139 } |
| 154 | 140 |
| 155 void FailProcessSyncChangesWith(const syncer::SyncError& error) { | 141 void FailProcessSyncChangesWith(const syncer::SyncError& error) { |
| 156 error_ = error; | 142 error_ = error; |
| 157 } | 143 } |
| 158 | 144 |
| 159 void SetSyncDataToReturn(const syncer::SyncDataList& data) { | 145 void SetSyncDataToReturn(const syncer::SyncDataList& data) { |
| 160 sync_data_to_return_ = data; | 146 sync_data_to_return_ = data; |
| 161 } | 147 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 i + 2, | 199 i + 2, |
| 214 entity, | 200 entity, |
| 215 base::Time(), | 201 base::Time(), |
| 216 syncer::AttachmentIdList(), | 202 syncer::AttachmentIdList(), |
| 217 syncer::AttachmentServiceProxyForTest::Create())); | 203 syncer::AttachmentServiceProxyForTest::Create())); |
| 218 } | 204 } |
| 219 } | 205 } |
| 220 | 206 |
| 221 class DummyRouter : public LocalSessionEventRouter { | 207 class DummyRouter : public LocalSessionEventRouter { |
| 222 public: | 208 public: |
| 223 virtual ~DummyRouter() {} | 209 ~DummyRouter() override {} |
| 224 virtual void StartRoutingTo(LocalSessionEventHandler* handler) override {} | 210 void StartRoutingTo(LocalSessionEventHandler* handler) override {} |
| 225 virtual void Stop() override {} | 211 void Stop() override {} |
| 226 }; | 212 }; |
| 227 | 213 |
| 228 scoped_ptr<LocalSessionEventRouter> NewDummyRouter() { | 214 scoped_ptr<LocalSessionEventRouter> NewDummyRouter() { |
| 229 return scoped_ptr<LocalSessionEventRouter>(new DummyRouter()); | 215 return scoped_ptr<LocalSessionEventRouter>(new DummyRouter()); |
| 230 } | 216 } |
| 231 | 217 |
| 232 } // namespace | 218 } // namespace |
| 233 | 219 |
| 234 class SessionsSyncManagerTest | 220 class SessionsSyncManagerTest |
| 235 : public BrowserWithTestWindowTest { | 221 : public BrowserWithTestWindowTest { |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 | 343 |
| 358 namespace { | 344 namespace { |
| 359 | 345 |
| 360 class SyncedTabDelegateFake : public SyncedTabDelegate { | 346 class SyncedTabDelegateFake : public SyncedTabDelegate { |
| 361 public: | 347 public: |
| 362 SyncedTabDelegateFake() : current_entry_index_(0), | 348 SyncedTabDelegateFake() : current_entry_index_(0), |
| 363 pending_entry_index_(-1), | 349 pending_entry_index_(-1), |
| 364 is_supervised_(false), | 350 is_supervised_(false), |
| 365 sync_id_(-1), | 351 sync_id_(-1), |
| 366 blocked_navigations_(NULL) {} | 352 blocked_navigations_(NULL) {} |
| 367 virtual ~SyncedTabDelegateFake() {} | 353 ~SyncedTabDelegateFake() override {} |
| 368 | 354 |
| 369 virtual int GetCurrentEntryIndex() const override { | 355 int GetCurrentEntryIndex() const override { return current_entry_index_; } |
| 370 return current_entry_index_; | |
| 371 } | |
| 372 void set_current_entry_index(int i) { | 356 void set_current_entry_index(int i) { |
| 373 current_entry_index_ = i; | 357 current_entry_index_ = i; |
| 374 } | 358 } |
| 375 | 359 |
| 376 virtual content::NavigationEntry* GetEntryAtIndex(int i) const override { | 360 content::NavigationEntry* GetEntryAtIndex(int i) const override { |
| 377 const int size = entries_.size(); | 361 const int size = entries_.size(); |
| 378 return (size < i + 1) ? NULL : entries_[i]; | 362 return (size < i + 1) ? NULL : entries_[i]; |
| 379 } | 363 } |
| 380 | 364 |
| 381 void AppendEntry(content::NavigationEntry* entry) { | 365 void AppendEntry(content::NavigationEntry* entry) { |
| 382 entries_.push_back(entry); | 366 entries_.push_back(entry); |
| 383 } | 367 } |
| 384 | 368 |
| 385 virtual int GetEntryCount() const override { | 369 int GetEntryCount() const override { return entries_.size(); } |
| 386 return entries_.size(); | |
| 387 } | |
| 388 | 370 |
| 389 virtual int GetPendingEntryIndex() const override { | 371 int GetPendingEntryIndex() const override { return pending_entry_index_; } |
| 390 return pending_entry_index_; | |
| 391 } | |
| 392 void set_pending_entry_index(int i) { | 372 void set_pending_entry_index(int i) { |
| 393 pending_entry_index_ = i; | 373 pending_entry_index_ = i; |
| 394 } | 374 } |
| 395 | 375 |
| 396 virtual SessionID::id_type GetWindowId() const override { | 376 SessionID::id_type GetWindowId() const override { |
| 397 return SessionID::id_type(); | 377 return SessionID::id_type(); |
| 398 } | 378 } |
| 399 | 379 |
| 400 virtual SessionID::id_type GetSessionId() const override { | 380 SessionID::id_type GetSessionId() const override { |
| 401 return SessionID::id_type(); | 381 return SessionID::id_type(); |
| 402 } | 382 } |
| 403 | 383 |
| 404 virtual bool IsBeingDestroyed() const override { return false; } | 384 bool IsBeingDestroyed() const override { return false; } |
| 405 virtual Profile* profile() const override { return NULL; } | 385 Profile* profile() const override { return NULL; } |
| 406 virtual std::string GetExtensionAppId() const override { | 386 std::string GetExtensionAppId() const override { return std::string(); } |
| 407 return std::string(); | 387 content::NavigationEntry* GetPendingEntry() const override { return NULL; } |
| 408 } | 388 content::NavigationEntry* GetActiveEntry() const override { return NULL; } |
| 409 virtual content::NavigationEntry* GetPendingEntry() const override { | 389 bool ProfileIsSupervised() const override { return is_supervised_; } |
| 410 return NULL; | |
| 411 } | |
| 412 virtual content::NavigationEntry* GetActiveEntry() const override { | |
| 413 return NULL; | |
| 414 } | |
| 415 virtual bool ProfileIsSupervised() const override { | |
| 416 return is_supervised_; | |
| 417 } | |
| 418 void set_is_supervised(bool is_supervised) { is_supervised_ = is_supervised; } | 390 void set_is_supervised(bool is_supervised) { is_supervised_ = is_supervised; } |
| 419 virtual const std::vector<const content::NavigationEntry*>* | 391 const std::vector<const content::NavigationEntry*>* GetBlockedNavigations() |
| 420 GetBlockedNavigations() const override { | 392 const override { |
| 421 return blocked_navigations_; | 393 return blocked_navigations_; |
| 422 } | 394 } |
| 423 void set_blocked_navigations( | 395 void set_blocked_navigations( |
| 424 std::vector<const content::NavigationEntry*>* navs) { | 396 std::vector<const content::NavigationEntry*>* navs) { |
| 425 blocked_navigations_ = navs; | 397 blocked_navigations_ = navs; |
| 426 } | 398 } |
| 427 virtual bool IsPinned() const override { | 399 bool IsPinned() const override { return false; } |
| 428 return false; | 400 bool HasWebContents() const override { return false; } |
| 429 } | 401 content::WebContents* GetWebContents() const override { return NULL; } |
| 430 virtual bool HasWebContents() const override { | |
| 431 return false; | |
| 432 } | |
| 433 virtual content::WebContents* GetWebContents() const override { | |
| 434 return NULL; | |
| 435 } | |
| 436 | 402 |
| 437 // Session sync related methods. | 403 // Session sync related methods. |
| 438 virtual int GetSyncId() const override { | 404 int GetSyncId() const override { return sync_id_; } |
| 439 return sync_id_; | 405 void SetSyncId(int sync_id) override { sync_id_ = sync_id; } |
| 440 } | |
| 441 virtual void SetSyncId(int sync_id) override { | |
| 442 sync_id_ = sync_id; | |
| 443 } | |
| 444 | 406 |
| 445 void reset() { | 407 void reset() { |
| 446 current_entry_index_ = 0; | 408 current_entry_index_ = 0; |
| 447 pending_entry_index_ = -1; | 409 pending_entry_index_ = -1; |
| 448 sync_id_ = -1; | 410 sync_id_ = -1; |
| 449 entries_.clear(); | 411 entries_.clear(); |
| 450 } | 412 } |
| 451 | 413 |
| 452 private: | 414 private: |
| 453 int current_entry_index_; | 415 int current_entry_index_; |
| (...skipping 1377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1831 namespace { | 1793 namespace { |
| 1832 class SessionNotificationObserver : public content::NotificationObserver { | 1794 class SessionNotificationObserver : public content::NotificationObserver { |
| 1833 public: | 1795 public: |
| 1834 SessionNotificationObserver() : notified_of_update_(false), | 1796 SessionNotificationObserver() : notified_of_update_(false), |
| 1835 notified_of_refresh_(false) { | 1797 notified_of_refresh_(false) { |
| 1836 registrar_.Add(this, chrome::NOTIFICATION_FOREIGN_SESSION_UPDATED, | 1798 registrar_.Add(this, chrome::NOTIFICATION_FOREIGN_SESSION_UPDATED, |
| 1837 content::NotificationService::AllSources()); | 1799 content::NotificationService::AllSources()); |
| 1838 registrar_.Add(this, chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, | 1800 registrar_.Add(this, chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, |
| 1839 content::NotificationService::AllSources()); | 1801 content::NotificationService::AllSources()); |
| 1840 } | 1802 } |
| 1841 virtual void Observe(int type, | 1803 void Observe(int type, |
| 1842 const content::NotificationSource& source, | 1804 const content::NotificationSource& source, |
| 1843 const content::NotificationDetails& details) override { | 1805 const content::NotificationDetails& details) override { |
| 1844 switch (type) { | 1806 switch (type) { |
| 1845 case chrome::NOTIFICATION_FOREIGN_SESSION_UPDATED: | 1807 case chrome::NOTIFICATION_FOREIGN_SESSION_UPDATED: |
| 1846 notified_of_update_ = true; | 1808 notified_of_update_ = true; |
| 1847 break; | 1809 break; |
| 1848 case chrome::NOTIFICATION_SYNC_REFRESH_LOCAL: | 1810 case chrome::NOTIFICATION_SYNC_REFRESH_LOCAL: |
| 1849 notified_of_refresh_ = true; | 1811 notified_of_refresh_ = true; |
| 1850 break; | 1812 break; |
| 1851 default: | 1813 default: |
| 1852 NOTREACHED(); | 1814 NOTREACHED(); |
| 1853 break; | 1815 break; |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2001 base::Time(), | 1963 base::Time(), |
| 2002 syncer::AttachmentIdList(), | 1964 syncer::AttachmentIdList(), |
| 2003 syncer::AttachmentServiceProxyForTest::Create())); | 1965 syncer::AttachmentServiceProxyForTest::Create())); |
| 2004 } | 1966 } |
| 2005 | 1967 |
| 2006 syncer::SyncChangeList output; | 1968 syncer::SyncChangeList output; |
| 2007 InitWithSyncDataTakeOutput(initial_data, &output); | 1969 InitWithSyncDataTakeOutput(initial_data, &output); |
| 2008 } | 1970 } |
| 2009 | 1971 |
| 2010 } // namespace browser_sync | 1972 } // namespace browser_sync |
| OLD | NEW |