summaryrefslogtreecommitdiffstats
path: root/chrome/browser/sync/sessions/sessions_util.cc
blob: c8d7418f01cc6581d952838fe11326c5c62fce8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/sync/sessions/sessions_util.h"

#include "chrome/browser/sync/glue/synced_tab_delegate.h"
#include "chrome/browser/sync/glue/synced_window_delegate.h"
#include "chrome/common/url_constants.h"
#include "content/public/browser/navigation_entry.h"
#include "url/gurl.h"

namespace browser_sync {

namespace sessions_util {

bool ShouldSyncTab(const SyncedTabDelegate& tab) {
  if (SyncedWindowDelegate::FindSyncedWindowDelegateWithId(
          tab.GetWindowId()) == NULL) {
    return false;
  }

  // Does the tab have a valid NavigationEntry?
  if (tab.ProfileIsSupervised() && tab.GetBlockedNavigations()->size() > 0)
    return true;

  int entry_count = tab.GetEntryCount();
  if (entry_count == 0)
    return false;  // This deliberately ignores a new pending entry.

  int pending_index = tab.GetPendingEntryIndex();
  bool found_valid_url = false;
  for (int i = 0; i < entry_count; ++i) {
    const content::NavigationEntry* entry = (i == pending_index) ?
       tab.GetPendingEntry() : tab.GetEntryAtIndex(i);
    if (!entry)
      return false;
    const GURL& virtual_url = entry->GetVirtualURL();
    if (virtual_url.is_valid() &&
        !virtual_url.SchemeIs(content::kChromeUIScheme) &&
        !virtual_url.SchemeIs(chrome::kChromeNativeScheme) &&
        !virtual_url.SchemeIsFile()) {
      found_valid_url = true;
    }
  }
  return found_valid_url;
}

bool ShouldSyncWindow(const SyncedWindowDelegate* window) {
  if (window->IsApp())
    return false;
  return window->IsTypeTabbed() || window->IsTypePopup();
}

}  // namespace sessions_util

}  // namespace browser_sync