| OLD | NEW | 
|    1 // Copyright 2013 The Chromium Authors. All rights reserved. |    1 // Copyright 2013 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/glue/sync_backend_host_core.h" |    5 #include "chrome/browser/sync/glue/sync_backend_host_core.h" | 
|    6  |    6  | 
|    7 #include "base/command_line.h" |    7 #include "base/command_line.h" | 
|    8 #include "base/file_util.h" |    8 #include "base/file_util.h" | 
|    9 #include "base/metrics/histogram.h" |    9 #include "base/metrics/histogram.h" | 
|   10 #include "chrome/browser/sync/glue/device_info.h" |   10 #include "chrome/browser/sync/glue/device_info.h" | 
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   97     const std::string& name, |   97     const std::string& name, | 
|   98     const base::FilePath& sync_data_folder_path, |   98     const base::FilePath& sync_data_folder_path, | 
|   99     bool has_sync_setup_completed, |   99     bool has_sync_setup_completed, | 
|  100     const base::WeakPtr<SyncBackendHostImpl>& backend) |  100     const base::WeakPtr<SyncBackendHostImpl>& backend) | 
|  101     : name_(name), |  101     : name_(name), | 
|  102       sync_data_folder_path_(sync_data_folder_path), |  102       sync_data_folder_path_(sync_data_folder_path), | 
|  103       host_(backend), |  103       host_(backend), | 
|  104       sync_loop_(NULL), |  104       sync_loop_(NULL), | 
|  105       registrar_(NULL), |  105       registrar_(NULL), | 
|  106       has_sync_setup_completed_(has_sync_setup_completed), |  106       has_sync_setup_completed_(has_sync_setup_completed), | 
 |  107       forward_protocol_events_(false), | 
|  107       weak_ptr_factory_(this) { |  108       weak_ptr_factory_(this) { | 
|  108   DCHECK(backend.get()); |  109   DCHECK(backend.get()); | 
|  109 } |  110 } | 
|  110  |  111  | 
|  111 SyncBackendHostCore::~SyncBackendHostCore() { |  112 SyncBackendHostCore::~SyncBackendHostCore() { | 
|  112   DCHECK(!sync_manager_.get()); |  113   DCHECK(!sync_manager_.get()); | 
|  113 } |  114 } | 
|  114  |  115  | 
|  115 void SyncBackendHostCore::OnSyncCycleCompleted( |  116 void SyncBackendHostCore::OnSyncCycleCompleted( | 
|  116     const syncer::sessions::SyncSessionSnapshot& snapshot) { |  117     const syncer::sessions::SyncSessionSnapshot& snapshot) { | 
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  598 } |  599 } | 
|  599  |  600  | 
|  600 void SyncBackendHostCore::DoRetryConfiguration( |  601 void SyncBackendHostCore::DoRetryConfiguration( | 
|  601     const base::Closure& retry_callback) { |  602     const base::Closure& retry_callback) { | 
|  602   DCHECK_EQ(base::MessageLoop::current(), sync_loop_); |  603   DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 
|  603   host_.Call(FROM_HERE, |  604   host_.Call(FROM_HERE, | 
|  604              &SyncBackendHostImpl::RetryConfigurationOnFrontendLoop, |  605              &SyncBackendHostImpl::RetryConfigurationOnFrontendLoop, | 
|  605              retry_callback); |  606              retry_callback); | 
|  606 } |  607 } | 
|  607  |  608  | 
|  608 void SyncBackendHostCore::SetForwardProtocolEvents(bool enabled) { |  609 void SyncBackendHostCore::SendBufferedProtocolEventsAndEnableForwarding() { | 
|  609   DCHECK_EQ(base::MessageLoop::current(), sync_loop_); |  610   DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 
|  610   forward_protocol_events_ = enabled; |  611   forward_protocol_events_ = true; | 
 |  612  | 
 |  613   if (sync_manager_) { | 
 |  614     // Grab our own copy of the buffered events. | 
 |  615     // The buffer is not modified by this operation. | 
 |  616     std::vector<syncer::ProtocolEvent*> buffered_events; | 
 |  617     sync_manager_->GetBufferedProtocolEvents().release(&buffered_events); | 
 |  618  | 
 |  619     // Send them all over the fence to the host. | 
 |  620     for (std::vector<syncer::ProtocolEvent*>::iterator it = | 
 |  621          buffered_events.begin(); it != buffered_events.end(); ++it) { | 
 |  622       // TODO(rlarocque): Make it explicit that host_ takes ownership. | 
 |  623       host_.Call( | 
 |  624           FROM_HERE, | 
 |  625           &SyncBackendHostImpl::HandleProtocolEventOnFrontendLoop, | 
 |  626           *it); | 
 |  627     } | 
 |  628   } | 
 |  629 } | 
 |  630  | 
 |  631 void SyncBackendHostCore::DisableProtocolEventForwarding() { | 
 |  632   forward_protocol_events_ = false; | 
|  611 } |  633 } | 
|  612  |  634  | 
|  613 void SyncBackendHostCore::DeleteSyncDataFolder() { |  635 void SyncBackendHostCore::DeleteSyncDataFolder() { | 
|  614   DCHECK_EQ(base::MessageLoop::current(), sync_loop_); |  636   DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 
|  615   if (base::DirectoryExists(sync_data_folder_path_)) { |  637   if (base::DirectoryExists(sync_data_folder_path_)) { | 
|  616     if (!base::DeleteFile(sync_data_folder_path_, true)) |  638     if (!base::DeleteFile(sync_data_folder_path_, true)) | 
|  617       SLOG(DFATAL) << "Could not delete the Sync Data folder."; |  639       SLOG(DFATAL) << "Could not delete the Sync Data folder."; | 
|  618   } |  640   } | 
|  619 } |  641 } | 
|  620  |  642  | 
|  621 void SyncBackendHostCore::StartSavingChanges() { |  643 void SyncBackendHostCore::StartSavingChanges() { | 
|  622   // We may already be shut down. |  644   // We may already be shut down. | 
|  623   if (!sync_loop_) |  645   if (!sync_loop_) | 
|  624     return; |  646     return; | 
|  625   DCHECK_EQ(base::MessageLoop::current(), sync_loop_); |  647   DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 
|  626   DCHECK(!save_changes_timer_.get()); |  648   DCHECK(!save_changes_timer_.get()); | 
|  627   save_changes_timer_.reset(new base::RepeatingTimer<SyncBackendHostCore>()); |  649   save_changes_timer_.reset(new base::RepeatingTimer<SyncBackendHostCore>()); | 
|  628   save_changes_timer_->Start(FROM_HERE, |  650   save_changes_timer_->Start(FROM_HERE, | 
|  629       base::TimeDelta::FromSeconds(kSaveChangesIntervalSeconds), |  651       base::TimeDelta::FromSeconds(kSaveChangesIntervalSeconds), | 
|  630       this, &SyncBackendHostCore::SaveChanges); |  652       this, &SyncBackendHostCore::SaveChanges); | 
|  631 } |  653 } | 
|  632  |  654  | 
|  633 void SyncBackendHostCore::SaveChanges() { |  655 void SyncBackendHostCore::SaveChanges() { | 
|  634   DCHECK_EQ(base::MessageLoop::current(), sync_loop_); |  656   DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 
|  635   sync_manager_->SaveChanges(); |  657   sync_manager_->SaveChanges(); | 
|  636 } |  658 } | 
|  637  |  659  | 
|  638 }  // namespace browser_sync |  660 }  // namespace browser_sync | 
|  639  |  661  | 
| OLD | NEW |