download_updates_command.h revision 3345a6884c488ff3a535c2c9acdd33d74b37e311
1// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_SYNC_ENGINE_DOWNLOAD_UPDATES_COMMAND_H_
6#define CHROME_BROWSER_SYNC_ENGINE_DOWNLOAD_UPDATES_COMMAND_H_
7#pragma once
8
9#include "base/basictypes.h"
10#include "chrome/browser/sync/engine/model_safe_worker.h"
11#include "chrome/browser/sync/engine/syncer_command.h"
12#include "chrome/browser/sync/syncable/model_type.h"
13
14namespace sync_pb {
15class EntitySpecifics;
16}
17
18namespace browser_sync {
19
20// Pick a subset of the enabled datatypes, download updates for them from
21// the server, place the result in the SyncSession for further processing.
22//
23// The main inputs to this operation are the last_download_timestamp state
24// in the syncable::Directory, and the set of enabled types as indicated by
25// the SyncSession. DownloadUpdatesCommand will fetch the enabled type
26// or types having the smallest (oldest) value for last_download_timestamp.
27// DownloadUpdatesCommand will request a download of those types and will
28// store the server response in the SyncSession. Only one server request
29// is performed per Execute operation. A loop that causes multiple Execute
30// operations within a sync session can be found in the Syncer logic.
31// When looping, the DownloadUpdatesCommand consumes the information stored
32// by the StoreTimestampsCommand.
33//
34// In practice, DownloadUpdatesCommand should exhibit one of two behaviors.
35// (a) If one or more datatypes has just been enabled, then they will have the
36//     oldest last_download_timestamp value (0). DownloadUpdatesCommand will
37//     choose to download updates for those types, and likely this will happen
38//     for several invocations of DownloadUpdatesCommand. Once the newly
39//     enabled types have caught up to the timestamp value of any previously
40//     enabled timestamps, DownloadUpdatesCommand will do a fetch for those
41//     datatypes. If nothing has changed on the server in the meantime,
42//     then the timestamp value for the new and old datatypes will now match.
43//     When that happens (and it eventually should), we have entered case (b).
44// (b) The common case is for all enabled datatypes to have the same
45//     last_download_timestamp value. This means that one server request
46//     tells us whether there are updates available to any datatype.  When
47//     the last_download_timestamp values for two datatypes is identical,
48//     those datatypes will never be separately requested, and the values
49//     will stay in lockstep indefinitely.
50class DownloadUpdatesCommand : public SyncerCommand {
51 public:
52  DownloadUpdatesCommand();
53  virtual ~DownloadUpdatesCommand();
54
55  // SyncerCommand implementation.
56  virtual void ExecuteImpl(sessions::SyncSession* session);
57
58  void SetRequestedTypes(const syncable::ModelTypeBitSet& target_datatypes,
59                         sync_pb::EntitySpecifics* filter_protobuf);
60
61 private:
62  DISALLOW_COPY_AND_ASSIGN(DownloadUpdatesCommand);
63};
64
65}  // namespace browser_sync
66
67#endif  // CHROME_BROWSER_SYNC_ENGINE_DOWNLOAD_UPDATES_COMMAND_H_
68
69