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

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: check db on DB thread Created 6 years, 5 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 #include "components/pref_registry/pref_registry_syncable.h" 69 #include "components/pref_registry/pref_registry_syncable.h"
70 #include "components/signin/core/browser/about_signin_internals.h" 70 #include "components/signin/core/browser/about_signin_internals.h"
71 #include "components/signin/core/browser/profile_oauth2_token_service.h" 71 #include "components/signin/core/browser/profile_oauth2_token_service.h"
72 #include "components/signin/core/browser/signin_manager.h" 72 #include "components/signin/core/browser/signin_manager.h"
73 #include "components/signin/core/browser/signin_metrics.h" 73 #include "components/signin/core/browser/signin_metrics.h"
74 #include "components/sync_driver/change_processor.h" 74 #include "components/sync_driver/change_processor.h"
75 #include "components/sync_driver/data_type_controller.h" 75 #include "components/sync_driver/data_type_controller.h"
76 #include "components/sync_driver/pref_names.h" 76 #include "components/sync_driver/pref_names.h"
77 #include "components/sync_driver/system_encryptor.h" 77 #include "components/sync_driver/system_encryptor.h"
78 #include "components/sync_driver/user_selectable_sync_type.h" 78 #include "components/sync_driver/user_selectable_sync_type.h"
79 #include "content/public/browser/browser_thread.h"
79 #include "content/public/browser/notification_details.h" 80 #include "content/public/browser/notification_details.h"
80 #include "content/public/browser/notification_service.h" 81 #include "content/public/browser/notification_service.h"
81 #include "content/public/browser/notification_source.h" 82 #include "content/public/browser/notification_source.h"
82 #include "grit/generated_resources.h" 83 #include "grit/generated_resources.h"
83 #include "net/cookies/cookie_monster.h" 84 #include "net/cookies/cookie_monster.h"
84 #include "net/url_request/url_request_context_getter.h" 85 #include "net/url_request/url_request_context_getter.h"
85 #include "sync/api/sync_error.h" 86 #include "sync/api/sync_error.h"
86 #include "sync/internal_api/public/configure_reason.h" 87 #include "sync/internal_api/public/configure_reason.h"
87 #include "sync/internal_api/public/http_bridge_network_resources.h" 88 #include "sync/internal_api/public/http_bridge_network_resources.h"
88 #include "sync/internal_api/public/network_resources.h" 89 #include "sync/internal_api/public/network_resources.h"
89 #include "sync/internal_api/public/sessions/type_debug_info_observer.h" 90 #include "sync/internal_api/public/sessions/type_debug_info_observer.h"
90 #include "sync/internal_api/public/sync_context_proxy.h" 91 #include "sync/internal_api/public/sync_context_proxy.h"
91 #include "sync/internal_api/public/sync_encryption_handler.h" 92 #include "sync/internal_api/public/sync_encryption_handler.h"
92 #include "sync/internal_api/public/util/experiments.h" 93 #include "sync/internal_api/public/util/experiments.h"
94 #include "sync/internal_api/public/util/sync_db_util.h"
93 #include "sync/internal_api/public/util/sync_string_conversions.h" 95 #include "sync/internal_api/public/util/sync_string_conversions.h"
94 #include "sync/js/js_event_details.h" 96 #include "sync/js/js_event_details.h"
95 #include "sync/util/cryptographer.h" 97 #include "sync/util/cryptographer.h"
96 #include "ui/base/l10n/l10n_util.h" 98 #include "ui/base/l10n/l10n_util.h"
97 #include "ui/base/l10n/time_format.h" 99 #include "ui/base/l10n/time_format.h"
98 100
99 #if defined(OS_ANDROID) 101 #if defined(OS_ANDROID)
100 #include "sync/internal_api/public/read_transaction.h" 102 #include "sync/internal_api/public/read_transaction.h"
101 #endif 103 #endif
102 104
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 653
652 DVLOG(1) << "Start backend mode: " << mode; 654 DVLOG(1) << "Start backend mode: " << mode;
653 655
654 if (backend_) 656 if (backend_)
655 ShutdownImpl(browser_sync::SyncBackendHost::STOP_AND_CLAIM_THREAD); 657 ShutdownImpl(browser_sync::SyncBackendHost::STOP_AND_CLAIM_THREAD);
656 658
657 backend_mode_ = mode; 659 backend_mode_ = mode;
658 660
659 if (backend_mode_ == ROLLBACK) 661 if (backend_mode_ == ROLLBACK)
660 ClearBrowsingDataSinceFirstSync(); 662 ClearBrowsingDataSinceFirstSync();
663 else if (backend_mode_ == SYNC)
664 CheckSyncBackupIfNeeded();
661 665
662 base::FilePath sync_folder = backend_mode_ == SYNC ? 666 base::FilePath sync_folder = backend_mode_ == SYNC ?
663 base::FilePath(kSyncDataFolderName) : 667 base::FilePath(kSyncDataFolderName) :
664 base::FilePath(kSyncBackupDataFolderName); 668 base::FilePath(kSyncBackupDataFolderName);
665 669
666 invalidation::InvalidationService* invalidator = NULL; 670 invalidation::InvalidationService* invalidator = NULL;
667 if (backend_mode_ == SYNC) { 671 if (backend_mode_ == SYNC) {
668 invalidation::ProfileInvalidationProvider* provider = 672 invalidation::ProfileInvalidationProvider* provider =
669 invalidation::ProfileInvalidationProviderFactory::GetForProfile( 673 invalidation::ProfileInvalidationProviderFactory::GetForProfile(
670 profile_); 674 profile_);
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
1015 UMA_HISTOGRAM_LONG_TIMES("Sync.BackendInitializeFirstTime", delta); 1019 UMA_HISTOGRAM_LONG_TIMES("Sync.BackendInitializeFirstTime", delta);
1016 } else { 1020 } else {
1017 UMA_HISTOGRAM_LONG_TIMES("Sync.BackendInitializeRestoreTime", delta); 1021 UMA_HISTOGRAM_LONG_TIMES("Sync.BackendInitializeRestoreTime", delta);
1018 } 1022 }
1019 } 1023 }
1020 1024
1021 void ProfileSyncService::PostBackendInitialization() { 1025 void ProfileSyncService::PostBackendInitialization() {
1022 // Never get here for backup / restore. 1026 // Never get here for backup / restore.
1023 DCHECK_EQ(backend_mode_, SYNC); 1027 DCHECK_EQ(backend_mode_, SYNC);
1024 1028
1029 if (last_backup_time_) {
1030 browser_sync::SyncedDeviceTracker* device_tracker =
1031 backend_->GetSyncedDeviceTracker();
1032 if (device_tracker)
1033 device_tracker->UpdateLocalDeviceBackupTime(*last_backup_time_);
1034 }
1035
1025 if (protocol_event_observers_.might_have_observers()) { 1036 if (protocol_event_observers_.might_have_observers()) {
1026 backend_->RequestBufferedProtocolEventsAndEnableForwarding(); 1037 backend_->RequestBufferedProtocolEventsAndEnableForwarding();
1027 } 1038 }
1028 1039
1029 non_blocking_data_type_manager_.ConnectSyncBackend( 1040 non_blocking_data_type_manager_.ConnectSyncBackend(
1030 backend_->GetSyncContextProxy()); 1041 backend_->GetSyncContextProxy());
1031 1042
1032 if (type_debug_info_observers_.might_have_observers()) { 1043 if (type_debug_info_observers_.might_have_observers()) {
1033 backend_->EnableDirectoryTypeDebugInfoForwarding(); 1044 backend_->EnableDirectoryTypeDebugInfoForwarding();
1034 } 1045 }
(...skipping 1555 matching lines...) Expand 10 before | Expand all | Expand 10 after
2590 } 2601 }
2591 return result; 2602 return result;
2592 } 2603 }
2593 2604
2594 void ProfileSyncService::StartStopBackupForTesting() { 2605 void ProfileSyncService::StartStopBackupForTesting() {
2595 if (backend_mode_ == BACKUP) 2606 if (backend_mode_ == BACKUP)
2596 ShutdownImpl(browser_sync::SyncBackendHost::STOP_AND_CLAIM_THREAD); 2607 ShutdownImpl(browser_sync::SyncBackendHost::STOP_AND_CLAIM_THREAD);
2597 else 2608 else
2598 backup_rollback_controller_.Start(base::TimeDelta()); 2609 backup_rollback_controller_.Start(base::TimeDelta());
2599 } 2610 }
2611
2612 void ProfileSyncService::CheckSyncBackupIfNeeded() {
2613 DCHECK_EQ(backend_mode_, SYNC);
2614
2615 #if defined(ENABLE_PRE_SYNC_BACKUP)
2616 // Check backup once a day.
2617 if (!last_backup_time_ &&
2618 (last_synced_time_.is_null() ||
2619 base::Time::Now() - last_synced_time_ >=
2620 base::TimeDelta::FromDays(1))) {
2621 // If sync thread is set, need to serialize check on sync thread after
2622 // closing backup DB.
2623 if (sync_thread_) {
2624 sync_thread_->message_loop_proxy()->PostTask(
2625 FROM_HERE,
2626 base::Bind(syncer::CheckSyncDbLastModifiedTime,
2627 profile_->GetPath().Append(kSyncBackupDataFolderName),
2628 base::MessageLoopProxy::current(),
2629 base::Bind(&ProfileSyncService::CheckSyncBackupCallback,
2630 weak_factory_.GetWeakPtr())));
2631 } else {
2632 content::BrowserThread::PostTask(
2633 content::BrowserThread::FILE, FROM_HERE,
2634 base::Bind(syncer::CheckSyncDbLastModifiedTime,
2635 profile_->GetPath().Append(kSyncBackupDataFolderName),
2636 base::MessageLoopProxy::current(),
2637 base::Bind(&ProfileSyncService::CheckSyncBackupCallback,
2638 weak_factory_.GetWeakPtr())));
2639 }
2640 }
2641 #endif
2642 }
2643
2644 void ProfileSyncService::CheckSyncBackupCallback(base::Time backup_time) {
2645 last_backup_time_.reset(new base::Time(backup_time));
2646
2647 if (HasSyncingBackend() && backend_initialized_) {
2648 browser_sync::SyncedDeviceTracker* device_tracker =
2649 backend_->GetSyncedDeviceTracker();
2650 if (device_tracker)
2651 device_tracker->UpdateLocalDeviceBackupTime(*last_backup_time_);
2652 }
2653 }
2654
2655 base::Time ProfileSyncService::GetDeviceBackupTimeForTesting() const {
2656 return backend_->GetSyncedDeviceTracker()->GetLocalDeviceBackupTime();
2657 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/profile_sync_service.h ('k') | chrome/browser/sync/test/integration/single_client_backup_rollback_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698