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

Side by Side Diff: components/sync_sessions/sessions_sync_manager.cc

Issue 2750163003: Prevent tabs sync during browser shutdown.
Patch Set: Created 3 years, 9 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 "components/sync_sessions/sessions_sync_manager.h" 5 #include "components/sync_sessions/sessions_sync_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/format_macros.h" 10 #include "base/format_macros.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 LocalDeviceInfoProvider* local_device, 121 LocalDeviceInfoProvider* local_device,
122 std::unique_ptr<LocalSessionEventRouter> router, 122 std::unique_ptr<LocalSessionEventRouter> router,
123 const base::Closure& sessions_updated_callback, 123 const base::Closure& sessions_updated_callback,
124 const base::Closure& datatype_refresh_callback) 124 const base::Closure& datatype_refresh_callback)
125 : sessions_client_(sessions_client), 125 : sessions_client_(sessions_client),
126 session_tracker_(sessions_client), 126 session_tracker_(sessions_client),
127 favicon_cache_(sessions_client->GetFaviconService(), 127 favicon_cache_(sessions_client->GetFaviconService(),
128 sessions_client->GetHistoryService(), 128 sessions_client->GetHistoryService(),
129 kMaxSyncFavicons), 129 kMaxSyncFavicons),
130 local_tab_pool_out_of_sync_(true), 130 local_tab_pool_out_of_sync_(true),
131 all_browsers_closing_(false),
131 sync_prefs_(sync_prefs), 132 sync_prefs_(sync_prefs),
132 local_device_(local_device), 133 local_device_(local_device),
133 current_device_type_(sync_pb::SyncEnums_DeviceType_TYPE_OTHER), 134 current_device_type_(sync_pb::SyncEnums_DeviceType_TYPE_OTHER),
134 local_session_header_node_id_(TabNodePool::kInvalidTabNodeID), 135 local_session_header_node_id_(TabNodePool::kInvalidTabNodeID),
135 stale_session_threshold_days_(kDefaultStaleSessionThresholdDays), 136 stale_session_threshold_days_(kDefaultStaleSessionThresholdDays),
136 local_event_router_(std::move(router)), 137 local_event_router_(std::move(router)),
137 page_revisit_broadcaster_(this, sessions_client), 138 page_revisit_broadcaster_(this, sessions_client),
138 sessions_updated_callback_(sessions_updated_callback), 139 sessions_updated_callback_(sessions_updated_callback),
139 datatype_refresh_callback_(datatype_refresh_callback) {} 140 datatype_refresh_callback_(datatype_refresh_callback) {}
140 141
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 } 463 }
463 464
464 if (local_tab_pool_out_of_sync_) { 465 if (local_tab_pool_out_of_sync_) {
465 // If our tab pool is corrupt, pay the price of a full re-association to 466 // If our tab pool is corrupt, pay the price of a full re-association to
466 // fix things up. This takes care of the new tab modification as well. 467 // fix things up. This takes care of the new tab modification as well.
467 bool rebuild_association_succeeded = RebuildAssociations(); 468 bool rebuild_association_succeeded = RebuildAssociations();
468 DCHECK(!rebuild_association_succeeded || !local_tab_pool_out_of_sync_); 469 DCHECK(!rebuild_association_succeeded || !local_tab_pool_out_of_sync_);
469 return; 470 return;
470 } 471 }
471 472
473 if (all_browsers_closing_) {
474 // Do not sync tabs closing during browser shutdown.
475 return;
476 }
477
472 syncer::SyncChangeList changes; 478 syncer::SyncChangeList changes;
473 AssociateTab(modified_tab, &changes); 479 AssociateTab(modified_tab, &changes);
474 // Note, we always associate windows because it's possible a tab became 480 // Note, we always associate windows because it's possible a tab became
475 // "interesting" by going to a valid URL, in which case it needs to be added 481 // "interesting" by going to a valid URL, in which case it needs to be added
476 // to the window's tab information. Similarly, if a tab became 482 // to the window's tab information. Similarly, if a tab became
477 // "uninteresting", we remove it from the window's tab information. 483 // "uninteresting", we remove it from the window's tab information.
478 AssociateWindows(DONT_RELOAD_TABS, &changes); 484 AssociateWindows(DONT_RELOAD_TABS, &changes);
479 sync_processor_->ProcessSyncChanges(FROM_HERE, changes); 485 sync_processor_->ProcessSyncChanges(FROM_HERE, changes);
480 } 486 }
481 487
482 void SessionsSyncManager::OnFaviconsChanged(const std::set<GURL>& page_urls, 488 void SessionsSyncManager::OnFaviconsChanged(const std::set<GURL>& page_urls,
483 const GURL& /* icon_url */) { 489 const GURL& /* icon_url */) {
484 for (const GURL& page_url : page_urls) 490 for (const GURL& page_url : page_urls)
485 favicon_cache_.OnPageFaviconUpdated(page_url); 491 favicon_cache_.OnPageFaviconUpdated(page_url);
486 } 492 }
487 493
494 void SessionsSyncManager::SetAllBrowsersClosing(bool browsers_closing) {
495 all_browsers_closing_ = browsers_closing;
496 }
497
498 bool SessionsSyncManager::GetAllBrowsersClosingForTesting() {
499 return all_browsers_closing_;
500 }
501
488 void SessionsSyncManager::StopSyncing(syncer::ModelType type) { 502 void SessionsSyncManager::StopSyncing(syncer::ModelType type) {
489 local_event_router_->Stop(); 503 local_event_router_->Stop();
490 if (sync_processor_.get() && lost_navigations_recorder_.get()) { 504 if (sync_processor_.get() && lost_navigations_recorder_.get()) {
491 sync_processor_->RemoveLocalChangeObserver( 505 sync_processor_->RemoveLocalChangeObserver(
492 lost_navigations_recorder_.get()); 506 lost_navigations_recorder_.get());
493 lost_navigations_recorder_.reset(); 507 lost_navigations_recorder_.reset();
494 } 508 }
495 sync_processor_.reset(nullptr); 509 sync_processor_.reset(nullptr);
496 error_handler_.reset(); 510 error_handler_.reset();
497 session_tracker_.Clear(); 511 session_tracker_.Clear();
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after
1139 } 1153 }
1140 1154
1141 // static 1155 // static
1142 std::string SessionsSyncManager::TagHashFromSpecifics( 1156 std::string SessionsSyncManager::TagHashFromSpecifics(
1143 const sync_pb::SessionSpecifics& specifics) { 1157 const sync_pb::SessionSpecifics& specifics) {
1144 return syncer::GenerateSyncableHash(syncer::SESSIONS, 1158 return syncer::GenerateSyncableHash(syncer::SESSIONS,
1145 TagFromSpecifics(specifics)); 1159 TagFromSpecifics(specifics));
1146 } 1160 }
1147 1161
1148 }; // namespace sync_sessions 1162 }; // namespace sync_sessions
OLDNEW
« no previous file with comments | « components/sync_sessions/sessions_sync_manager.h ('k') | components/sync_sessions/sessions_sync_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698