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

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

Issue 2568743004: [Sync] Stop deleting LevelDB files when deleting Directory (Closed)
Patch Set: Updated for Max's comments. Created 3 years, 12 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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 // has no significant state, -1 to never discard. 165 // has no significant state, -1 to never discard.
166 -1, 166 -1,
167 167
168 // Don't use initial delay unless the last request was an error. 168 // Don't use initial delay unless the last request was an error.
169 false, 169 false,
170 }; 170 };
171 171
172 const base::FilePath::CharType kLevelDBFolderName[] = 172 const base::FilePath::CharType kLevelDBFolderName[] =
173 FILE_PATH_LITERAL("LevelDB"); 173 FILE_PATH_LITERAL("LevelDB");
174 174
175 // Perform the actual sync data folder deletion.
176 // This should only be called on the sync thread.
177 void DeleteSyncDataFolder(const base::FilePath& directory_path) {
178 if (base::DirectoryExists(directory_path)) {
179 if (!base::DeleteFile(directory_path, true))
180 LOG(DFATAL) << "Could not delete the Sync Data folder.";
181 }
182 }
183
184 } // namespace 175 } // namespace
185 176
186 ProfileSyncService::InitParams::InitParams() = default; 177 ProfileSyncService::InitParams::InitParams() = default;
187 ProfileSyncService::InitParams::InitParams(InitParams&& other) = default; 178 ProfileSyncService::InitParams::InitParams(InitParams&& other) = default;
188 ProfileSyncService::InitParams::~InitParams() = default; 179 ProfileSyncService::InitParams::~InitParams() = default;
189 180
190 ProfileSyncService::ProfileSyncService(InitParams init_params) 181 ProfileSyncService::ProfileSyncService(InitParams init_params)
191 : SyncServiceBase(std::move(init_params.sync_client), 182 : SyncServiceBase(std::move(init_params.sync_client),
192 std::move(init_params.signin_wrapper), 183 std::move(init_params.signin_wrapper),
193 init_params.channel, 184 init_params.channel,
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 syncer::ModelTypeSet(syncer::SESSIONS))); 272 syncer::ModelTypeSet(syncer::SESSIONS)));
282 273
283 if (base::FeatureList::IsEnabled(switches::kSyncUSSDeviceInfo)) { 274 if (base::FeatureList::IsEnabled(switches::kSyncUSSDeviceInfo)) {
284 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner( 275 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner(
285 blocking_pool_->GetSequencedTaskRunnerWithShutdownBehavior( 276 blocking_pool_->GetSequencedTaskRunnerWithShutdownBehavior(
286 blocking_pool_->GetSequenceToken(), 277 blocking_pool_->GetSequenceToken(),
287 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); 278 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN));
288 // TODO(skym): Stop creating leveldb files when signed out. 279 // TODO(skym): Stop creating leveldb files when signed out.
289 // TODO(skym): Verify using AsUTF8Unsafe is okay here. Should work as long 280 // TODO(skym): Verify using AsUTF8Unsafe is okay here. Should work as long
290 // as the Local State file is guaranteed to be UTF-8. 281 // as the Local State file is guaranteed to be UTF-8.
291 device_info_service_ = base::MakeUnique<DeviceInfoSyncBridge>( 282 device_info_sync_bridge_ = base::MakeUnique<DeviceInfoSyncBridge>(
292 local_device_.get(), 283 local_device_.get(),
293 base::Bind(&ModelTypeStore::CreateStore, syncer::DEVICE_INFO, 284 base::Bind(&ModelTypeStore::CreateStore, syncer::DEVICE_INFO,
294 directory_path_.Append(base::FilePath(kLevelDBFolderName)) 285 sync_data_folder_.Append(base::FilePath(kLevelDBFolderName))
295 .AsUTF8Unsafe(), 286 .AsUTF8Unsafe(),
296 blocking_task_runner), 287 blocking_task_runner),
297 base::Bind(&ModelTypeChangeProcessor::Create)); 288 base::Bind(&ModelTypeChangeProcessor::Create));
298 } else { 289 } else {
299 device_info_sync_service_ = 290 device_info_sync_service_ =
300 base::MakeUnique<DeviceInfoSyncService>(local_device_.get()); 291 base::MakeUnique<DeviceInfoSyncService>(local_device_.get());
301 } 292 }
302 293
303 syncer::SyncApiComponentFactory::RegisterDataTypesMethod 294 syncer::SyncApiComponentFactory::RegisterDataTypesMethod
304 register_platform_types_callback = 295 register_platform_types_callback =
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 } 431 }
441 432
442 sync_sessions::FaviconCache* ProfileSyncService::GetFaviconCache() { 433 sync_sessions::FaviconCache* ProfileSyncService::GetFaviconCache() {
443 DCHECK(thread_checker_.CalledOnValidThread()); 434 DCHECK(thread_checker_.CalledOnValidThread());
444 return sessions_sync_manager_->GetFaviconCache(); 435 return sessions_sync_manager_->GetFaviconCache();
445 } 436 }
446 437
447 syncer::DeviceInfoTracker* ProfileSyncService::GetDeviceInfoTracker() const { 438 syncer::DeviceInfoTracker* ProfileSyncService::GetDeviceInfoTracker() const {
448 DCHECK(thread_checker_.CalledOnValidThread()); 439 DCHECK(thread_checker_.CalledOnValidThread());
449 // One of the two should always be non-null after initialization is done. 440 // One of the two should always be non-null after initialization is done.
450 if (device_info_service_) { 441 if (device_info_sync_bridge_) {
451 return device_info_service_.get(); 442 return device_info_sync_bridge_.get();
452 } else { 443 } else {
453 return device_info_sync_service_.get(); 444 return device_info_sync_service_.get();
454 } 445 }
455 } 446 }
456 447
457 syncer::LocalDeviceInfoProvider* 448 syncer::LocalDeviceInfoProvider*
458 ProfileSyncService::GetLocalDeviceInfoProvider() const { 449 ProfileSyncService::GetLocalDeviceInfoProvider() const {
459 DCHECK(thread_checker_.CalledOnValidThread()); 450 DCHECK(thread_checker_.CalledOnValidThread());
460 return local_device_.get(); 451 return local_device_.get();
461 } 452 }
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 579
589 startup_controller_->OnDataTypeRequestsSyncStartup(type); 580 startup_controller_->OnDataTypeRequestsSyncStartup(type);
590 } 581 }
591 582
592 void ProfileSyncService::StartUpSlowEngineComponents() { 583 void ProfileSyncService::StartUpSlowEngineComponents() {
593 invalidation::InvalidationService* invalidator = 584 invalidation::InvalidationService* invalidator =
594 sync_client_->GetInvalidationService(); 585 sync_client_->GetInvalidationService();
595 586
596 engine_.reset(sync_client_->GetSyncApiComponentFactory()->CreateSyncEngine( 587 engine_.reset(sync_client_->GetSyncApiComponentFactory()->CreateSyncEngine(
597 debug_identifier_, invalidator, sync_prefs_.AsWeakPtr(), 588 debug_identifier_, invalidator, sync_prefs_.AsWeakPtr(),
598 directory_path_)); 589 sync_data_folder_));
599 590
600 // Clear any old errors the first time sync starts. 591 // Clear any old errors the first time sync starts.
601 if (!IsFirstSetupComplete()) 592 if (!IsFirstSetupComplete())
602 ClearStaleErrors(); 593 ClearStaleErrors();
603 594
604 InitializeEngine(); 595 InitializeEngine();
605 596
606 UpdateFirstSyncTimePref(); 597 UpdateFirstSyncTimePref();
607 598
608 ReportPreviousSessionMemoryWarningCount(); 599 ReportPreviousSessionMemoryWarningCount();
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 if (sync_thread_) 712 if (sync_thread_)
722 sync_thread_->Stop(); 713 sync_thread_->Stop();
723 } 714 }
724 715
725 void ProfileSyncService::ShutdownImpl(syncer::ShutdownReason reason) { 716 void ProfileSyncService::ShutdownImpl(syncer::ShutdownReason reason) {
726 if (!engine_) { 717 if (!engine_) {
727 if (reason == syncer::ShutdownReason::DISABLE_SYNC && sync_thread_) { 718 if (reason == syncer::ShutdownReason::DISABLE_SYNC && sync_thread_) {
728 // If the engine is already shut down when a DISABLE_SYNC happens, 719 // If the engine is already shut down when a DISABLE_SYNC happens,
729 // the data directory needs to be cleaned up here. 720 // the data directory needs to be cleaned up here.
730 sync_thread_->task_runner()->PostTask( 721 sync_thread_->task_runner()->PostTask(
731 FROM_HERE, base::Bind(&DeleteSyncDataFolder, directory_path_)); 722 FROM_HERE,
723 base::Bind(&syncer::syncable::Directory::DeleteDirectoryFiles,
724 sync_data_folder_));
732 } 725 }
733 return; 726 return;
734 } 727 }
735 728
736 if (reason == syncer::ShutdownReason::STOP_SYNC || 729 if (reason == syncer::ShutdownReason::STOP_SYNC ||
737 reason == syncer::ShutdownReason::DISABLE_SYNC) { 730 reason == syncer::ShutdownReason::DISABLE_SYNC) {
738 RemoveClientFromServer(); 731 RemoveClientFromServer();
739 } 732 }
740 733
741 // First, we spin down the engine to stop change processing as soon as 734 // First, we spin down the engine to stop change processing as soon as
(...skipping 1728 matching lines...) Expand 10 before | Expand all | Expand 10 after
2470 return sessions_sync_manager_.get(); 2463 return sessions_sync_manager_.get();
2471 } 2464 }
2472 2465
2473 syncer::SyncableService* ProfileSyncService::GetDeviceInfoSyncableService() { 2466 syncer::SyncableService* ProfileSyncService::GetDeviceInfoSyncableService() {
2474 DCHECK(thread_checker_.CalledOnValidThread()); 2467 DCHECK(thread_checker_.CalledOnValidThread());
2475 return device_info_sync_service_.get(); 2468 return device_info_sync_service_.get();
2476 } 2469 }
2477 2470
2478 syncer::ModelTypeSyncBridge* ProfileSyncService::GetDeviceInfoSyncBridge() { 2471 syncer::ModelTypeSyncBridge* ProfileSyncService::GetDeviceInfoSyncBridge() {
2479 DCHECK(thread_checker_.CalledOnValidThread()); 2472 DCHECK(thread_checker_.CalledOnValidThread());
2480 return device_info_service_.get(); 2473 return device_info_sync_bridge_.get();
2481 } 2474 }
2482 2475
2483 syncer::SyncService::SyncTokenStatus ProfileSyncService::GetSyncTokenStatus() 2476 syncer::SyncService::SyncTokenStatus ProfileSyncService::GetSyncTokenStatus()
2484 const { 2477 const {
2485 DCHECK(thread_checker_.CalledOnValidThread()); 2478 DCHECK(thread_checker_.CalledOnValidThread());
2486 SyncTokenStatus status; 2479 SyncTokenStatus status;
2487 status.connection_status_update_time = connection_status_update_time_; 2480 status.connection_status_update_time = connection_status_update_time_;
2488 status.connection_status = connection_status_; 2481 status.connection_status = connection_status_;
2489 status.token_request_time = token_request_time_; 2482 status.token_request_time = token_request_time_;
2490 status.token_receive_time = token_receive_time_; 2483 status.token_receive_time = token_receive_time_;
(...skipping 25 matching lines...) Expand all
2516 void ProfileSyncService::FlushDirectory() const { 2509 void ProfileSyncService::FlushDirectory() const {
2517 DCHECK(thread_checker_.CalledOnValidThread()); 2510 DCHECK(thread_checker_.CalledOnValidThread());
2518 // engine_initialized_ implies engine_ isn't null and the manager exists. 2511 // engine_initialized_ implies engine_ isn't null and the manager exists.
2519 // If sync is not initialized yet, we fail silently. 2512 // If sync is not initialized yet, we fail silently.
2520 if (engine_initialized_) 2513 if (engine_initialized_)
2521 engine_->FlushDirectory(); 2514 engine_->FlushDirectory();
2522 } 2515 }
2523 2516
2524 base::FilePath ProfileSyncService::GetDirectoryPathForTest() const { 2517 base::FilePath ProfileSyncService::GetDirectoryPathForTest() const {
2525 DCHECK(thread_checker_.CalledOnValidThread()); 2518 DCHECK(thread_checker_.CalledOnValidThread());
2526 return directory_path_; 2519 return sync_data_folder_;
2527 } 2520 }
2528 2521
2529 base::MessageLoop* ProfileSyncService::GetSyncLoopForTest() const { 2522 base::MessageLoop* ProfileSyncService::GetSyncLoopForTest() const {
2530 DCHECK(thread_checker_.CalledOnValidThread()); 2523 DCHECK(thread_checker_.CalledOnValidThread());
2531 if (sync_thread_) { 2524 if (sync_thread_) {
2532 return sync_thread_->message_loop(); 2525 return sync_thread_->message_loop();
2533 } else { 2526 } else {
2534 return nullptr; 2527 return nullptr;
2535 } 2528 }
2536 } 2529 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
2609 2602
2610 DCHECK(startup_controller_->IsSetupInProgress()); 2603 DCHECK(startup_controller_->IsSetupInProgress());
2611 startup_controller_->SetSetupInProgress(false); 2604 startup_controller_->SetSetupInProgress(false);
2612 2605
2613 if (IsEngineInitialized()) 2606 if (IsEngineInitialized())
2614 ReconfigureDatatypeManager(); 2607 ReconfigureDatatypeManager();
2615 NotifyObservers(); 2608 NotifyObservers();
2616 } 2609 }
2617 2610
2618 } // namespace browser_sync 2611 } // namespace browser_sync
OLDNEW
« no previous file with comments | « components/browser_sync/profile_sync_service.h ('k') | components/sync/driver/glue/sync_backend_host_core.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698