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

Side by Side Diff: chrome/browser/sync/profile_sync_service.cc

Issue 332923002: [sync] Add backup time in synced device info so that server can flag device (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
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 "chrome/browser/sync/profile_sync_service.h" 5 #include "chrome/browser/sync/profile_sync_service.h"
6 6
7 #include <cstddef> 7 #include <cstddef>
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <utility> 10 #include <utility>
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 #include "net/cookies/cookie_monster.h" 80 #include "net/cookies/cookie_monster.h"
81 #include "net/url_request/url_request_context_getter.h" 81 #include "net/url_request/url_request_context_getter.h"
82 #include "sync/api/sync_error.h" 82 #include "sync/api/sync_error.h"
83 #include "sync/internal_api/public/configure_reason.h" 83 #include "sync/internal_api/public/configure_reason.h"
84 #include "sync/internal_api/public/http_bridge_network_resources.h" 84 #include "sync/internal_api/public/http_bridge_network_resources.h"
85 #include "sync/internal_api/public/network_resources.h" 85 #include "sync/internal_api/public/network_resources.h"
86 #include "sync/internal_api/public/sessions/type_debug_info_observer.h" 86 #include "sync/internal_api/public/sessions/type_debug_info_observer.h"
87 #include "sync/internal_api/public/sync_core_proxy.h" 87 #include "sync/internal_api/public/sync_core_proxy.h"
88 #include "sync/internal_api/public/sync_encryption_handler.h" 88 #include "sync/internal_api/public/sync_encryption_handler.h"
89 #include "sync/internal_api/public/util/experiments.h" 89 #include "sync/internal_api/public/util/experiments.h"
90 #include "sync/internal_api/public/util/sync_db_util.h"
90 #include "sync/internal_api/public/util/sync_string_conversions.h" 91 #include "sync/internal_api/public/util/sync_string_conversions.h"
91 #include "sync/js/js_event_details.h" 92 #include "sync/js/js_event_details.h"
92 #include "sync/util/cryptographer.h" 93 #include "sync/util/cryptographer.h"
93 #include "ui/base/l10n/l10n_util.h" 94 #include "ui/base/l10n/l10n_util.h"
94 #include "ui/base/l10n/time_format.h" 95 #include "ui/base/l10n/time_format.h"
95 96
96 #if defined(OS_ANDROID) 97 #if defined(OS_ANDROID)
97 #include "sync/internal_api/public/read_transaction.h" 98 #include "sync/internal_api/public/read_transaction.h"
98 #endif 99 #endif
99 100
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 674
674 DVLOG(1) << "Start backend mode: " << mode; 675 DVLOG(1) << "Start backend mode: " << mode;
675 676
676 if (backend_) 677 if (backend_)
677 ShutdownImpl(browser_sync::SyncBackendHost::STOP_AND_CLAIM_THREAD); 678 ShutdownImpl(browser_sync::SyncBackendHost::STOP_AND_CLAIM_THREAD);
678 679
679 backend_mode_ = mode; 680 backend_mode_ = mode;
680 681
681 if (backend_mode_ == ROLLBACK) 682 if (backend_mode_ == ROLLBACK)
682 ClearBrowsingDataSinceFirstSync(); 683 ClearBrowsingDataSinceFirstSync();
684 else if (backend_mode_ == SYNC)
685 CheckSyncBackupIfNeeded();
683 686
684 base::FilePath sync_folder = backend_mode_ == SYNC ? 687 base::FilePath sync_folder = backend_mode_ == SYNC ?
685 base::FilePath(kSyncDataFolderName) : 688 base::FilePath(kSyncDataFolderName) :
686 base::FilePath(kSyncBackupDataFolderName); 689 base::FilePath(kSyncBackupDataFolderName);
687 690
688 invalidation::InvalidationService* invalidator = backend_mode_ == SYNC ? 691 invalidation::InvalidationService* invalidator = backend_mode_ == SYNC ?
689 invalidation::InvalidationServiceFactory::GetForProfile(profile_) : 692 invalidation::InvalidationServiceFactory::GetForProfile(profile_) :
690 NULL; 693 NULL;
691 694
692 backend_.reset( 695 backend_.reset(
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
1014 UMA_HISTOGRAM_LONG_TIMES("Sync.BackendInitializeFirstTime", delta); 1017 UMA_HISTOGRAM_LONG_TIMES("Sync.BackendInitializeFirstTime", delta);
1015 } else { 1018 } else {
1016 UMA_HISTOGRAM_LONG_TIMES("Sync.BackendInitializeRestoreTime", delta); 1019 UMA_HISTOGRAM_LONG_TIMES("Sync.BackendInitializeRestoreTime", delta);
1017 } 1020 }
1018 } 1021 }
1019 1022
1020 void ProfileSyncService::PostBackendInitialization() { 1023 void ProfileSyncService::PostBackendInitialization() {
1021 // Never get here for backup / restore. 1024 // Never get here for backup / restore.
1022 DCHECK_EQ(backend_mode_, SYNC); 1025 DCHECK_EQ(backend_mode_, SYNC);
1023 1026
1027 if (last_backup_time_) {
1028 browser_sync::SyncedDeviceTracker* device_tracker =
1029 backend_->GetSyncedDeviceTracker();
1030 if (device_tracker)
1031 device_tracker->UpdateLocalDeviceBackupTime(*last_backup_time_);
1032 }
1033
1024 if (protocol_event_observers_.might_have_observers()) { 1034 if (protocol_event_observers_.might_have_observers()) {
1025 backend_->RequestBufferedProtocolEventsAndEnableForwarding(); 1035 backend_->RequestBufferedProtocolEventsAndEnableForwarding();
1026 } 1036 }
1027 1037
1028 non_blocking_data_type_manager_.ConnectSyncBackend( 1038 non_blocking_data_type_manager_.ConnectSyncBackend(
1029 backend_->GetSyncCoreProxy()); 1039 backend_->GetSyncCoreProxy());
1030 1040
1031 if (type_debug_info_observers_.might_have_observers()) { 1041 if (type_debug_info_observers_.might_have_observers()) {
1032 backend_->EnableDirectoryTypeDebugInfoForwarding(); 1042 backend_->EnableDirectoryTypeDebugInfoForwarding();
1033 } 1043 }
(...skipping 1512 matching lines...) Expand 10 before | Expand all | Expand 10 after
2546 if (first_sync_time.is_null()) 2556 if (first_sync_time.is_null())
2547 return; 2557 return;
2548 2558
2549 clear_browsing_data_.Run(profile_, first_sync_time, base::Time::Now()); 2559 clear_browsing_data_.Run(profile_, first_sync_time, base::Time::Now());
2550 } 2560 }
2551 2561
2552 void ProfileSyncService::SetClearingBrowseringDataForTesting( 2562 void ProfileSyncService::SetClearingBrowseringDataForTesting(
2553 base::Callback<void(Profile*, base::Time, base::Time)> c) { 2563 base::Callback<void(Profile*, base::Time, base::Time)> c) {
2554 clear_browsing_data_ = c; 2564 clear_browsing_data_ = c;
2555 } 2565 }
2566
2567 void ProfileSyncService::CheckSyncBackupIfNeeded() {
2568 DCHECK_EQ(backend_mode_, SYNC);
2569
2570 #if defined(OS_WIN) || defined(OS_MACOSX) || (defined(OS_LINUX) && !defined(OS_C HROMEOS))
2571 // Check backup once a day.
2572 if (last_synced_time_.is_null() ||
2573 base::Time::Now() - last_synced_time_ >= base::TimeDelta::FromDays(1)) {
2574 // If sync thread is set, need to serialize check on sync thread after
2575 // closing backup DB.
2576 base::TaskRunner* check_task_runner = sync_thread_ ?
2577 sync_thread_->message_loop_proxy().get() :
2578 profile_->GetIOTaskRunner().get();
2579 check_task_runner->PostTask(
2580 FROM_HERE,
2581 base::Bind(syncer::CheckSyncDbLastModifiedTime,
2582 profile_->GetPath().Append(kSyncBackupDataFolderName),
2583 base::MessageLoopProxy::current(),
2584 base::Bind(&ProfileSyncService::CheckSyncBackupCallback,
2585 weak_factory_.GetWeakPtr())));
2586 }
2587 #endif
2588 }
2589
2590 void ProfileSyncService::CheckSyncBackupCallback(base::Time backup_time) {
2591 last_backup_time_.reset(new base::Time(backup_time));
2592
2593 if (HasSyncingBackend()) {
2594 browser_sync::SyncedDeviceTracker* device_tracker =
2595 backend_->GetSyncedDeviceTracker();
2596 if (device_tracker)
2597 device_tracker->UpdateLocalDeviceBackupTime(*last_backup_time_);
2598 }
2599 }
2600
2601 base::Time ProfileSyncService::GetDeviceBackupTimeForTesting() const {
2602 return backend_->GetSyncedDeviceTracker()->GetLocalDeviceBackupTime();
2603 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698