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