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