#include "base/memory/ref_counted.h"
#include "base/message_loop/message_loop.h"
#include "base/metrics/histogram.h"
+#include "base/profiler/scoped_tracker.h"
#include "base/strings/string16.h"
#include "base/strings/stringprintf.h"
#include "base/threading/thread_restrictions.h"
password->RemoveLoginsSyncedBetween(start, end);
}
+// Perform the actual sync data folder deletion.
+// This should only be called on the sync thread.
+void DeleteSyncDataFolder(const base::FilePath& directory_path) {
+ if (base::DirectoryExists(directory_path)) {
+ if (!base::DeleteFile(directory_path, true))
+ LOG(DFATAL) << "Could not delete the Sync Data folder.";
+ }
+}
+
} // anonymous namespace
bool ShouldShowActionOnUI(
}
void ProfileSyncService::TrySyncDatatypePrefRecovery() {
- DCHECK(!sync_initialized());
+ DCHECK(!backend_initialized());
if (!HasSyncSetupCompleted())
return;
return !Intersection(preferred_types, encrypted_types).Empty();
}
-void ProfileSyncService::OnSyncConfigureRetry() {
- // Note: in order to handle auth failures that arise before the backend is
- // initialized (e.g. from invalidation notifier, or downloading new control
- // types), we have to gracefully handle configuration retries at all times.
- // At this point an auth error badge should be shown, which once resolved
- // will trigger a new sync cycle.
- NotifyObservers();
-}
-
void ProfileSyncService::OnProtocolEvent(
const syncer::ProtocolEvent& event) {
FOR_EACH_OBSERVER(browser_sync::ProtocolEventObserver,
invalidator = provider->GetInvalidationService();
}
+ directory_path_ = profile_->GetPath().Append(sync_folder);
+
backend_.reset(
factory_->CreateSyncBackendHost(
profile_->GetDebugName(),
InitializeBackend(ShouldDeleteSyncFolder());
UpdateFirstSyncTimePref();
-
- NotifyObservers();
}
void ProfileSyncService::OnGetTokenSuccess(
void ProfileSyncService::OnRefreshTokenAvailable(
const std::string& account_id) {
+ // TODO(vadimt): Remove ScopedTracker below once crbug.com/422460 is fixed.
+ tracked_objects::ScopedTracker tracking_profile(
+ FROM_HERE_WITH_EXPLICIT_FUNCTION(
+ "422460 ProfileSyncService::OnRefreshTokenAvailable"));
+
if (account_id == signin_->GetAccountIdToUse())
OnRefreshTokensLoaded();
}
}
void ProfileSyncService::ShutdownImpl(syncer::ShutdownReason reason) {
- if (!backend_)
+ if (!backend_) {
+ if (reason == syncer::ShutdownReason::DISABLE_SYNC && sync_thread_) {
+ // If the backend is already shut down when a DISABLE_SYNC happens,
+ // the data directory needs to be cleaned up here.
+ sync_thread_->message_loop()->PostTask(FROM_HERE,
+ base::Bind(&DeleteSyncDataFolder, directory_path_));
+ }
return;
+ }
non_blocking_data_type_manager_.DisconnectSyncBackend();
UMA_HISTOGRAM_ENUMERATION(kSyncUnrecoverableErrorHistogram,
unrecoverable_error_reason_,
ERROR_REASON_LIMIT);
- NotifyObservers();
std::string location;
from_here.Write(true, true, &location);
LOG(ERROR)
}
}
-void ProfileSyncService::OnConfigureRetry() {
- // We should have cleared our cached passphrase before we get here (in
- // OnBackendInitialized()).
- DCHECK(cached_passphrase_.empty());
-
- OnSyncConfigureRetry();
-}
-
void ProfileSyncService::OnConfigureStart() {
sync_configure_start_time_ = base::Time::Now();
NotifyObservers();
} else if (
backend_.get() && HasSyncSetupCompleted() &&
directory_data_type_manager_.get() &&
- directory_data_type_manager_->state() != DataTypeManager::CONFIGURED) {
+ directory_data_type_manager_->state() == DataTypeManager::STOPPED) {
return DATATYPES_NOT_INITIALIZED;
- } else if (ShouldPushChanges()) {
+ } else if (SyncActive()) {
return INITIALIZED;
}
return UNKNOWN_ERROR;
return;
startup_controller_.set_setup_in_progress(setup_in_progress);
- if (!setup_in_progress && sync_initialized())
+ if (!setup_in_progress && backend_initialized())
ReconfigureDatatypeManager();
NotifyObservers();
}
-bool ProfileSyncService::sync_initialized() const {
+bool ProfileSyncService::SyncActive() const {
+ return backend_initialized_ && backend_mode_ == SYNC &&
+ directory_data_type_manager_ &&
+ directory_data_type_manager_->state() != DataTypeManager::STOPPED;
+}
+
+bool ProfileSyncService::backend_initialized() const {
return backend_initialized_;
}
+ProfileSyncService::BackendMode ProfileSyncService::backend_mode() const {
+ return backend_mode_;
+}
+
+bool ProfileSyncService::ConfigurationDone() const {
+ return directory_data_type_manager_ &&
+ directory_data_type_manager_->state() == DataTypeManager::CONFIGURED;
+}
+
bool ProfileSyncService::waiting_for_auth() const {
return is_auth_in_progress_;
}
sync_driver::user_selectable_type::TYPED_URLS,
sync_driver::user_selectable_type::EXTENSIONS,
sync_driver::user_selectable_type::APPS,
- sync_driver::user_selectable_type::PROXY_TABS
+ sync_driver::user_selectable_type::WIFI_CREDENTIAL,
+ sync_driver::user_selectable_type::PROXY_TABS,
};
- COMPILE_ASSERT(32 == syncer::MODEL_TYPE_COUNT, UpdateCustomConfigHistogram);
+ COMPILE_ASSERT(33 == syncer::MODEL_TYPE_COUNT, UpdateCustomConfigHistogram);
if (!sync_everything) {
const syncer::ModelTypeSet current_types = GetPreferredDataTypes();
directory_data_type_manager_->ResetDataTypeErrors();
ChangePreferredDataTypes(chosen_types);
AcknowledgeSyncedTypes();
- NotifyObservers();
}
void ProfileSyncService::ChangePreferredDataTypes(
}
syncer::ModelTypeSet ProfileSyncService::GetActiveDataTypes() const {
+ if (!SyncActive() || !ConfigurationDone())
+ return syncer::ModelTypeSet();
const syncer::ModelTypeSet preferred_types = GetPreferredDataTypes();
const syncer::ModelTypeSet failed_types =
data_type_status_table_.GetFailedTypes();
syncer::sessions::SyncSessionSnapshot
ProfileSyncService::GetLastSessionSnapshot() const {
- if (HasSyncingBackend() && backend_initialized_) {
+ if (backend_)
return backend_->GetLastSessionSnapshot();
- }
return syncer::sessions::SyncSessionSnapshot();
}
// If no cached passphrase, or sync backend hasn't started up yet, just exit.
// If the backend isn't running yet, OnBackendInitialized() will call this
// method again after the backend starts up.
- if (cached_passphrase_.empty() || !sync_initialized())
+ if (cached_passphrase_.empty() || !backend_initialized())
return;
// Backend is up and running, so we can consume the cached passphrase.
void ProfileSyncService::SetEncryptionPassphrase(const std::string& passphrase,
PassphraseType type) {
// This should only be called when the backend has been initialized.
- DCHECK(sync_initialized());
+ DCHECK(backend_initialized());
DCHECK(!(type == IMPLICIT && IsUsingSecondaryPassphrase())) <<
"Data is already encrypted using an explicit passphrase";
DCHECK(!(type == EXPLICIT &&
}
void ProfileSyncService::SetEncryptEverythingAllowed(bool allowed) {
- DCHECK(allowed || !backend_initialized_ || !EncryptEverythingEnabled());
+ DCHECK(allowed || !backend_initialized() || !EncryptEverythingEnabled());
encrypt_everything_allowed_ = allowed;
}
void ProfileSyncService::EnableEncryptEverything() {
DCHECK(EncryptEverythingAllowed());
- // Tests override sync_initialized() to always return true, so we
+ // Tests override backend_initialized() to always return true, so we
// must check that instead of |backend_initialized_|.
// TODO(akalin): Fix the above. :/
- DCHECK(sync_initialized());
+ DCHECK(backend_initialized());
// TODO(atwilson): Persist the encryption_pending_ flag to address the various
// problems around cancelling encryption in the background (crbug.com/119649).
if (!encrypt_everything_)
}
void ProfileSyncService::OnSyncManagedPrefChange(bool is_sync_managed) {
- NotifyObservers();
if (is_sync_managed) {
DisableForUser();
} else {
#if defined(OS_CHROMEOS)
RefreshSpareBootstrapToken(password);
#endif
- if (!sync_initialized() || GetAuthError().state() != AuthError::NONE) {
+ if (!backend_initialized() || GetAuthError().state() != AuthError::NONE) {
// Track the fact that we're still waiting for auth to complete.
is_auth_in_progress_ = true;
}
return sync_prefs_.IsManaged() || sync_disabled_by_admin_;
}
-bool ProfileSyncService::ShouldPushChanges() {
- // True only after all bootstrapping has succeeded: the sync backend
- // is initialized, all enabled data types are consistent with one
- // another, and no unrecoverable error has transpired.
- if (HasUnrecoverableError())
- return false;
-
- if (!directory_data_type_manager_)
- return false;
-
- return directory_data_type_manager_->state() == DataTypeManager::CONFIGURED;
-}
-
void ProfileSyncService::StopAndSuppress() {
sync_prefs_.SetStartSuppressed(true);
if (HasSyncingBackend()) {
base::Time ProfileSyncService::GetDeviceBackupTimeForTesting() const {
return device_info_sync_service_->GetLocalDeviceBackupTime();
}
+
+void ProfileSyncService::FlushDirectory() const {
+ // backend_initialized_ implies backend_ isn't NULL and the manager exists.
+ // If sync is not initialized yet, we fail silently.
+ if (backend_initialized_)
+ backend_->FlushDirectory();
+}
+
+base::FilePath ProfileSyncService::GetDirectoryPathForTest() const {
+ return directory_path_;
+}
+
+base::MessageLoop* ProfileSyncService::GetSyncLoopForTest() const {
+ if (sync_thread_) {
+ return sync_thread_->message_loop();
+ } else if (backend_) {
+ return backend_->GetSyncLoopForTesting();
+ } else {
+ return NULL;
+ }
+}