| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/sync/glue/synced_tab_delegate.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "chrome/browser/sync/glue/synced_session_util.h" | |
| 9 #include "chrome/browser/ui/sync/tab_contents_synced_tab_delegate.h" | |
| 10 #include "chrome/common/url_constants.h" | |
| 11 #include "content/public/browser/navigation_entry.h" | |
| 12 #include "url/gurl.h" | |
| 13 | |
| 14 using browser_sync::SyncedTabDelegate; | |
| 15 | |
| 16 namespace browser_sync { | |
| 17 | |
| 18 SyncedTabDelegate::SyncedTabDelegate() {} | |
| 19 SyncedTabDelegate::~SyncedTabDelegate() {} | |
| 20 | |
| 21 content::NavigationEntry* SyncedTabDelegate::GetCurrentEntryMaybePending() | |
| 22 const { | |
| 23 return GetEntryAtIndexMaybePending(GetCurrentEntryIndex()); | |
| 24 } | |
| 25 | |
| 26 content::NavigationEntry* SyncedTabDelegate::GetEntryAtIndexMaybePending( | |
| 27 int i) const { | |
| 28 return (GetPendingEntryIndex() == i) ? GetPendingEntry() : GetEntryAtIndex(i); | |
| 29 } | |
| 30 | |
| 31 bool SyncedTabDelegate::ShouldSync() const { | |
| 32 if (GetSyncedWindowDelegate() == nullptr) | |
| 33 return false; | |
| 34 | |
| 35 // Is there a valid NavigationEntry? | |
| 36 if (ProfileIsSupervised() && GetBlockedNavigations()->size() > 0) | |
| 37 return true; | |
| 38 | |
| 39 if (IsInitialBlankNavigation()) | |
| 40 return false; // This deliberately ignores a new pending entry. | |
| 41 | |
| 42 int entry_count = GetEntryCount(); | |
| 43 bool found_valid_url = false; | |
| 44 for (int i = 0; i < entry_count; ++i) { | |
| 45 const content::NavigationEntry* entry = GetEntryAtIndexMaybePending(i); | |
| 46 if (!entry) { | |
| 47 return false; | |
| 48 } | |
| 49 const GURL& virtual_url = entry->GetVirtualURL(); | |
| 50 | |
| 51 if (ShouldSyncURL(virtual_url)) { | |
| 52 found_valid_url = true; | |
| 53 } else if (virtual_url == GURL(chrome::kChromeUIHistoryURL)) { | |
| 54 // The history page is treated specially as we want it to trigger syncable | |
| 55 // events for UI purposes. | |
| 56 found_valid_url = true; | |
| 57 } | |
| 58 } | |
| 59 return found_valid_url; | |
| 60 } | |
| 61 | |
| 62 void SyncedTabDelegate::SetSyncedWindowGetter( | |
| 63 scoped_ptr<SyncedWindowDelegatesGetter> getter) { | |
| 64 synced_window_getter_.reset(getter.release()); | |
| 65 } | |
| 66 | |
| 67 const SyncedWindowDelegate* SyncedTabDelegate::GetSyncedWindowDelegate() const { | |
| 68 if (!synced_window_getter_) { | |
| 69 NOTREACHED(); | |
| 70 } | |
| 71 return synced_window_getter_->FindById(GetWindowId()); | |
| 72 } | |
| 73 | |
| 74 } // namespace browser_sync | |
| OLD | NEW |