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

Side by Side Diff: components/browser_sync/profile_sync_service.cc

Issue 2422253002: [Sync] Rewriting ".reset(new" pattern to use "= base::MakeUnique" instead. (Closed)
Patch Set: Fixing compile. Created 4 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 (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 "components/browser_sync/profile_sync_service.h" 5 #include "components/browser_sync/profile_sync_service.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <cstddef> 9 #include <cstddef>
10 #include <map> 10 #include <map>
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 256
257 bool ProfileSyncService::CanSyncStart() const { 257 bool ProfileSyncService::CanSyncStart() const {
258 return IsSyncAllowed() && IsSyncRequested() && IsSignedIn(); 258 return IsSyncAllowed() && IsSyncRequested() && IsSignedIn();
259 } 259 }
260 260
261 void ProfileSyncService::Initialize() { 261 void ProfileSyncService::Initialize() {
262 sync_client_->Initialize(); 262 sync_client_->Initialize();
263 263
264 // We don't pass StartupController an Unretained reference to future-proof 264 // We don't pass StartupController an Unretained reference to future-proof
265 // against the controller impl changing to post tasks. 265 // against the controller impl changing to post tasks.
266 startup_controller_.reset(new syncer::StartupController( 266 startup_controller_ = base::MakeUnique<syncer::StartupController>(
267 &sync_prefs_, 267 &sync_prefs_,
268 base::Bind(&ProfileSyncService::CanBackendStart, base::Unretained(this)), 268 base::Bind(&ProfileSyncService::CanBackendStart, base::Unretained(this)),
269 base::Bind(&ProfileSyncService::StartUpSlowBackendComponents, 269 base::Bind(&ProfileSyncService::StartUpSlowBackendComponents,
270 weak_factory_.GetWeakPtr()))); 270 weak_factory_.GetWeakPtr()));
271 std::unique_ptr<sync_sessions::LocalSessionEventRouter> router( 271 std::unique_ptr<sync_sessions::LocalSessionEventRouter> router(
272 sync_client_->GetSyncSessionsClient()->GetLocalSessionEventRouter()); 272 sync_client_->GetSyncSessionsClient()->GetLocalSessionEventRouter());
273 local_device_ = sync_client_->GetSyncApiComponentFactory() 273 local_device_ = sync_client_->GetSyncApiComponentFactory()
274 ->CreateLocalDeviceInfoProvider(); 274 ->CreateLocalDeviceInfoProvider();
275 sync_stopped_reporter_.reset(new syncer::SyncStoppedReporter( 275 sync_stopped_reporter_ = base::MakeUnique<syncer::SyncStoppedReporter>(
276 sync_service_url_, local_device_->GetSyncUserAgent(), 276 sync_service_url_, local_device_->GetSyncUserAgent(),
277 url_request_context_, syncer::SyncStoppedReporter::ResultCallback())); 277 url_request_context_, syncer::SyncStoppedReporter::ResultCallback());
278 sessions_sync_manager_.reset(new SessionsSyncManager( 278 sessions_sync_manager_ = base::MakeUnique<SessionsSyncManager>(
279 sync_client_->GetSyncSessionsClient(), &sync_prefs_, local_device_.get(), 279 sync_client_->GetSyncSessionsClient(), &sync_prefs_, local_device_.get(),
280 std::move(router), 280 std::move(router),
281 base::Bind(&ProfileSyncService::NotifyForeignSessionUpdated, 281 base::Bind(&ProfileSyncService::NotifyForeignSessionUpdated,
282 sync_enabled_weak_factory_.GetWeakPtr()), 282 sync_enabled_weak_factory_.GetWeakPtr()),
283 base::Bind(&ProfileSyncService::TriggerRefresh, 283 base::Bind(&ProfileSyncService::TriggerRefresh,
284 sync_enabled_weak_factory_.GetWeakPtr(), 284 sync_enabled_weak_factory_.GetWeakPtr(),
285 syncer::ModelTypeSet(syncer::SESSIONS)))); 285 syncer::ModelTypeSet(syncer::SESSIONS)));
286 286
287 if (base::FeatureList::IsEnabled(switches::kSyncUSSDeviceInfo)) { 287 if (base::FeatureList::IsEnabled(switches::kSyncUSSDeviceInfo)) {
288 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner( 288 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner(
289 blocking_pool_->GetSequencedTaskRunnerWithShutdownBehavior( 289 blocking_pool_->GetSequencedTaskRunnerWithShutdownBehavior(
290 blocking_pool_->GetSequenceToken(), 290 blocking_pool_->GetSequenceToken(),
291 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); 291 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN));
292 // TODO(skym): Stop creating leveldb files when signed out. 292 // TODO(skym): Stop creating leveldb files when signed out.
293 // TODO(skym): Verify using AsUTF8Unsafe is okay here. Should work as long 293 // TODO(skym): Verify using AsUTF8Unsafe is okay here. Should work as long
294 // as the Local State file is guaranteed to be UTF-8. 294 // as the Local State file is guaranteed to be UTF-8.
295 device_info_service_.reset(new DeviceInfoService( 295 device_info_service_ = base::MakeUnique<DeviceInfoService>(
296 local_device_.get(), 296 local_device_.get(),
297 base::Bind(&ModelTypeStore::CreateStore, syncer::DEVICE_INFO, 297 base::Bind(&ModelTypeStore::CreateStore, syncer::DEVICE_INFO,
298 directory_path_.Append(base::FilePath(kLevelDBFolderName)) 298 directory_path_.Append(base::FilePath(kLevelDBFolderName))
299 .AsUTF8Unsafe(), 299 .AsUTF8Unsafe(),
300 blocking_task_runner), 300 blocking_task_runner),
301 base::Bind(&ModelTypeChangeProcessor::Create))); 301 base::Bind(&ModelTypeChangeProcessor::Create));
302 } else { 302 } else {
303 device_info_sync_service_.reset( 303 device_info_sync_service_ =
304 new DeviceInfoSyncService(local_device_.get())); 304 base::MakeUnique<DeviceInfoSyncService>(local_device_.get());
305 } 305 }
306 306
307 syncer::SyncApiComponentFactory::RegisterDataTypesMethod 307 syncer::SyncApiComponentFactory::RegisterDataTypesMethod
308 register_platform_types_callback = 308 register_platform_types_callback =
309 sync_client_->GetRegisterPlatformTypesCallback(); 309 sync_client_->GetRegisterPlatformTypesCallback();
310 sync_client_->GetSyncApiComponentFactory()->RegisterDataTypes( 310 sync_client_->GetSyncApiComponentFactory()->RegisterDataTypes(
311 this, register_platform_types_callback); 311 this, register_platform_types_callback);
312 312
313 if (gaia_cookie_manager_service_) 313 if (gaia_cookie_manager_service_)
314 gaia_cookie_manager_service_->AddObserver(this); 314 gaia_cookie_manager_service_->AddObserver(this);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 std::string bootstrap_token = sync_prefs_.GetEncryptionBootstrapToken(); 359 std::string bootstrap_token = sync_prefs_.GetEncryptionBootstrapToken();
360 if (bootstrap_token.empty()) { 360 if (bootstrap_token.empty()) {
361 sync_prefs_.SetEncryptionBootstrapToken( 361 sync_prefs_.SetEncryptionBootstrapToken(
362 sync_prefs_.GetSpareBootstrapToken()); 362 sync_prefs_.GetSpareBootstrapToken());
363 } 363 }
364 #endif 364 #endif
365 365
366 #if !defined(OS_ANDROID) 366 #if !defined(OS_ANDROID)
367 DCHECK(sync_error_controller_ == NULL) 367 DCHECK(sync_error_controller_ == NULL)
368 << "Initialize() called more than once."; 368 << "Initialize() called more than once.";
369 sync_error_controller_.reset(new syncer::SyncErrorController(this)); 369 sync_error_controller_ = base::MakeUnique<syncer::SyncErrorController>(this);
370 AddObserver(sync_error_controller_.get()); 370 AddObserver(sync_error_controller_.get());
371 #endif 371 #endif
372 372
373 memory_pressure_listener_.reset(new base::MemoryPressureListener( 373 memory_pressure_listener_ = base::MakeUnique<base::MemoryPressureListener>(
374 base::Bind(&ProfileSyncService::OnMemoryPressure, 374 base::Bind(&ProfileSyncService::OnMemoryPressure,
375 sync_enabled_weak_factory_.GetWeakPtr()))); 375 sync_enabled_weak_factory_.GetWeakPtr()));
376 startup_controller_->Reset(GetRegisteredDataTypes()); 376 startup_controller_->Reset(GetRegisteredDataTypes());
377 377
378 // Auto-start means means the first time the profile starts up, sync should 378 // Auto-start means means the first time the profile starts up, sync should
379 // start up immediately. 379 // start up immediately.
380 if (start_behavior_ == AUTO_START && IsSyncRequested() && 380 if (start_behavior_ == AUTO_START && IsSyncRequested() &&
381 !IsFirstSetupComplete()) { 381 !IsFirstSetupComplete()) {
382 startup_controller_->TryStartImmediately(); 382 startup_controller_->TryStartImmediately();
383 } else { 383 } else {
384 startup_controller_->TryStart(); 384 startup_controller_->TryStart();
385 } 385 }
(...skipping 1360 matching lines...) Expand 10 before | Expand all | Expand 10 after
1746 1746
1747 bool restart = false; 1747 bool restart = false;
1748 if (!data_type_manager_) { 1748 if (!data_type_manager_) {
1749 restart = true; 1749 restart = true;
1750 data_type_manager_.reset( 1750 data_type_manager_.reset(
1751 sync_client_->GetSyncApiComponentFactory()->CreateDataTypeManager( 1751 sync_client_->GetSyncApiComponentFactory()->CreateDataTypeManager(
1752 debug_info_listener_, &data_type_controllers_, this, backend_.get(), 1752 debug_info_listener_, &data_type_controllers_, this, backend_.get(),
1753 this)); 1753 this));
1754 1754
1755 // We create the migrator at the same time. 1755 // We create the migrator at the same time.
1756 migrator_.reset(new BackendMigrator( 1756 migrator_ = base::MakeUnique<BackendMigrator>(
1757 debug_identifier_, GetUserShare(), this, data_type_manager_.get(), 1757 debug_identifier_, GetUserShare(), this, data_type_manager_.get(),
1758 base::Bind(&ProfileSyncService::StartSyncingWithServer, 1758 base::Bind(&ProfileSyncService::StartSyncingWithServer,
1759 base::Unretained(this)))); 1759 base::Unretained(this)));
1760 } 1760 }
1761 1761
1762 syncer::ModelTypeSet types; 1762 syncer::ModelTypeSet types;
1763 syncer::ConfigureReason reason = syncer::CONFIGURE_REASON_UNKNOWN; 1763 syncer::ConfigureReason reason = syncer::CONFIGURE_REASON_UNKNOWN;
1764 types = GetPreferredDataTypes(); 1764 types = GetPreferredDataTypes();
1765 if (restart) { 1765 if (restart) {
1766 // Datatype downloads on restart are generally due to newly supported 1766 // Datatype downloads on restart are generally due to newly supported
1767 // datatypes (although it's also possible we're picking up where a failed 1767 // datatypes (although it's also possible we're picking up where a failed
1768 // previous configuration left off). 1768 // previous configuration left off).
1769 // TODO(sync): consider detecting configuration recovery and setting 1769 // TODO(sync): consider detecting configuration recovery and setting
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1844 type_status_header->SetString("status", "header"); 1844 type_status_header->SetString("status", "header");
1845 type_status_header->SetString("value", "Group Type"); 1845 type_status_header->SetString("value", "Group Type");
1846 type_status_header->SetString("num_entries", "Total Entries"); 1846 type_status_header->SetString("num_entries", "Total Entries");
1847 type_status_header->SetString("num_live", "Live Entries"); 1847 type_status_header->SetString("num_live", "Live Entries");
1848 result->Append(std::move(type_status_header)); 1848 result->Append(std::move(type_status_header));
1849 1849
1850 std::unique_ptr<base::DictionaryValue> type_status; 1850 std::unique_ptr<base::DictionaryValue> type_status;
1851 for (ModelTypeSet::Iterator it = registered.First(); it.Good(); it.Inc()) { 1851 for (ModelTypeSet::Iterator it = registered.First(); it.Good(); it.Inc()) {
1852 ModelType type = it.Get(); 1852 ModelType type = it.Get();
1853 1853
1854 type_status.reset(new base::DictionaryValue()); 1854 type_status = base::MakeUnique<base::DictionaryValue>();
1855 type_status->SetString("name", ModelTypeToString(type)); 1855 type_status->SetString("name", ModelTypeToString(type));
1856 1856
1857 if (error_map.find(type) != error_map.end()) { 1857 if (error_map.find(type) != error_map.end()) {
1858 const syncer::SyncError& error = error_map.find(type)->second; 1858 const syncer::SyncError& error = error_map.find(type)->second;
1859 DCHECK(error.IsSet()); 1859 DCHECK(error.IsSet());
1860 switch (error.GetSeverity()) { 1860 switch (error.GetSeverity()) {
1861 case syncer::SyncError::SYNC_ERROR_SEVERITY_ERROR: 1861 case syncer::SyncError::SYNC_ERROR_SEVERITY_ERROR:
1862 type_status->SetString("status", "error"); 1862 type_status->SetString("status", "error");
1863 type_status->SetString( 1863 type_status->SetString(
1864 "value", "Error: " + error.location().ToString() + ", " + 1864 "value", "Error: " + error.location().ToString() + ", " +
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after
2498 2498
2499 DCHECK(startup_controller_->IsSetupInProgress()); 2499 DCHECK(startup_controller_->IsSetupInProgress());
2500 startup_controller_->SetSetupInProgress(false); 2500 startup_controller_->SetSetupInProgress(false);
2501 2501
2502 if (IsBackendInitialized()) 2502 if (IsBackendInitialized())
2503 ReconfigureDatatypeManager(); 2503 ReconfigureDatatypeManager();
2504 NotifyObservers(); 2504 NotifyObservers();
2505 } 2505 }
2506 2506
2507 } // namespace browser_sync 2507 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698