1c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Copyright (c) 2010 The Chromium Authors. All rights reserved.
2c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Use of this source code is governed by a BSD-style license that can be
3c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// found in the LICENSE file.
4c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
5c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#ifndef CHROME_BROWSER_SYNC_ENGINE_CLEANUP_DISABLED_TYPES_COMMAND_H_
6c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#define CHROME_BROWSER_SYNC_ENGINE_CLEANUP_DISABLED_TYPES_COMMAND_H_
73345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick#pragma once
8c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
9c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "chrome/browser/sync/engine/syncer_command.h"
10c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
11c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochnamespace browser_sync {
12c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
13c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// A syncer command that purges (from memory and disk) entries belonging to
14c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// a ModelType or ServerModelType that the user has not elected to sync.
15c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch//
16c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// This is done as part of a session to 1) ensure it does not block the UI,
17c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// and 2) avoid complicated races that could arise between a) deleting
18c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// things b) a sync session trying to use these things c) and the potential
19c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// re-enabling of the data type by the user before some scheduled deletion
20c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// took place.  Here, we are safe to perform I/O synchronously and we know it
21c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// is a safe time to delete as we are in the only active session.
22c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch//
23c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// The removal from memory is done synchronously, while the disk purge is left
24c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// to an asynchronous SaveChanges operation.  However, all the updates for
25c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// meta data fields (such as initial_sync_ended) as well as the actual entry
26c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// deletions will be committed in a single sqlite transaction.  Thus it is
27c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// possible that disabled types re-appear (in the sync db) after a reboot,
28c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// but things will remain in a consistent state.  This kind of error case is
29c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// cared for in this command by retrying; see ExecuteImpl.
30c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass CleanupDisabledTypesCommand : public SyncerCommand {
31c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch public:
32c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  CleanupDisabledTypesCommand();
33c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual ~CleanupDisabledTypesCommand();
34c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
35c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // SyncerCommand implementation.
36c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void ExecuteImpl(sessions::SyncSession* session);
37c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
38c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch private:
39c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  DISALLOW_COPY_AND_ASSIGN(CleanupDisabledTypesCommand);
40c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch};
41c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
42c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch}  // namespace browser_sync
43c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
44c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#endif  // CHROME_BROWSER_SYNC_ENGINE_CLEANUP_DISABLED_TYPES_COMMAND_H_
45c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
46