summaryrefslogtreecommitdiffstats
path: root/chrome/browser/sync/sessions/sessions_sync_manager.cc
diff options
context:
space:
mode:
authorstanisc@chromium.org <stanisc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-22 00:36:20 +0000
committerstanisc@chromium.org <stanisc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-22 00:36:20 +0000
commitd85f0ac40f155b13ff9f67f85937112f6a2074de (patch)
tree8784996593344007e3337720e7d31f8cb93b253d /chrome/browser/sync/sessions/sessions_sync_manager.cc
parent8b7e37e4ddf9c62eb5e3f01e5d68ab2a77abe091 (diff)
downloadchromium_src-d85f0ac40f155b13ff9f67f85937112f6a2074de.zip
chromium_src-d85f0ac40f155b13ff9f67f85937112f6a2074de.tar.gz
chromium_src-d85f0ac40f155b13ff9f67f85937112f6a2074de.tar.bz2
Sync: Refactoring of DEVICE_INFO syncable type - Part 1
This reintroduces change 283461 (issue 367153005) that has been reverted due to memory leaks in some unit tests. The memory leak was in a mock implementation of ProfileSyncComponentsFactory. The factory is responsible for creating an instance of LocalDeviceInfoProvider, which it does on demand and immediately transfer ownership of LocalDeviceInfoProvider to the caller. But due to the way mocking was implemented in ProfileSyncComponentsFactoryMock a mock instance of LocalDeviceInfoProvider was created in the constructor and if a test never called CreateLocalDeviceInfoProvider(), it would be leaked. In this change I moved away from using ON_CALL mocking mechanism that resulted in the leak to a custom implementation that avoids that problem. See original changes in the patch #1 and the fix in the patch #2. The original description copied from issue 367153005: This change introduces a new class LocalDeviceInfoProvider that is responsible for providing the local device specific DeviceInfo/cache_guid. It initializes the data asynchronously and allows consumers to get notified when the data becomes available. LocalDeviceInfoProvider will allow to remove these responsibilities from SyncedDeviceTracker / ProfileSyncService and loose coupling between ProfileSyncService and a number of SyncableService and DataTypeController derived classes. LocalDeviceInfoProvider is hosted on the frontend thread. Since it needs cache_guid to initialize DeviceInfo, which is currently available only on the backend, I updated SyncBackendHostCore and SyncBackendHostImpl to pass cache_guid to the frontend via OnBackendInitialized. For the time being SyncedDeviceTracker remains unchanged and continues to initialize the local device info too. The entire class will be removed in the Part 2 of the change which will move SyncedDeviceTracker functionality to a new SyncableService. LocalDeviceInfoProvider also replaces SessionsSyncManager::SyncInternalApiDelegate which was previously used to decouple SessionsSyncManager from the specifics of of the local device info implementation. SessionsSyncManager is changed to consume LocalDeviceInfoProvider instead of SessionsSyncManager::SyncInternalApiDelegate. SessionDataTypeController now also consumes LocalDeviceInfoProvider to make sure that SESSIONS type model doesn't start before local device info becomes available. A very similar approach will be used in the upcoming second part of the change for DEVICE_INFO DataTypeController and SyncableType. The change includes new unit tests for LocalDeviceInfoProvider and SessionDataTypeController. TBR=maniscalco@chromium.org,sky@chromium.org,zea@chromium.org BUG=395349 Review URL: https://codereview.chromium.org/398423002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284561 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/sync/sessions/sessions_sync_manager.cc')
-rw-r--r--chrome/browser/sync/sessions/sessions_sync_manager.cc34
1 files changed, 26 insertions, 8 deletions
diff --git a/chrome/browser/sync/sessions/sessions_sync_manager.cc b/chrome/browser/sync/sessions/sessions_sync_manager.cc
index 72a01d2..069f1f2 100644
--- a/chrome/browser/sync/sessions/sessions_sync_manager.cc
+++ b/chrome/browser/sync/sessions/sessions_sync_manager.cc
@@ -6,6 +6,7 @@
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/sync/glue/local_device_info_provider.h"
#include "chrome/browser/sync/glue/synced_tab_delegate.h"
#include "chrome/browser/sync/glue/synced_window_delegate.h"
#include "chrome/browser/sync/sessions/sessions_util.h"
@@ -44,15 +45,17 @@ static const char kNTPOpenTabSyncURL[] = "chrome://newtab/#open_tabs";
// stale and becomes a candidate for garbage collection.
static const size_t kDefaultStaleSessionThresholdDays = 14; // 2 weeks.
+// |local_device| is owned by ProfileSyncService, its lifetime exceeds
+// lifetime of SessionSyncManager.
SessionsSyncManager::SessionsSyncManager(
Profile* profile,
- SyncInternalApiDelegate* delegate,
+ LocalDeviceInfoProvider* local_device,
scoped_ptr<LocalSessionEventRouter> router)
: favicon_cache_(profile, kMaxSyncFavicons),
local_tab_pool_out_of_sync_(true),
sync_prefs_(profile->GetPrefs()),
profile_(profile),
- delegate_(delegate),
+ local_device_(local_device),
local_session_header_node_id_(TabNodePool::kInvalidTabNodeID),
stale_session_threshold_days_(kDefaultStaleSessionThresholdDays),
local_event_router_(router.Pass()),
@@ -85,24 +88,31 @@ syncer::SyncMergeResult SessionsSyncManager::MergeDataAndStartSyncing(
sync_processor_ = sync_processor.Pass();
local_session_header_node_id_ = TabNodePool::kInvalidTabNodeID;
- scoped_ptr<DeviceInfo> local_device_info(delegate_->GetLocalDeviceInfo());
- syncer::SyncChangeList new_changes;
// Make sure we have a machine tag. We do this now (versus earlier) as it's
// a conveniently safe time to assert sync is ready and the cache_guid is
// initialized.
- if (current_machine_tag_.empty())
+ if (current_machine_tag_.empty()) {
InitializeCurrentMachineTag();
+ }
+
+ // SessionDataTypeController ensures that the local device info
+ // is available before activating this datatype.
+ DCHECK(local_device_);
+ const DeviceInfo* local_device_info = local_device_->GetLocalDeviceInfo();
if (local_device_info) {
current_session_name_ = local_device_info->client_name();
} else {
merge_result.set_error(error_handler_->CreateAndUploadError(
FROM_HERE,
- "Failed to get device info for machine tag."));
+ "Failed to get local device info."));
return merge_result;
}
+
session_tracker_.SetLocalSessionTag(current_machine_tag_);
+ syncer::SyncChangeList new_changes;
+
// First, we iterate over sync data to update our session_tracker_.
syncer::SyncDataList restored_tabs;
if (!InitFromSyncModel(initial_sync_data, &restored_tabs, &new_changes)) {
@@ -121,7 +131,7 @@ syncer::SyncMergeResult SessionsSyncManager::MergeDataAndStartSyncing(
#if defined(OS_ANDROID)
std::string sync_machine_tag(BuildMachineTag(
- delegate_->GetLocalSyncCacheGUID()));
+ local_device_->GetLocalSyncCacheGUID()));
if (current_machine_tag_.compare(sync_machine_tag) != 0)
DeleteForeignSessionInternal(sync_machine_tag, &new_changes);
#endif
@@ -639,7 +649,10 @@ void SessionsSyncManager::InitializeCurrentMachineTag() {
current_machine_tag_ = persisted_guid;
DVLOG(1) << "Restoring persisted session sync guid: " << persisted_guid;
} else {
- current_machine_tag_ = BuildMachineTag(delegate_->GetLocalSyncCacheGUID());
+ DCHECK(local_device_);
+ std::string cache_guid = local_device_->GetLocalSyncCacheGUID();
+ DCHECK(!cache_guid.empty());
+ current_machine_tag_ = BuildMachineTag(cache_guid);
DVLOG(1) << "Creating session sync guid: " << current_machine_tag_;
sync_prefs_.SetSyncSessionsGUID(current_machine_tag_);
}
@@ -954,6 +967,11 @@ FaviconCache* SessionsSyncManager::GetFaviconCache() {
return &favicon_cache_;
}
+SyncedWindowDelegatesGetter*
+SessionsSyncManager::GetSyncedWindowDelegatesGetter() const {
+ return synced_window_getter_.get();
+}
+
void SessionsSyncManager::DoGarbageCollection() {
std::vector<const SyncedSession*> sessions;
if (!GetAllForeignSessions(&sessions))