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
3 // found in the LICENSE file.
5 #include "chrome/browser/sync/sessions/sessions_util.h"
7 #include "chrome/browser/sync/glue/synced_tab_delegate.h"
8 #include "chrome/browser/sync/glue/synced_window_delegate.h"
9 #include "chrome/common/url_constants.h"
10 #include "content/public/browser/navigation_entry.h"
13 namespace browser_sync {
15 namespace sessions_util {
17 bool ShouldSyncTab(const SyncedTabDelegate& tab) {
18 if (SyncedWindowDelegate::FindSyncedWindowDelegateWithId(
19 tab.GetWindowId()) == NULL) {
23 // Does the tab have a valid NavigationEntry?
24 if (tab.ProfileIsManaged() && tab.GetBlockedNavigations()->size() > 0)
27 int entry_count = tab.GetEntryCount();
29 return false; // This deliberately ignores a new pending entry.
31 int pending_index = tab.GetPendingEntryIndex();
32 bool found_valid_url = false;
33 for (int i = 0; i < entry_count; ++i) {
34 const content::NavigationEntry* entry = (i == pending_index) ?
35 tab.GetPendingEntry() : tab.GetEntryAtIndex(i);
38 const GURL& virtual_url = entry->GetVirtualURL();
39 if (virtual_url.is_valid() &&
40 !virtual_url.SchemeIs(content::kChromeUIScheme) &&
41 !virtual_url.SchemeIs(chrome::kChromeNativeScheme) &&
42 !virtual_url.SchemeIsFile()) {
43 found_valid_url = true;
46 return found_valid_url;
49 bool ShouldSyncWindow(const SyncedWindowDelegate* window) {
52 return window->IsTypeTabbed() || window->IsTypePopup();
55 } // namespace sessions_util
57 } // namespace browser_sync