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.
5 #include "chrome/browser/sync/glue/synced_tab_delegate.h"
7 #include "base/logging.h"
8 #include "chrome/browser/ui/sync/tab_contents_synced_tab_delegate.h"
9 #include "chrome/common/url_constants.h"
10 #include "content/public/browser/navigation_entry.h"
13 using browser_sync::SyncedTabDelegate
;
15 namespace browser_sync
{
17 SyncedTabDelegate::SyncedTabDelegate() {}
18 SyncedTabDelegate::~SyncedTabDelegate() {}
20 content::NavigationEntry
* SyncedTabDelegate::GetCurrentEntryMaybePending()
22 return GetEntryAtIndexMaybePending(GetCurrentEntryIndex());
25 content::NavigationEntry
* SyncedTabDelegate::GetEntryAtIndexMaybePending(
27 return (GetPendingEntryIndex() == i
) ? GetPendingEntry() : GetEntryAtIndex(i
);
30 bool SyncedTabDelegate::ShouldSync() const {
31 if (GetSyncedWindowDelegate() == nullptr)
34 // Is there a valid NavigationEntry?
35 if (ProfileIsSupervised() && GetBlockedNavigations()->size() > 0)
38 int entry_count
= GetEntryCount();
40 return false; // This deliberately ignores a new pending entry.
42 bool found_valid_url
= false;
43 for (int i
= 0; i
< entry_count
; ++i
) {
44 const content::NavigationEntry
* entry
= GetEntryAtIndexMaybePending(i
);
48 const GURL
& virtual_url
= entry
->GetVirtualURL();
50 if (virtual_url
.is_valid() &&
51 !virtual_url
.SchemeIs(content::kChromeUIScheme
) &&
52 !virtual_url
.SchemeIs(chrome::kChromeNativeScheme
) &&
53 !virtual_url
.SchemeIsFile()) {
54 found_valid_url
= true;
55 } else if (virtual_url
== GURL(chrome::kChromeUIHistoryURL
)) {
56 // The history page is treated specially as we want it to trigger syncable
57 // events for UI purposes.
58 found_valid_url
= true;
61 return found_valid_url
;
64 void SyncedTabDelegate::SetSyncedWindowGetter(
65 scoped_ptr
<SyncedWindowDelegatesGetter
> getter
) {
66 synced_window_getter_
.reset(getter
.release());
69 const SyncedWindowDelegate
* SyncedTabDelegate::GetSyncedWindowDelegate() const {
70 if (!synced_window_getter_
) {
73 return synced_window_getter_
->FindById(GetWindowId());
76 } // namespace browser_sync