Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / sync / sessions / sessions_util.cc
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.
4
5 #include "chrome/browser/sync/sessions/sessions_util.h"
6
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"
11 #include "url/gurl.h"
12
13 namespace browser_sync {
14
15 namespace sessions_util {
16
17 bool ShouldSyncTab(const SyncedTabDelegate& tab) {
18   if (SyncedWindowDelegate::FindSyncedWindowDelegateWithId(
19           tab.GetWindowId()) == NULL) {
20     return false;
21   }
22
23   // Does the tab have a valid NavigationEntry?
24   if (tab.ProfileIsManaged() && tab.GetBlockedNavigations()->size() > 0)
25     return true;
26
27   int entry_count = tab.GetEntryCount();
28   if (entry_count == 0)
29     return false;  // This deliberately ignores a new pending entry.
30
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);
36     if (!entry)
37       return false;
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;
44     }
45   }
46   return found_valid_url;
47 }
48
49 bool ShouldSyncWindow(const SyncedWindowDelegate* window) {
50   if (window->IsApp())
51     return false;
52   return window->IsTypeTabbed() || window->IsTypePopup();
53 }
54
55 }  // namespace sessions_util
56
57 }  // namespace browser_sync