Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(279)

Side by Side Diff: chrome/browser/sync/glue/synced_session_tracker.cc

Issue 1408643002: [Sync] Componentize synced_tab_delegate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix test broken by rebase Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/sync/glue/synced_session_tracker.h" 5 #include "chrome/browser/sync/glue/synced_session_tracker.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/sync/glue/synced_session_util.h" 10 #include "components/sync_sessions/sync_sessions_client.h"
11 11
12 namespace browser_sync { 12 namespace browser_sync {
13 13
14 SyncedSessionTracker::SyncedSessionTracker() { 14 namespace {
15
16 // Helper for iterating through all tabs within a window, and all navigations
17 // within a tab, to find if there's a valid syncable url.
18 bool ShouldSyncSessionWindow(sync_sessions::SyncSessionsClient* sessions_client,
19 const sessions::SessionWindow& window) {
20 for (sessions::SessionTab* const tab : window.tabs) {
21 for (const sessions::SerializedNavigationEntry& navigation :
22 tab->navigations) {
23 if (sessions_client->ShouldSyncURL(navigation.virtual_url())) {
24 return true;
25 }
26 }
27 }
28 return false;
15 } 29 }
16 30
31 } // namespace
32
33 SyncedSessionTracker::SyncedSessionTracker(
34 sync_sessions::SyncSessionsClient* sessions_client)
35 : sessions_client_(sessions_client) {}
36
17 SyncedSessionTracker::~SyncedSessionTracker() { 37 SyncedSessionTracker::~SyncedSessionTracker() {
18 Clear(); 38 Clear();
19 } 39 }
20 40
21 void SyncedSessionTracker::SetLocalSessionTag( 41 void SyncedSessionTracker::SetLocalSessionTag(
22 const std::string& local_session_tag) { 42 const std::string& local_session_tag) {
23 local_session_tag_ = local_session_tag; 43 local_session_tag_ = local_session_tag;
24 } 44 }
25 45
26 bool SyncedSessionTracker::LookupAllForeignSessions( 46 bool SyncedSessionTracker::LookupAllForeignSessions(
27 std::vector<const sync_driver::SyncedSession*>* sessions) const { 47 std::vector<const sync_driver::SyncedSession*>* sessions) const {
28 DCHECK(sessions); 48 DCHECK(sessions);
29 sessions->clear(); 49 sessions->clear();
30 // Fill vector of sessions from our synced session map. 50 // Fill vector of sessions from our synced session map.
31 for (SyncedSessionMap::const_iterator i = 51 for (SyncedSessionMap::const_iterator i =
32 synced_session_map_.begin(); i != synced_session_map_.end(); ++i) { 52 synced_session_map_.begin(); i != synced_session_map_.end(); ++i) {
33 // Only include foreign sessions with open tabs. 53 // Only include foreign sessions with open tabs.
34 sync_driver::SyncedSession* foreign_session = i->second; 54 sync_driver::SyncedSession* foreign_session = i->second;
35 if (i->first != local_session_tag_ && !foreign_session->windows.empty()) { 55 if (i->first != local_session_tag_ && !foreign_session->windows.empty()) {
36 bool found_tabs = false; 56 bool found_tabs = false;
37 for (sync_driver::SyncedSession::SyncedWindowMap::const_iterator iter = 57 for (sync_driver::SyncedSession::SyncedWindowMap::const_iterator iter =
38 foreign_session->windows.begin(); 58 foreign_session->windows.begin();
39 iter != foreign_session->windows.end(); ++iter) { 59 iter != foreign_session->windows.end(); ++iter) {
40 if (ShouldSyncSessionWindow(*(iter->second))) { 60 if (ShouldSyncSessionWindow(sessions_client_, *(iter->second))) {
41 found_tabs = true; 61 found_tabs = true;
42 break; 62 break;
43 } 63 }
44 } 64 }
45 if (found_tabs) 65 if (found_tabs)
46 sessions->push_back(foreign_session); 66 sessions->push_back(foreign_session);
47 } 67 }
48 } 68 }
49 69
50 return !sessions->empty(); 70 return !sessions->empty();
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 STLDeleteElements(&unmapped_tabs_); 423 STLDeleteElements(&unmapped_tabs_);
404 424
405 // Get rid of our Window/Tab maps (does not delete the actual Window/Tabs 425 // Get rid of our Window/Tab maps (does not delete the actual Window/Tabs
406 // themselves; they should have all been deleted above). 426 // themselves; they should have all been deleted above).
407 synced_window_map_.clear(); 427 synced_window_map_.clear();
408 synced_tab_map_.clear(); 428 synced_tab_map_.clear();
409 local_session_tag_.clear(); 429 local_session_tag_.clear();
410 } 430 }
411 431
412 } // namespace browser_sync 432 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698