File: local_data_migration_item_queue.h

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,122,156 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (65 lines) | stat: -rw-r--r-- 2,542 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_SYNC_SERVICE_LOCAL_DATA_MIGRATION_ITEM_QUEUE_H_
#define COMPONENTS_SYNC_SERVICE_LOCAL_DATA_MIGRATION_ITEM_QUEUE_H_

#include <map>
#include <tuple>

#include "base/scoped_observation.h"
#include "base/time/default_clock.h"
#include "components/sync/service/local_data_description.h"
#include "components/sync/service/sync_service_observer.h"

namespace syncer {

class SyncService;
class DataTypeManager;

// This class is used to migrate data to account storage once the sync service
// activates, if the user is eligible for account storage.
// The queue `items_` is cleared when sync is paused or disabled, for example
// when the user signs out. An item is removed from the queue if it had been
// added more than `kTimeLimitForActivatingDataType` minutes ago, or if its data
// type is non-preferred. If the data type is not active, the item stays in the
// queue.
class LocalDataMigrationItemQueue : public SyncServiceObserver {
 public:
  // `sync_service` and `data_type_manager` must not be null and must outlive
  // this class.
  LocalDataMigrationItemQueue(SyncService* sync_service,
                              DataTypeManager* data_type_manager);
  ~LocalDataMigrationItemQueue() override;

  // Adds the `items` to the queue and triggers `OnStateChanged()` once. If sync
  // is disabled or the user has consented to sync, the items are removed again.
  void TriggerLocalDataMigrationForItemsWhenTypeBecomesActive(
      DataType data_type,
      std::vector<LocalDataItemModel::DataId> items);

  // SyncServiceObserver:
  void OnStateChanged(SyncService* sync_service) override;
  void OnSyncShutdown(SyncService* sync_service) override;

  void SetClockForTesting(base::Clock* clock);

  // Returns the number of items in the queue `items_`.
  size_t GetItemsCountForTesting() const;

 private:
  const raw_ptr<SyncService> sync_service_;
  const raw_ptr<DataTypeManager> data_type_manager_;
  raw_ptr<base::Clock> clock_;
  // TODO (crbug.com/385310859): Create a function that converts from `DataId`
  // to `DataType` so that we don't need to store this information.
  std::map<syncer::LocalDataItemModel::DataId, std::tuple<DataType, base::Time>>
      items_;
  base::ScopedObservation<SyncService, SyncServiceObserver>
      sync_service_observer_{this};
};

}  // namespace syncer

#endif  // COMPONENTS_SYNC_SERVICE_LOCAL_DATA_MIGRATION_ITEM_QUEUE_H_