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

Side by Side Diff: chrome/browser/sync/glue/sync_backend_host_core.cc

Issue 551843003: Persist Directory to disk when the app is backgrounded. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add a thread check and fix a comment. Created 6 years, 3 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
OLDNEW
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/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "chrome/browser/sync/glue/device_info.h" 9 #include "chrome/browser/sync/glue/device_info.h"
10 #include "chrome/browser/sync/glue/invalidation_adapter.h" 10 #include "chrome/browser/sync/glue/invalidation_adapter.h"
11 #include "chrome/browser/sync/glue/sync_backend_registrar.h" 11 #include "chrome/browser/sync/glue/sync_backend_registrar.h"
12 #include "chrome/browser/sync/glue/synced_device_tracker.h" 12 #include "chrome/browser/sync/glue/synced_device_tracker.h"
13 #include "chrome/common/chrome_version_info.h" 13 #include "chrome/common/chrome_version_info.h"
14 #include "components/invalidation/invalidation_util.h" 14 #include "components/invalidation/invalidation_util.h"
15 #include "components/invalidation/object_id_invalidation_map.h" 15 #include "components/invalidation/object_id_invalidation_map.h"
16 #include "sync/internal_api/public/events/protocol_event.h" 16 #include "sync/internal_api/public/events/protocol_event.h"
17 #include "sync/internal_api/public/http_post_provider_factory.h" 17 #include "sync/internal_api/public/http_post_provider_factory.h"
18 #include "sync/internal_api/public/internal_components_factory.h" 18 #include "sync/internal_api/public/internal_components_factory.h"
19 #include "sync/internal_api/public/sessions/commit_counters.h" 19 #include "sync/internal_api/public/sessions/commit_counters.h"
20 #include "sync/internal_api/public/sessions/status_counters.h" 20 #include "sync/internal_api/public/sessions/status_counters.h"
21 #include "sync/internal_api/public/sessions/sync_session_snapshot.h" 21 #include "sync/internal_api/public/sessions/sync_session_snapshot.h"
22 #include "sync/internal_api/public/sessions/update_counters.h" 22 #include "sync/internal_api/public/sessions/update_counters.h"
23 #include "sync/internal_api/public/sync_context_proxy.h" 23 #include "sync/internal_api/public/sync_context_proxy.h"
24 #include "sync/internal_api/public/sync_manager.h" 24 #include "sync/internal_api/public/sync_manager.h"
25 #include "sync/internal_api/public/sync_manager_factory.h" 25 #include "sync/internal_api/public/sync_manager_factory.h"
26 #include "sync/syncable/directory.h"
26 #include "url/gurl.h" 27 #include "url/gurl.h"
27 28
28 // Helper macros to log with the syncer thread name; useful when there 29 // Helper macros to log with the syncer thread name; useful when there
29 // are multiple syncers involved. 30 // are multiple syncers involved.
30 31
31 #define SLOG(severity) LOG(severity) << name_ << ": " 32 #define SLOG(severity) LOG(severity) << name_ << ": "
32 33
33 #define SDVLOG(verbose_level) DVLOG(verbose_level) << name_ << ": " 34 #define SDVLOG(verbose_level) DVLOG(verbose_level) << name_ << ": "
34 35
35 static const int kSaveChangesIntervalSeconds = 10; 36 static const int kSaveChangesIntervalSeconds = 10;
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 } 656 }
656 657
657 void SyncBackendHostCore::DoRetryConfiguration( 658 void SyncBackendHostCore::DoRetryConfiguration(
658 const base::Closure& retry_callback) { 659 const base::Closure& retry_callback) {
659 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); 660 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
660 host_.Call(FROM_HERE, 661 host_.Call(FROM_HERE,
661 &SyncBackendHostImpl::RetryConfigurationOnFrontendLoop, 662 &SyncBackendHostImpl::RetryConfigurationOnFrontendLoop,
662 retry_callback); 663 retry_callback);
663 } 664 }
664 665
666 void SyncBackendHostCore::DoFlushDirectory() {
667 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
668 syncer::syncable::Directory* directory =
Nicolas Zea 2014/09/15 22:38:59 What will this do if the SBH isn't initialized yet
maxbogue 2014/09/16 15:34:31 Which part will currently crash? How would the cal
Nicolas Zea 2014/09/18 16:52:17 The SyncManager is only created when DoInitialize
maxbogue 2014/09/22 17:23:25 Fixed this in PSS.
669 sync_manager()->GetUserShare()->directory.get();
670 if (directory != NULL) {
671 directory->SaveChanges();
672 }
673 }
674
665 void SyncBackendHostCore::SendBufferedProtocolEventsAndEnableForwarding() { 675 void SyncBackendHostCore::SendBufferedProtocolEventsAndEnableForwarding() {
666 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); 676 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
667 forward_protocol_events_ = true; 677 forward_protocol_events_ = true;
668 678
669 if (sync_manager_) { 679 if (sync_manager_) {
670 // Grab our own copy of the buffered events. 680 // Grab our own copy of the buffered events.
671 // The buffer is not modified by this operation. 681 // The buffer is not modified by this operation.
672 std::vector<syncer::ProtocolEvent*> buffered_events; 682 std::vector<syncer::ProtocolEvent*> buffered_events;
673 sync_manager_->GetBufferedProtocolEvents().release(&buffered_events); 683 sync_manager_->GetBufferedProtocolEvents().release(&buffered_events);
674 684
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 base::TimeDelta::FromSeconds(kSaveChangesIntervalSeconds), 766 base::TimeDelta::FromSeconds(kSaveChangesIntervalSeconds),
757 this, &SyncBackendHostCore::SaveChanges); 767 this, &SyncBackendHostCore::SaveChanges);
758 } 768 }
759 769
760 void SyncBackendHostCore::SaveChanges() { 770 void SyncBackendHostCore::SaveChanges() {
761 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); 771 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
762 sync_manager_->SaveChanges(); 772 sync_manager_->SaveChanges();
763 } 773 }
764 774
765 } // namespace browser_sync 775 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698