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

Unified Diff: chrome/browser/ui/app_list/arc/arc_package_syncable_service.h

Issue 2106663004: arc: Initial implemetation of Chrome sync for Arc packages. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. More refactor. Fix unit_test related to refactor. Created 4 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/ui/app_list/arc/arc_package_syncable_service.h
diff --git a/chrome/browser/ui/app_list/arc/arc_package_syncable_service.h b/chrome/browser/ui/app_list/arc/arc_package_syncable_service.h
new file mode 100644
index 0000000000000000000000000000000000000000..362d564cdfd0a94be3cae4dd74c8076f059ddd9b
--- /dev/null
+++ b/chrome/browser/ui/app_list/arc/arc_package_syncable_service.h
@@ -0,0 +1,136 @@
+// Copyright 2016 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_UI_APP_LIST_ARC_ARC_PACKAGE_SYNCABLE_SERVICE_H_
+#define CHROME_BROWSER_UI_APP_LIST_ARC_ARC_PACKAGE_SYNCABLE_SERVICE_H_
+
+#include <stddef.h>
+
+#include <map>
+#include <memory>
+#include <string>
+
+#include "base/macros.h"
+#include "chrome/browser/sync/glue/sync_start_util.h"
+#include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h"
+#include "components/keyed_service/core/keyed_service.h"
+#include "sync/api/sync_change.h"
+#include "sync/api/sync_change_processor.h"
+#include "sync/api/sync_error_factory.h"
+#include "sync/api/syncable_service.h"
+#include "sync/protocol/arc_package_specifics.pb.h"
+
+class Profile;
+
+namespace content {
+class BrowserContext;
+} // namespace content
+
+namespace arc {
+
+// Class that syncs ARC pakcages install/uninstall.
+class ArcPackageSyncableService : public syncer::SyncableService,
+ public KeyedService,
+ public ArcAppListPrefs::Observer {
+ public:
+ struct SyncItem {
+ SyncItem(const std::string& package_name,
+ int32_t package_version,
+ int64_t last_backup_android_id,
+ int64_t last_backup_time);
+ const std::string package_name;
+ int32_t package_version;
+ int64_t last_backup_android_id;
+ int64_t last_backup_time;
+ };
Luis Héctor Chávez 2016/07/20 00:01:15 Given that this will always be wrapped in an uniqu
lgcheng 2016/07/20 01:23:58 I have seen reviewers require to remove DISALLOW_C
+
+ ~ArcPackageSyncableService() override;
+
+ static ArcPackageSyncableService* Create(Profile* profile);
+ static ArcPackageSyncableService* Get(content::BrowserContext* context);
+
+ // syncer::SyncableService:
+ syncer::SyncMergeResult MergeDataAndStartSyncing(
+ syncer::ModelType type,
+ const syncer::SyncDataList& initial_sync_data,
+ std::unique_ptr<syncer::SyncChangeProcessor> sync_processor,
+ std::unique_ptr<syncer::SyncErrorFactory> error_handler) override;
+ void StopSyncing(syncer::ModelType type) override;
+ syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const override;
+ syncer::SyncError ProcessSyncChanges(
+ const tracked_objects::Location& from_here,
+ const syncer::SyncChangeList& change_list) override;
+
+ bool SyncStarted();
+ void SetAppInstance(mojom::AppInstance* app_instance);
+
+ private:
+ using SyncItemMap = std::map<std::string, std::unique_ptr<SyncItem>>;
Luis Héctor Chávez 2016/07/20 00:01:15 std::unordered_map?
lgcheng 2016/07/20 01:23:58 Done.
+
+ explicit ArcPackageSyncableService(Profile* profile);
+
+ // ArcAppListPrefs::Observer:
+ void OnPackageInstalled(const mojom::ArcPackageInfo& package_info) override;
+ void OnPackageModified(const mojom::ArcPackageInfo& package_info) override;
+ void OnPackageRemoved(const std::string& package_name) override;
+
+ // Sends adds/updates sync change to sync server.
+ void SendSyncChange(
+ const mojom::ArcPackageInfo& package_info,
+ const syncer::SyncChange::SyncChangeType& sync_change_type);
+
+ // Creates or updates local syncItem with data change from sync server. Sends
+ // request to install/update package to Android.
+ bool ProcessSyncItemSpecifics(const sync_pb::ArcPackageSpecifics& specifics);
+
+ // Deletes local syncItem corresponding to data change from sync server.
+ // Sends request to uninstall package to Android.
+ bool DeleteSyncItemSpecifics(const sync_pb::ArcPackageSpecifics& specifics);
+
+ // Sends install notification for given package to Android.
+ void InstallPackage(const SyncItem* sync_item);
+
+ // Sends uninstall notification for given package to Android.
+ void UninstallPackage(const SyncItem* sync_item);
+
+ // Returns if a package should be synced.
+ // TODO(lgcheng@) Supoort may need to be added in this function for different
+ // use cases.
+ bool ShouldSyncPackage(const std::string& package_name) const;
+
+ Profile* profile_;
Luis Héctor Chávez 2016/07/20 00:01:15 Profile* const profile_; ?
lgcheng 2016/07/20 01:23:58 Done.
+ std::unique_ptr<syncer::SyncChangeProcessor> sync_processor_;
+ std::unique_ptr<syncer::SyncErrorFactory> sync_error_handler_;
+
+ // Items which are synced.
+ SyncItemMap sync_items_;
+
+ // Items new from sync service, waiting for confirmation of installation.
+ // These items may never be approved for installation and this structure is
+ // used to ensure syncer::SyncDataList GetAllSyncData(syncer::ModelType type)
+ // returns consistent results from different devices.
+ // API to re-install pending_install_items_ can be created when needed.
+ SyncItemMap pending_install_items_;
+
+ // Items to delete from sync service, waiting for confirmation of
+ // uninstallation. These items will no longer be counted in
+ // syncer::SyncDataList GetAllSyncData(syncer::ModelType type).
+ // API to re-uninstall pending_uninstall_items_ can be created when needed.
+ SyncItemMap pending_uninstall_items_;
+
+ // Run()ning tells sync to try and start soon, because syncable changes
+ // have started happening. It will cause sync to call us back
+ // asynchronously via MergeDataAndStartSyncing as soon as possible.
+ syncer::SyncableService::StartSyncFlare flare_;
+
+ ArcAppListPrefs* prefs_;
Luis Héctor Chávez 2016/07/20 00:01:15 ArcAppListPrefs* const prefs_; ?
lgcheng 2016/07/20 01:23:58 Done.
+
+ mojom::AppInstance* app_instance_;
Luis Héctor Chávez 2016/07/20 00:01:15 You shouldn't keep a reference to this. If necessa
lgcheng 2016/07/20 01:23:58 I think you are right. Let me ask some questions o
+
+ DISALLOW_COPY_AND_ASSIGN(ArcPackageSyncableService);
+};
+
+} // namespace arc
+
+#endif // CHROME_BROWSER_UI_APP_LIST_ARC_ARC_PACKAGE_SYNCABLE_SERVICE_H_

Powered by Google App Engine
This is Rietveld 408576698