Home | History | Annotate | Download | only in glue
      1 // Copyright (c) 2012 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_session.h"
      6 
      7 #include "base/stl_util.h"
      8 #include "chrome/common/url_constants.h"
      9 #include "content/public/browser/navigation_entry.h"
     10 
     11 namespace browser_sync {
     12 
     13 SyncedSession::SyncedSession() : session_tag("invalid"),
     14                                  device_type(TYPE_UNSET) {
     15 }
     16 
     17 SyncedSession::~SyncedSession() {
     18   STLDeleteContainerPairSecondPointers(windows.begin(), windows.end());
     19 }
     20 
     21 // Note: if you modify this, make sure you modify
     22 // SessionModelAssociator::ShouldSyncTab to ensure the logic matches.
     23 bool ShouldSyncSessionTab(const SessionTab& tab) {
     24   if (tab.navigations.empty())
     25     return false;
     26   bool found_valid_url = false;
     27   for (size_t i = 0; i < tab.navigations.size(); ++i) {
     28     if (tab.navigations.at(i).virtual_url().is_valid() &&
     29         !tab.navigations.at(i).virtual_url().SchemeIs("chrome") &&
     30         !tab.navigations.at(i).virtual_url().SchemeIsFile()) {
     31       found_valid_url = true;
     32       break;
     33     }
     34   }
     35   return found_valid_url;
     36 }
     37 
     38 bool SessionWindowHasNoTabsToSync(const SessionWindow& window) {
     39   int num_populated = 0;
     40   for (std::vector<SessionTab*>::const_iterator i = window.tabs.begin();
     41       i != window.tabs.end(); ++i) {
     42     const SessionTab* tab = *i;
     43     if (ShouldSyncSessionTab(*tab))
     44       num_populated++;
     45   }
     46   return (num_populated == 0);
     47 }
     48 
     49 }  // namespace browser_sync
     50