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

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

Issue 2568743004: [Sync] Stop deleting LevelDB files when deleting Directory (Closed)
Patch Set: Only delete top level files in sync data folder. Created 4 years 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 1733 matching lines...) Expand 10 before | Expand all | Expand 10 after
2475 return sessions_sync_manager_.get(); 2468 return sessions_sync_manager_.get();
2476 } 2469 }
2477 2470
2478 syncer::SyncableService* ProfileSyncService::GetDeviceInfoSyncableService() { 2471 syncer::SyncableService* ProfileSyncService::GetDeviceInfoSyncableService() {
2479 DCHECK(thread_checker_.CalledOnValidThread()); 2472 DCHECK(thread_checker_.CalledOnValidThread());
2480 return device_info_sync_service_.get(); 2473 return device_info_sync_service_.get();
2481 } 2474 }
2482 2475
2483 syncer::ModelTypeSyncBridge* ProfileSyncService::GetDeviceInfoSyncBridge() { 2476 syncer::ModelTypeSyncBridge* ProfileSyncService::GetDeviceInfoSyncBridge() {
2484 DCHECK(thread_checker_.CalledOnValidThread()); 2477 DCHECK(thread_checker_.CalledOnValidThread());
2485 return device_info_service_.get(); 2478 return device_info_sync_bridge_.get();
2486 } 2479 }
2487 2480
2488 syncer::SyncService::SyncTokenStatus ProfileSyncService::GetSyncTokenStatus() 2481 syncer::SyncService::SyncTokenStatus ProfileSyncService::GetSyncTokenStatus()
2489 const { 2482 const {
2490 DCHECK(thread_checker_.CalledOnValidThread()); 2483 DCHECK(thread_checker_.CalledOnValidThread());
2491 SyncTokenStatus status; 2484 SyncTokenStatus status;
2492 status.connection_status_update_time = connection_status_update_time_; 2485 status.connection_status_update_time = connection_status_update_time_;
2493 status.connection_status = connection_status_; 2486 status.connection_status = connection_status_;
2494 status.token_request_time = token_request_time_; 2487 status.token_request_time = token_request_time_;
2495 status.token_receive_time = token_receive_time_; 2488 status.token_receive_time = token_receive_time_;
(...skipping 25 matching lines...) Expand all
2521 void ProfileSyncService::FlushDirectory() const { 2514 void ProfileSyncService::FlushDirectory() const {
2522 DCHECK(thread_checker_.CalledOnValidThread()); 2515 DCHECK(thread_checker_.CalledOnValidThread());
2523 // engine_initialized_ implies engine_ isn't null and the manager exists. 2516 // engine_initialized_ implies engine_ isn't null and the manager exists.
2524 // If sync is not initialized yet, we fail silently. 2517 // If sync is not initialized yet, we fail silently.
2525 if (engine_initialized_) 2518 if (engine_initialized_)
2526 engine_->FlushDirectory(); 2519 engine_->FlushDirectory();
2527 } 2520 }
2528 2521
2529 base::FilePath ProfileSyncService::GetDirectoryPathForTest() const { 2522 base::FilePath ProfileSyncService::GetDirectoryPathForTest() const {
2530 DCHECK(thread_checker_.CalledOnValidThread()); 2523 DCHECK(thread_checker_.CalledOnValidThread());
2531 return directory_path_; 2524 return sync_data_folder_;
2532 } 2525 }
2533 2526
2534 base::MessageLoop* ProfileSyncService::GetSyncLoopForTest() const { 2527 base::MessageLoop* ProfileSyncService::GetSyncLoopForTest() const {
2535 DCHECK(thread_checker_.CalledOnValidThread()); 2528 DCHECK(thread_checker_.CalledOnValidThread());
2536 if (sync_thread_) { 2529 if (sync_thread_) {
2537 return sync_thread_->message_loop(); 2530 return sync_thread_->message_loop();
2538 } else { 2531 } else {
2539 return nullptr; 2532 return nullptr;
2540 } 2533 }
2541 } 2534 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
2614 2607
2615 DCHECK(startup_controller_->IsSetupInProgress()); 2608 DCHECK(startup_controller_->IsSetupInProgress());
2616 startup_controller_->SetSetupInProgress(false); 2609 startup_controller_->SetSetupInProgress(false);
2617 2610
2618 if (IsEngineInitialized()) 2611 if (IsEngineInitialized())
2619 ReconfigureDatatypeManager(); 2612 ReconfigureDatatypeManager();
2620 NotifyObservers(); 2613 NotifyObservers();
2621 } 2614 }
2622 2615
2623 } // namespace browser_sync 2616 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698