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

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

Issue 2461463002: [Sync] Replacing NULL with nullptr/null throughout sync code. (Closed)
Patch Set: Reverted PROFILE_nullptr mistake. Created 4 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 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/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 windows.begin(); 223 windows.begin();
224 i != windows.end(); ++i) { 224 i != windows.end(); ++i) {
225 if (option == RELOAD_TABS) { 225 if (option == RELOAD_TABS) {
226 UMA_HISTOGRAM_COUNTS("Sync.SessionTabs", (*i)->GetTabCount()); 226 UMA_HISTOGRAM_COUNTS("Sync.SessionTabs", (*i)->GetTabCount());
227 } 227 }
228 228
229 // Make sure the window has tabs and a viewable window. The viewable window 229 // Make sure the window has tabs and a viewable window. The viewable window
230 // check is necessary because, for example, when a browser is closed the 230 // check is necessary because, for example, when a browser is closed the
231 // destructor is not necessarily run immediately. This means its possible 231 // destructor is not necessarily run immediately. This means its possible
232 // for us to get a handle to a browser that is about to be removed. If 232 // for us to get a handle to a browser that is about to be removed. If
233 // the tab count is 0 or the window is NULL, the browser is about to be 233 // the tab count is 0 or the window is null, the browser is about to be
234 // deleted, so we ignore it. 234 // deleted, so we ignore it.
235 if ((*i)->ShouldSync() && (*i)->GetTabCount() && (*i)->HasWindow()) { 235 if ((*i)->ShouldSync() && (*i)->GetTabCount() && (*i)->HasWindow()) {
236 sync_pb::SessionWindow window_s; 236 sync_pb::SessionWindow window_s;
237 SessionID::id_type window_id = (*i)->GetSessionId(); 237 SessionID::id_type window_id = (*i)->GetSessionId();
238 DVLOG(1) << "Associating window " << window_id << " with " 238 DVLOG(1) << "Associating window " << window_id << " with "
239 << (*i)->GetTabCount() << " tabs."; 239 << (*i)->GetTabCount() << " tabs.";
240 window_s.set_window_id(window_id); 240 window_s.set_window_id(window_id);
241 // Note: We don't bother to set selected tab index anymore. We still 241 // Note: We don't bother to set selected tab index anymore. We still
242 // consume it when receiving foreign sessions, as reading it is free, but 242 // consume it when receiving foreign sessions, as reading it is free, but
243 // it triggers too many sync cycles with too little value to make setting 243 // it triggers too many sync cycles with too little value to make setting
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 } 276 }
277 277
278 if (RELOAD_TABS == option) 278 if (RELOAD_TABS == option)
279 AssociateTab(synced_tab, change_output); 279 AssociateTab(synced_tab, change_output);
280 280
281 // If the tab is valid, it would have been added to the tracker either 281 // If the tab is valid, it would have been added to the tracker either
282 // by the above AssociateTab call (at association time), or by the 282 // by the above AssociateTab call (at association time), or by the
283 // change processor calling AssociateTab for all modified tabs. 283 // change processor calling AssociateTab for all modified tabs.
284 // Therefore, we can key whether this window has valid tabs based on 284 // Therefore, we can key whether this window has valid tabs based on
285 // the tab's presence in the tracker. 285 // the tab's presence in the tracker.
286 const sessions::SessionTab* tab = NULL; 286 const sessions::SessionTab* tab = nullptr;
287 if (session_tracker_.LookupSessionTab(local_tag, tab_id, &tab)) { 287 if (session_tracker_.LookupSessionTab(local_tag, tab_id, &tab)) {
288 found_tabs = true; 288 found_tabs = true;
289 window_s.add_tab(tab_id); 289 window_s.add_tab(tab_id);
290 } 290 }
291 } 291 }
292 if (found_tabs) { 292 if (found_tabs) {
293 sync_pb::SessionWindow* header_window = header_s->add_window(); 293 sync_pb::SessionWindow* header_window = header_s->add_window();
294 *header_window = window_s; 294 *header_window = window_s;
295 295
296 // Update this window's representation in the synced session tracker. 296 // Update this window's representation in the synced session tracker.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 } 329 }
330 local_tab_pool_.FreeTabNode(tab_iter->second->tab_node_id(), change_output); 330 local_tab_pool_.FreeTabNode(tab_iter->second->tab_node_id(), change_output);
331 local_tab_map_.erase(tab_iter); 331 local_tab_map_.erase(tab_iter);
332 return; 332 return;
333 } 333 }
334 334
335 if (!tab->ShouldSync(sessions_client_)) 335 if (!tab->ShouldSync(sessions_client_))
336 return; 336 return;
337 337
338 TabLinksMap::iterator local_tab_map_iter = local_tab_map_.find(tab_id); 338 TabLinksMap::iterator local_tab_map_iter = local_tab_map_.find(tab_id);
339 TabLink* tab_link = NULL; 339 TabLink* tab_link = nullptr;
340 340
341 if (local_tab_map_iter == local_tab_map_.end()) { 341 if (local_tab_map_iter == local_tab_map_.end()) {
342 int tab_node_id = tab->GetSyncId(); 342 int tab_node_id = tab->GetSyncId();
343 // If there is an old sync node for the tab, reuse it. If this is a new 343 // If there is an old sync node for the tab, reuse it. If this is a new
344 // tab, get a sync node for it. 344 // tab, get a sync node for it.
345 if (!local_tab_pool_.IsUnassociatedTabNode(tab_node_id)) { 345 if (!local_tab_pool_.IsUnassociatedTabNode(tab_node_id)) {
346 tab_node_id = local_tab_pool_.GetFreeTabNode(change_output); 346 tab_node_id = local_tab_pool_.GetFreeTabNode(change_output);
347 tab->SetSyncId(tab_node_id); 347 tab->SetSyncId(tab_node_id);
348 } 348 }
349 local_tab_pool_.AssociateTabNode(tab_node_id, tab_id); 349 local_tab_pool_.AssociateTabNode(tab_node_id, tab_id);
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 } 457 }
458 } 458 }
459 459
460 void SessionsSyncManager::StopSyncing(syncer::ModelType type) { 460 void SessionsSyncManager::StopSyncing(syncer::ModelType type) {
461 local_event_router_->Stop(); 461 local_event_router_->Stop();
462 if (sync_processor_.get() && lost_navigations_recorder_.get()) { 462 if (sync_processor_.get() && lost_navigations_recorder_.get()) {
463 sync_processor_->RemoveLocalChangeObserver( 463 sync_processor_->RemoveLocalChangeObserver(
464 lost_navigations_recorder_.get()); 464 lost_navigations_recorder_.get());
465 lost_navigations_recorder_.reset(); 465 lost_navigations_recorder_.reset();
466 } 466 }
467 sync_processor_.reset(NULL); 467 sync_processor_.reset(nullptr);
468 error_handler_.reset(); 468 error_handler_.reset();
469 session_tracker_.Clear(); 469 session_tracker_.Clear();
470 local_tab_map_.clear(); 470 local_tab_map_.clear();
471 local_tab_pool_.Clear(); 471 local_tab_pool_.Clear();
472 current_machine_tag_.clear(); 472 current_machine_tag_.clear();
473 current_session_name_.clear(); 473 current_session_name_.clear();
474 local_session_header_node_id_ = TabNodePool::kInvalidTabNodeID; 474 local_session_header_node_id_ = TabNodePool::kInvalidTabNodeID;
475 } 475 }
476 476
477 syncer::SyncDataList SessionsSyncManager::GetAllSyncData( 477 syncer::SyncDataList SessionsSyncManager::GetAllSyncData(
478 syncer::ModelType type) const { 478 syncer::ModelType type) const {
479 syncer::SyncDataList list; 479 syncer::SyncDataList list;
480 const SyncedSession* session = NULL; 480 const SyncedSession* session = nullptr;
481 if (!session_tracker_.LookupLocalSession(&session)) 481 if (!session_tracker_.LookupLocalSession(&session))
482 return syncer::SyncDataList(); 482 return syncer::SyncDataList();
483 483
484 // First construct the header node. 484 // First construct the header node.
485 sync_pb::EntitySpecifics header_entity; 485 sync_pb::EntitySpecifics header_entity;
486 header_entity.mutable_session()->set_session_tag(current_machine_tag()); 486 header_entity.mutable_session()->set_session_tag(current_machine_tag());
487 sync_pb::SessionHeader* header_specifics = 487 sync_pb::SessionHeader* header_specifics =
488 header_entity.mutable_session()->mutable_header(); 488 header_entity.mutable_session()->mutable_header();
489 header_specifics->MergeFrom(session->ToSessionHeader()); 489 header_specifics->MergeFrom(session->ToSessionHeader());
490 syncer::SyncData data = syncer::SyncData::CreateLocalData( 490 syncer::SyncData data = syncer::SyncData::CreateLocalData(
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 tabs->push_back(tab); 940 tabs->push_back(tab);
941 } 941 }
942 } 942 }
943 std::sort(tabs->begin(), tabs->end(), TabsRecencyComparator); 943 std::sort(tabs->begin(), tabs->end(), TabsRecencyComparator);
944 return true; 944 return true;
945 } 945 }
946 946
947 bool SessionsSyncManager::GetForeignTab(const std::string& tag, 947 bool SessionsSyncManager::GetForeignTab(const std::string& tag,
948 const SessionID::id_type tab_id, 948 const SessionID::id_type tab_id,
949 const sessions::SessionTab** tab) { 949 const sessions::SessionTab** tab) {
950 const sessions::SessionTab* synced_tab = NULL; 950 const sessions::SessionTab* synced_tab = nullptr;
951 bool success = session_tracker_.LookupSessionTab(tag, tab_id, &synced_tab); 951 bool success = session_tracker_.LookupSessionTab(tag, tab_id, &synced_tab);
952 if (success) 952 if (success)
953 *tab = synced_tab; 953 *tab = synced_tab;
954 return success; 954 return success;
955 } 955 }
956 956
957 void SessionsSyncManager::LocalTabDelegateToSpecifics( 957 void SessionsSyncManager::LocalTabDelegateToSpecifics(
958 const SyncedTabDelegate& tab_delegate, 958 const SyncedTabDelegate& tab_delegate,
959 sync_pb::SessionSpecifics* specifics) { 959 sync_pb::SessionSpecifics* specifics) {
960 sessions::SessionTab* session_tab = NULL; 960 sessions::SessionTab* session_tab = nullptr;
961 session_tab = session_tracker_.GetTab(current_machine_tag(), 961 session_tab = session_tracker_.GetTab(current_machine_tag(),
962 tab_delegate.GetSessionId(), 962 tab_delegate.GetSessionId(),
963 tab_delegate.GetSyncId()); 963 tab_delegate.GetSyncId());
964 SetSessionTabFromDelegate(tab_delegate, base::Time::Now(), session_tab); 964 SetSessionTabFromDelegate(tab_delegate, base::Time::Now(), session_tab);
965 SetVariationIds(session_tab); 965 SetVariationIds(session_tab);
966 sync_pb::SessionTab tab_s = session_tab->ToSyncData(); 966 sync_pb::SessionTab tab_s = session_tab->ToSyncData();
967 specifics->set_session_tag(current_machine_tag_); 967 specifics->set_session_tag(current_machine_tag_);
968 specifics->set_tab_node_id(tab_delegate.GetSyncId()); 968 specifics->set_tab_node_id(tab_delegate.GetSyncId());
969 specifics->mutable_tab()->CopyFrom(tab_s); 969 specifics->mutable_tab()->CopyFrom(tab_s);
970 } 970 }
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1125 } 1125 }
1126 1126
1127 // static 1127 // static
1128 std::string SessionsSyncManager::TagHashFromSpecifics( 1128 std::string SessionsSyncManager::TagHashFromSpecifics(
1129 const sync_pb::SessionSpecifics& specifics) { 1129 const sync_pb::SessionSpecifics& specifics) {
1130 return syncer::syncable::GenerateSyncableHash(syncer::SESSIONS, 1130 return syncer::syncable::GenerateSyncableHash(syncer::SESSIONS,
1131 TagFromSpecifics(specifics)); 1131 TagFromSpecifics(specifics));
1132 } 1132 }
1133 1133
1134 }; // namespace sync_sessions 1134 }; // namespace sync_sessions
OLDNEW
« no previous file with comments | « components/sync_sessions/session_data_type_controller_unittest.cc ('k') | components/sync_sessions/sync_sessions_metrics.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698