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

Side by Side Diff: chrome/browser/sync/sessions/sessions_sync_manager.cc

Issue 1408643002: [Sync] Componentize synced_tab_delegate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix GN, self review Created 5 years, 2 months 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 2014 The Chromium Authors. All rights reserved. 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 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/sessions/sessions_sync_manager.h" 5 #include "chrome/browser/sync/sessions/sessions_sync_manager.h"
6 6
7 #include "base/metrics/field_trial.h" 7 #include "base/metrics/field_trial.h"
8 #include "chrome/browser/chrome_notification_types.h" 8 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/browser/favicon/favicon_service_factory.h" 9 #include "chrome/browser/favicon/favicon_service_factory.h"
10 #include "chrome/browser/history/history_service_factory.h" 10 #include "chrome/browser/history/history_service_factory.h"
11 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/search/search.h" 12 #include "chrome/browser/search/search.h"
13 #include "chrome/browser/sync/glue/synced_tab_delegate.h"
14 #include "chrome/common/url_constants.h"
15 #include "components/sessions/content/content_serialized_navigation_builder.h"
16 #include "components/sync_driver/glue/synced_window_delegate.h" 13 #include "components/sync_driver/glue/synced_window_delegate.h"
17 #include "components/sync_driver/local_device_info_provider.h" 14 #include "components/sync_driver/local_device_info_provider.h"
18 #include "components/sync_driver/sessions/synced_window_delegates_getter.h" 15 #include "components/sync_driver/sessions/synced_window_delegates_getter.h"
19 #include "content/public/browser/favicon_status.h" 16 #include "components/sync_sessions/sync_sessions_client.h"
20 #include "content/public/browser/navigation_entry.h" 17 #include "components/sync_sessions/synced_tab_delegate.h"
21 #include "content/public/browser/notification_details.h" 18 #include "content/public/browser/notification_details.h"
22 #include "content/public/browser/notification_service.h" 19 #include "content/public/browser/notification_service.h"
23 #include "content/public/browser/notification_source.h" 20 #include "content/public/browser/notification_source.h"
24 #include "content/public/common/url_constants.h"
25 #include "sync/api/sync_error.h" 21 #include "sync/api/sync_error.h"
26 #include "sync/api/sync_error_factory.h" 22 #include "sync/api/sync_error_factory.h"
27 #include "sync/api/sync_merge_result.h" 23 #include "sync/api/sync_merge_result.h"
28 #include "sync/api/time.h" 24 #include "sync/api/time.h"
29 25
30 using content::NavigationEntry;
31 using sessions::ContentSerializedNavigationBuilder;
32 using sessions::SerializedNavigationEntry; 26 using sessions::SerializedNavigationEntry;
33 using sync_driver::DeviceInfo; 27 using sync_driver::DeviceInfo;
34 using sync_driver::LocalDeviceInfoProvider; 28 using sync_driver::LocalDeviceInfoProvider;
35 using syncer::SyncChange; 29 using syncer::SyncChange;
36 using syncer::SyncData; 30 using syncer::SyncData;
37 31
38 namespace browser_sync { 32 namespace browser_sync {
39 33
40 namespace { 34 namespace {
41 35
(...skipping 19 matching lines...) Expand all
61 return t1->timestamp > t2->timestamp; 55 return t1->timestamp > t2->timestamp;
62 } 56 }
63 57
64 // Comparator function for use with std::sort that will sort sessions by 58 // Comparator function for use with std::sort that will sort sessions by
65 // descending modified_time (i.e., most recent first). 59 // descending modified_time (i.e., most recent first).
66 bool SessionsRecencyComparator(const sync_driver::SyncedSession* s1, 60 bool SessionsRecencyComparator(const sync_driver::SyncedSession* s1,
67 const sync_driver::SyncedSession* s2) { 61 const sync_driver::SyncedSession* s2) {
68 return s1->modified_time > s2->modified_time; 62 return s1->modified_time > s2->modified_time;
69 } 63 }
70 64
65 // Helper to check if this is a valid tab that should be synced.
66 bool ShouldSyncTab(sync_sessions::SyncSessionsClient* sessions_client,
67 SyncedTabDelegate* tab_delegate) {
68 if (tab_delegate->GetSyncedWindowDelegate() == nullptr)
69 return false;
70
71 // Is there a valid NavigationEntry?
72 if (tab_delegate->ProfileIsSupervised() &&
73 tab_delegate->GetBlockedNavigations()->size() > 0)
74 return true;
75
76 if (tab_delegate->IsInitialBlankNavigation())
77 return false; // This deliberately ignores a new pending entry.
78
79 int entry_count = tab_delegate->GetEntryCount();
80 for (int i = 0; i < entry_count; ++i) {
81 const GURL& virtual_url = tab_delegate->GetVirtualURLAtIndex(i);
82 if (!virtual_url.is_valid())
83 continue;
84
85 if (sessions_client->ShouldSyncURL(virtual_url))
86 return true;
87 }
88 return false;
89 }
90
71 } // namespace 91 } // namespace
72 92
73 // |local_device| is owned by ProfileSyncService, its lifetime exceeds 93 // |local_device| is owned by ProfileSyncService, its lifetime exceeds
74 // lifetime of SessionSyncManager. 94 // lifetime of SessionSyncManager.
75 SessionsSyncManager::SessionsSyncManager( 95 SessionsSyncManager::SessionsSyncManager(
96 sync_sessions::SyncSessionsClient* sessions_client,
76 Profile* profile, 97 Profile* profile,
77 LocalDeviceInfoProvider* local_device, 98 LocalDeviceInfoProvider* local_device,
78 scoped_ptr<LocalSessionEventRouter> router, 99 scoped_ptr<LocalSessionEventRouter> router,
79 scoped_ptr<SyncedWindowDelegatesGetter> synced_window_getter) 100 scoped_ptr<SyncedWindowDelegatesGetter> synced_window_getter)
80 : favicon_cache_(FaviconServiceFactory::GetForProfile( 101 : sessions_client_(sessions_client),
102 session_tracker_(sessions_client),
103 favicon_cache_(FaviconServiceFactory::GetForProfile(
81 profile, 104 profile,
82 ServiceAccessType::EXPLICIT_ACCESS), 105 ServiceAccessType::EXPLICIT_ACCESS),
83 HistoryServiceFactory::GetForProfile( 106 HistoryServiceFactory::GetForProfile(
84 profile, 107 profile,
85 ServiceAccessType::EXPLICIT_ACCESS), 108 ServiceAccessType::EXPLICIT_ACCESS),
86 kMaxSyncFavicons), 109 kMaxSyncFavicons),
87 local_tab_pool_out_of_sync_(true), 110 local_tab_pool_out_of_sync_(true),
88 sync_prefs_(profile->GetPrefs()), 111 sync_prefs_(profile->GetPrefs()),
89 profile_(profile), 112 profile_(profile),
90 local_device_(local_device), 113 local_device_(local_device),
91 local_session_header_node_id_(TabNodePool::kInvalidTabNodeID), 114 local_session_header_node_id_(TabNodePool::kInvalidTabNodeID),
92 stale_session_threshold_days_(kDefaultStaleSessionThresholdDays), 115 stale_session_threshold_days_(kDefaultStaleSessionThresholdDays),
93 local_event_router_(router.Pass()), 116 local_event_router_(router.Pass()),
94 synced_window_getter_(synced_window_getter.Pass()), 117 synced_window_getter_(synced_window_getter.Pass()),
95 page_revisit_broadcaster_(this, profile) {} 118 page_revisit_broadcaster_(this, sessions_client, profile) {}
96 119
97 LocalSessionEventRouter::~LocalSessionEventRouter() {} 120 LocalSessionEventRouter::~LocalSessionEventRouter() {}
98 121
99 SessionsSyncManager::~SessionsSyncManager() { 122 SessionsSyncManager::~SessionsSyncManager() {
100 } 123 }
101 124
102 // Returns the GUID-based string that should be used for 125 // Returns the GUID-based string that should be used for
103 // |SessionsSyncManager::current_machine_tag_|. 126 // |SessionsSyncManager::current_machine_tag_|.
104 static std::string BuildMachineTag(const std::string& cache_guid) { 127 static std::string BuildMachineTag(const std::string& cache_guid) {
105 std::string machine_tag = "session_sync"; 128 std::string machine_tag = "session_sync";
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 syncer::SyncData data = syncer::SyncData::CreateLocalData( 313 syncer::SyncData data = syncer::SyncData::CreateLocalData(
291 current_machine_tag(), current_session_name_, entity); 314 current_machine_tag(), current_session_name_, entity);
292 change_output->push_back(syncer::SyncChange( 315 change_output->push_back(syncer::SyncChange(
293 FROM_HERE, syncer::SyncChange::ACTION_UPDATE, data)); 316 FROM_HERE, syncer::SyncChange::ACTION_UPDATE, data));
294 } 317 }
295 318
296 void SessionsSyncManager::AssociateTab(SyncedTabDelegate* const tab, 319 void SessionsSyncManager::AssociateTab(SyncedTabDelegate* const tab,
297 syncer::SyncChangeList* change_output) { 320 syncer::SyncChangeList* change_output) {
298 DCHECK(tab->HasWebContents()); 321 DCHECK(tab->HasWebContents());
299 SessionID::id_type tab_id = tab->GetSessionId(); 322 SessionID::id_type tab_id = tab->GetSessionId();
300 if (tab->profile() != profile_)
301 return;
302 323
303 if (tab->IsBeingDestroyed()) { 324 if (tab->IsBeingDestroyed()) {
304 // This tab is closing. 325 // This tab is closing.
305 TabLinksMap::iterator tab_iter = local_tab_map_.find(tab_id); 326 TabLinksMap::iterator tab_iter = local_tab_map_.find(tab_id);
306 if (tab_iter == local_tab_map_.end()) { 327 if (tab_iter == local_tab_map_.end()) {
307 // We aren't tracking this tab (for example, sync setting page). 328 // We aren't tracking this tab (for example, sync setting page).
308 return; 329 return;
309 } 330 }
310 local_tab_pool_.FreeTabNode(tab_iter->second->tab_node_id(), 331 local_tab_pool_.FreeTabNode(tab_iter->second->tab_node_id(),
311 change_output); 332 change_output);
312 local_tab_map_.erase(tab_iter); 333 local_tab_map_.erase(tab_iter);
313 return; 334 return;
314 } 335 }
315 336
316 if (!tab->ShouldSync()) 337 if (!ShouldSyncTab(sessions_client_, tab))
317 return; 338 return;
318 339
319 TabLinksMap::iterator local_tab_map_iter = local_tab_map_.find(tab_id); 340 TabLinksMap::iterator local_tab_map_iter = local_tab_map_.find(tab_id);
320 TabLink* tab_link = NULL; 341 TabLink* tab_link = NULL;
321 342
322 if (local_tab_map_iter == local_tab_map_.end()) { 343 if (local_tab_map_iter == local_tab_map_.end()) {
323 int tab_node_id = tab->GetSyncId(); 344 int tab_node_id = tab->GetSyncId();
324 // If there is an old sync node for the tab, reuse it. If this is a new 345 // If there is an old sync node for the tab, reuse it. If this is a new
325 // tab, get a sync node for it. 346 // tab, get a sync node for it.
326 if (!local_tab_pool_.IsUnassociatedTabNode(tab_node_id)) { 347 if (!local_tab_pool_.IsUnassociatedTabNode(tab_node_id)) {
(...skipping 19 matching lines...) Expand all
346 sync_pb::EntitySpecifics specifics; 367 sync_pb::EntitySpecifics specifics;
347 LocalTabDelegateToSpecifics(*tab, specifics.mutable_session()); 368 LocalTabDelegateToSpecifics(*tab, specifics.mutable_session());
348 syncer::SyncData data = syncer::SyncData::CreateLocalData( 369 syncer::SyncData data = syncer::SyncData::CreateLocalData(
349 TabNodePool::TabIdToTag(current_machine_tag_, 370 TabNodePool::TabIdToTag(current_machine_tag_,
350 tab_link->tab_node_id()), 371 tab_link->tab_node_id()),
351 current_session_name_, 372 current_session_name_,
352 specifics); 373 specifics);
353 change_output->push_back(syncer::SyncChange( 374 change_output->push_back(syncer::SyncChange(
354 FROM_HERE, syncer::SyncChange::ACTION_UPDATE, data)); 375 FROM_HERE, syncer::SyncChange::ACTION_UPDATE, data));
355 376
356 const GURL new_url = GetCurrentVirtualURL(*tab); 377 int current_index = tab->GetCurrentEntryIndex();
378 const GURL new_url = tab->GetVirtualURLAtIndex(current_index);
357 if (new_url != tab_link->url()) { 379 if (new_url != tab_link->url()) {
358 tab_link->set_url(new_url); 380 tab_link->set_url(new_url);
359 favicon_cache_.OnFaviconVisited(new_url, GetCurrentFaviconURL(*tab)); 381 favicon_cache_.OnFaviconVisited(new_url,
382 tab->GetFaviconURLAtIndex(current_index));
360 page_revisit_broadcaster_.OnPageVisit( 383 page_revisit_broadcaster_.OnPageVisit(
361 new_url, tab->GetCurrentEntryMaybePending()->GetTransitionType()); 384 new_url, tab->GetTransitionAtIndex(current_index));
362 } 385 }
363 386
364 session_tracker_.GetSession(current_machine_tag())->modified_time = 387 session_tracker_.GetSession(current_machine_tag())->modified_time =
365 base::Time::Now(); 388 base::Time::Now();
366 } 389 }
367 390
368 void SessionsSyncManager::RebuildAssociations() { 391 void SessionsSyncManager::RebuildAssociations() {
369 syncer::SyncDataList data( 392 syncer::SyncDataList data(
370 sync_processor_->GetAllSyncData(syncer::SESSIONS)); 393 sync_processor_->GetAllSyncData(syncer::SESSIONS));
371 scoped_ptr<syncer::SyncErrorFactory> error_handler(error_handler_.Pass()); 394 scoped_ptr<syncer::SyncErrorFactory> error_handler(error_handler_.Pass());
(...skipping 15 matching lines...) Expand all
387 const int tab_id = window.tab(j); 410 const int tab_id = window.tab(j);
388 bool success = session_tab_ids.insert(tab_id).second; 411 bool success = session_tab_ids.insert(tab_id).second;
389 if (!success) 412 if (!success)
390 return false; 413 return false;
391 } 414 }
392 } 415 }
393 416
394 return true; 417 return true;
395 } 418 }
396 419
397 void SessionsSyncManager::OnLocalTabModified(SyncedTabDelegate* modified_tab) { 420 bool SessionsSyncManager::OnLocalTabModified(SyncedTabDelegate* modified_tab) {
398 const content::NavigationEntry* entry = modified_tab->GetActiveEntry(); 421 if (!ShouldSyncTab(sessions_client_, modified_tab))
skym 2015/10/16 16:55:47 Won't this miss things like if you have a tab www
Nicolas Zea 2015/10/20 23:14:42 Good catch! You're right, previously we'd have rem
skym 2015/10/21 00:38:36 I'm a little sad to see this optimization go away,
399 if (!modified_tab->IsBeingDestroyed() && 422 return false;
400 entry && 423
401 entry->GetVirtualURL().is_valid() && 424 GURL virtual_url =
402 entry->GetVirtualURL().spec() == kNTPOpenTabSyncURL) { 425 modified_tab->GetVirtualURLAtIndex(modified_tab->GetCurrentEntryIndex());
426 if (!modified_tab->IsBeingDestroyed() && virtual_url.is_valid() &&
427 virtual_url.spec() == kNTPOpenTabSyncURL) {
403 DVLOG(1) << "Triggering sync refresh for sessions datatype."; 428 DVLOG(1) << "Triggering sync refresh for sessions datatype.";
404 const syncer::ModelTypeSet types(syncer::SESSIONS); 429 const syncer::ModelTypeSet types(syncer::SESSIONS);
405 content::NotificationService::current()->Notify( 430 content::NotificationService::current()->Notify(
406 chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, 431 chrome::NOTIFICATION_SYNC_REFRESH_LOCAL,
407 content::Source<Profile>(profile_), 432 content::Source<Profile>(profile_),
408 content::Details<const syncer::ModelTypeSet>(&types)); 433 content::Details<const syncer::ModelTypeSet>(&types));
409 } 434 }
410 435
411 if (local_tab_pool_out_of_sync_) { 436 if (local_tab_pool_out_of_sync_) {
412 // If our tab pool is corrupt, pay the price of a full re-association to 437 // If our tab pool is corrupt, pay the price of a full re-association to
413 // fix things up. This takes care of the new tab modification as well. 438 // fix things up. This takes care of the new tab modification as well.
414 RebuildAssociations(); 439 RebuildAssociations();
415 DCHECK(!local_tab_pool_out_of_sync_); 440 DCHECK(!local_tab_pool_out_of_sync_);
416 return; 441 return true;
417 } 442 }
418 443
419 syncer::SyncChangeList changes; 444 syncer::SyncChangeList changes;
420 // Associate tabs first so the synced session tracker is aware of them. 445 // Associate tabs first so the synced session tracker is aware of them.
421 AssociateTab(modified_tab, &changes); 446 AssociateTab(modified_tab, &changes);
422 // Note, we always associate windows because it's possible a tab became 447 // Note, we always associate windows because it's possible a tab became
skym 2015/10/16 16:55:47 It seems AssociateWindows gets called every time t
Nicolas Zea 2015/10/20 23:14:42 I'm not sure I understand your comment. What do yo
skym 2015/10/21 00:38:36 Oooh, good point, this is more complex than I real
423 // "interesting" by going to a valid URL, in which case it needs to be added 448 // "interesting" by going to a valid URL, in which case it needs to be added
424 // to the window's tab information. 449 // to the window's tab information.
425 AssociateWindows(DONT_RELOAD_TABS, syncer::SyncDataList(), &changes); 450 AssociateWindows(DONT_RELOAD_TABS, syncer::SyncDataList(), &changes);
426 sync_processor_->ProcessSyncChanges(FROM_HERE, changes); 451 sync_processor_->ProcessSyncChanges(FROM_HERE, changes);
452 return true;
427 } 453 }
428 454
429 void SessionsSyncManager::OnFaviconsChanged( 455 void SessionsSyncManager::OnFaviconsChanged(
430 const std::set<GURL>& page_urls, 456 const std::set<GURL>& page_urls,
431 const GURL& /* icon_url */) { 457 const GURL& /* icon_url */) {
432 // TODO(zea): consider a separate container for tabs with outstanding favicon 458 // TODO(zea): consider a separate container for tabs with outstanding favicon
433 // loads so we don't have to iterate through all tabs comparing urls. 459 // loads so we don't have to iterate through all tabs comparing urls.
434 for (const GURL& page_url : page_urls) { 460 for (const GURL& page_url : page_urls) {
435 for (TabLinksMap::iterator tab_iter = local_tab_map_.begin(); 461 for (TabLinksMap::iterator tab_iter = local_tab_map_.begin();
436 tab_iter != local_tab_map_.end(); 462 tab_iter != local_tab_map_.end();
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
877 const std::string& foreign_session_tag) { 903 const std::string& foreign_session_tag) {
878 if (foreign_session_tag == current_machine_tag()) { 904 if (foreign_session_tag == current_machine_tag()) {
879 DVLOG(1) << "Local session deleted! Doing nothing until a navigation is " 905 DVLOG(1) << "Local session deleted! Doing nothing until a navigation is "
880 << "triggered."; 906 << "triggered.";
881 return false; 907 return false;
882 } 908 }
883 DVLOG(1) << "Disassociating session " << foreign_session_tag; 909 DVLOG(1) << "Disassociating session " << foreign_session_tag;
884 return session_tracker_.DeleteSession(foreign_session_tag); 910 return session_tracker_.DeleteSession(foreign_session_tag);
885 } 911 }
886 912
887 // static
888 GURL SessionsSyncManager::GetCurrentVirtualURL(
889 const SyncedTabDelegate& tab_delegate) {
890 const NavigationEntry* current_entry =
891 tab_delegate.GetCurrentEntryMaybePending();
892 return current_entry->GetVirtualURL();
893 }
894
895 // static
896 GURL SessionsSyncManager::GetCurrentFaviconURL(
897 const SyncedTabDelegate& tab_delegate) {
898 const NavigationEntry* current_entry =
899 tab_delegate.GetCurrentEntryMaybePending();
900 return (current_entry->GetFavicon().valid ?
901 current_entry->GetFavicon().url :
902 GURL());
903 }
904
905 bool SessionsSyncManager::GetForeignSession( 913 bool SessionsSyncManager::GetForeignSession(
906 const std::string& tag, 914 const std::string& tag,
907 std::vector<const sessions::SessionWindow*>* windows) { 915 std::vector<const sessions::SessionWindow*>* windows) {
908 return session_tracker_.LookupSessionWindows(tag, windows); 916 return session_tracker_.LookupSessionWindows(tag, windows);
909 } 917 }
910 918
911 bool SessionsSyncManager::GetForeignSessionTabs( 919 bool SessionsSyncManager::GetForeignSessionTabs(
912 const std::string& tag, 920 const std::string& tag,
913 std::vector<const sessions::SessionTab*>* tabs) { 921 std::vector<const sessions::SessionTab*>* tabs) {
914 std::vector<const sessions::SessionWindow*> windows; 922 std::vector<const sessions::SessionWindow*> windows;
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 session_tab->user_agent_override.clear(); 1037 session_tab->user_agent_override.clear();
1030 session_tab->timestamp = mtime; 1038 session_tab->timestamp = mtime;
1031 const int current_index = tab_delegate.GetCurrentEntryIndex(); 1039 const int current_index = tab_delegate.GetCurrentEntryIndex();
1032 const int min_index = std::max(0, current_index - kMaxSyncNavigationCount); 1040 const int min_index = std::max(0, current_index - kMaxSyncNavigationCount);
1033 const int max_index = std::min(current_index + kMaxSyncNavigationCount, 1041 const int max_index = std::min(current_index + kMaxSyncNavigationCount,
1034 tab_delegate.GetEntryCount()); 1042 tab_delegate.GetEntryCount());
1035 bool is_supervised = tab_delegate.ProfileIsSupervised(); 1043 bool is_supervised = tab_delegate.ProfileIsSupervised();
1036 session_tab->navigations.clear(); 1044 session_tab->navigations.clear();
1037 1045
1038 for (int i = min_index; i < max_index; ++i) { 1046 for (int i = min_index; i < max_index; ++i) {
1039 const NavigationEntry* entry = tab_delegate.GetEntryAtIndexMaybePending(i); 1047 if (!tab_delegate.GetVirtualURLAtIndex(i).is_valid())
1040 DCHECK(entry);
1041 if (!entry->GetVirtualURL().is_valid())
1042 continue; 1048 continue;
1049 sessions::SerializedNavigationEntry serialized_entry;
1050 tab_delegate.GetSerializedNavigationAtIndex(i, &serialized_entry);
pavely 2015/10/16 21:55:20 Nit: It would make sense to move obtaining seriali
1043 1051
1044 // Set current_navigation_index to the index in navigations. 1052 // Set current_navigation_index to the index in navigations.
1045 if (i == current_index) 1053 if (i == current_index)
1046 session_tab->current_navigation_index = session_tab->navigations.size(); 1054 session_tab->current_navigation_index = session_tab->navigations.size();
1047 1055
1048 session_tab->navigations.push_back( 1056 session_tab->navigations.push_back(serialized_entry);
1049 ContentSerializedNavigationBuilder::FromNavigationEntry(i, *entry));
1050 if (is_supervised) { 1057 if (is_supervised) {
1051 session_tab->navigations.back().set_blocked_state( 1058 session_tab->navigations.back().set_blocked_state(
1052 SerializedNavigationEntry::STATE_ALLOWED); 1059 SerializedNavigationEntry::STATE_ALLOWED);
1053 } 1060 }
1054 } 1061 }
1055 1062
1056 // If the current navigation is invalid, set the index to the end of the 1063 // If the current navigation is invalid, set the index to the end of the
1057 // navigation array. 1064 // navigation array.
1058 if (session_tab->current_navigation_index < 0) { 1065 if (session_tab->current_navigation_index < 0) {
1059 session_tab->current_navigation_index = 1066 session_tab->current_navigation_index =
1060 session_tab->navigations.size() - 1; 1067 session_tab->navigations.size() - 1;
1061 } 1068 }
1062 1069
1063 if (is_supervised) { 1070 if (is_supervised) {
1064 const std::vector<const NavigationEntry*>& blocked_navigations = 1071 int offset = session_tab->navigations.size();
1072 const std::vector<const SerializedNavigationEntry*>& blocked_navigations =
1065 *tab_delegate.GetBlockedNavigations(); 1073 *tab_delegate.GetBlockedNavigations();
1066 int offset = session_tab->navigations.size();
1067 for (size_t i = 0; i < blocked_navigations.size(); ++i) { 1074 for (size_t i = 0; i < blocked_navigations.size(); ++i) {
1068 session_tab->navigations.push_back( 1075 session_tab->navigations.push_back(*blocked_navigations[i]);
1069 ContentSerializedNavigationBuilder::FromNavigationEntry( 1076 session_tab->navigations.back().set_index(offset + i);
1070 i + offset, *blocked_navigations[i]));
1071 session_tab->navigations.back().set_blocked_state( 1077 session_tab->navigations.back().set_blocked_state(
1072 SerializedNavigationEntry::STATE_BLOCKED); 1078 SerializedNavigationEntry::STATE_BLOCKED);
1073 // TODO(bauerb): Add categories 1079 // TODO(bauerb): Add categories
1074 } 1080 }
1075 } 1081 }
1076 session_tab->session_storage_persistent_id.clear(); 1082 session_tab->session_storage_persistent_id.clear();
1077 } 1083 }
1078 1084
1079 // static 1085 // static
1080 void SessionsSyncManager::SetVariationIds(sessions::SessionTab* session_tab) { 1086 void SessionsSyncManager::SetVariationIds(sessions::SessionTab* session_tab) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 << " with age " << session_age_in_days << ", deleting."; 1126 << " with age " << session_age_in_days << ", deleting.";
1121 DeleteForeignSessionInternal(session_tag, &changes); 1127 DeleteForeignSessionInternal(session_tag, &changes);
1122 } 1128 }
1123 } 1129 }
1124 1130
1125 if (!changes.empty()) 1131 if (!changes.empty())
1126 sync_processor_->ProcessSyncChanges(FROM_HERE, changes); 1132 sync_processor_->ProcessSyncChanges(FROM_HERE, changes);
1127 } 1133 }
1128 1134
1129 }; // namespace browser_sync 1135 }; // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698