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

Unified Diff: chrome/browser/sync/glue/device_info_sync_service.h

Issue 430583003: Refactor syncable DEVICE_INFO type from ChangeProcessor to SyncableService - Part 2 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/sync/glue/device_info_sync_service.h
diff --git a/chrome/browser/sync/glue/device_info_sync_service.h b/chrome/browser/sync/glue/device_info_sync_service.h
new file mode 100644
index 0000000000000000000000000000000000000000..a21b8efd3b24be9d896682c66e4cd6403b424f11
--- /dev/null
+++ b/chrome/browser/sync/glue/device_info_sync_service.h
@@ -0,0 +1,85 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_SYNC_GLUE_DEVICE_INFO_SYNC_SERVICE_H_
+#define CHROME_BROWSER_SYNC_GLUE_DEVICE_INFO_SYNC_SERVICE_H_
+
+#include "base/callback_list.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/memory/scoped_vector.h"
+#include "chrome/browser/sync/glue/device_info.h"
+#include "sync/api/sync_change_processor.h"
+#include "sync/api/sync_data.h"
+#include "sync/api/sync_error_factory.h"
+#include "sync/api/syncable_service.h"
+
+namespace browser_sync {
+
+class LocalDeviceInfoProvider;
+
+// SyncableService implementation for DEVICE_INFO model type.
+class DeviceInfoSyncService : public syncer::SyncableService {
+ public:
+ explicit DeviceInfoSyncService(
+ LocalDeviceInfoProvider* local_device_info_provider);
+ virtual ~DeviceInfoSyncService();
+
+ // syncer::SyncableService implementation.
+ virtual syncer::SyncMergeResult MergeDataAndStartSyncing(
+ syncer::ModelType type,
+ const syncer::SyncDataList& initial_sync_data,
+ scoped_ptr<syncer::SyncChangeProcessor> sync_processor,
+ scoped_ptr<syncer::SyncErrorFactory> error_handler) OVERRIDE;
+ virtual void StopSyncing(syncer::ModelType type) OVERRIDE;
+ virtual syncer::SyncDataList GetAllSyncData(
+ syncer::ModelType type) const OVERRIDE;
+ virtual syncer::SyncError ProcessSyncChanges(
+ const tracked_objects::Location& from_here,
+ const syncer::SyncChangeList& change_list) OVERRIDE;
+
+ // DeviceInfoSyncService API
stanisc 2014/07/30 18:57:50 Will add missing period at the end of the sentence
stanisc 2014/08/01 18:54:51 Done.
+ scoped_ptr<DeviceInfo> GetDeviceInfo(const std::string& client_id) const;
+ ScopedVector<DeviceInfo> GetAllDeviceInfo() const;
+
+ typedef base::CallbackList<void(void)>::Subscription Subscription;
pavely 2014/07/31 22:52:40 nit: typedef should be before ctor (http://google-
stanisc 2014/08/01 18:54:51 Done.
+
+ // Registers an observer callback to be called on syncing any updated
+ // DeviceInfo. The callback remains registered until the returned
+ // Subscription is destroyed, which must occur before this object
+ // is destroyed.
+ scoped_ptr<Subscription> RegisterOnDeviceInfoChangedCallback(
+ const base::Closure& callback);
+
+ private:
+ // Create SyncData from local DeviceInfo.
+ static syncer::SyncData CreateLocalData(const DeviceInfo* info);
+ // Allocate new DeviceInfo from SyncData.
+ static DeviceInfo* CreateDeviceInfo(const syncer::SyncData sync_data);
+ // Store SyncData in the cache.
+ void StoreSyncData(
+ const std::string& client_id, const syncer::SyncData& sync_data);
+ // Delete SyncData from the cache.
+ void DeleteSyncData(const std::string& client_id);
+
+ // |local_device_info_provider_| isn't owned.
+ const LocalDeviceInfoProvider* const local_device_info_provider_;
+
+ // Receives ownership of |sync_processor_| and |error_handler_| in
+ // MergeDataAndStartSyncing() and destroy them in StopSyncing().
+ scoped_ptr<syncer::SyncChangeProcessor> sync_processor_;
+ scoped_ptr<syncer::SyncErrorFactory> error_handler_;
+
+ // Cache of all syncable and local data.
+ typedef std::map<std::string, syncer::SyncData> SyncDataMap;
+ SyncDataMap all_data_;
+
+ // Registered observer callbacks.
+ base::CallbackList<void(void)> callback_list_;
+
+ DISALLOW_COPY_AND_ASSIGN(DeviceInfoSyncService);
+};
+
+} // namespace browser_sync
+
+#endif // CHROME_BROWSER_SYNC_GLUE_DEVICE_INFO_SYNC_SERVICE_H_

Powered by Google App Engine
This is Rietveld 408576698