summaryrefslogtreecommitdiffstats
path: root/sync/engine/store_timestamps_command.cc
blob: 5911fca41a71e3434962b807861c377811a397f3 (plain)
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
// Copyright (c) 2012 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.

#include "sync/engine/store_timestamps_command.h"

#include "sync/internal_api/public/base/model_type.h"
#include "sync/sessions/status_controller.h"
#include "sync/sessions/sync_session.h"
#include "sync/syncable/directory.h"

namespace syncer {

StoreTimestampsCommand::StoreTimestampsCommand() {}
StoreTimestampsCommand::~StoreTimestampsCommand() {}

SyncerError StoreTimestampsCommand::ExecuteImpl(
    sessions::SyncSession* session) {
  syncable::Directory* dir = session->context()->directory();

  const GetUpdatesResponse& updates =
      session->status_controller().updates_response().get_updates();

  sessions::StatusController* status = session->mutable_status_controller();

  // Update the progress marker tokens from the server result.  If a marker
  // was omitted for any one type, that indicates no change from the previous
  // state.
  syncer::ModelTypeSet forward_progress_types;
  for (int i = 0; i < updates.new_progress_marker_size(); ++i) {
    syncer::ModelType model =
        syncer::GetModelTypeFromSpecificsFieldNumber(
            updates.new_progress_marker(i).data_type_id());
    if (model == syncer::UNSPECIFIED || model == syncer::TOP_LEVEL_FOLDER) {
      NOTREACHED() << "Unintelligible server response.";
      continue;
    }
    forward_progress_types.Put(model);
    dir->SetDownloadProgress(model, updates.new_progress_marker(i));
  }
  DCHECK(!forward_progress_types.Empty() ||
         updates.changes_remaining() == 0);
  if (VLOG_IS_ON(1)) {
    DVLOG_IF(1, !forward_progress_types.Empty())
        << "Get Updates got new progress marker for types: "
        << syncer::ModelTypeSetToString(forward_progress_types)
        << " out of possible: "
        << syncer::ModelTypeSetToString(status->updates_request_types());
  }
  if (updates.has_changes_remaining()) {
    int64 changes_left = updates.changes_remaining();
    DVLOG(1) << "Changes remaining: " << changes_left;
    status->set_num_server_changes_remaining(changes_left);
  }

  return SYNCER_OK;
}

}  // namespace syncer