syncer_end_command.cc revision 731df977c0511bca2206b5f333555b1205ff1f43
1// Copyright (c) 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#include "chrome/browser/sync/engine/syncer_end_command.h"
6
7#include "chrome/browser/sync/engine/syncer_types.h"
8#include "chrome/browser/sync/sessions/sync_session.h"
9#include "chrome/browser/sync/syncable/directory_manager.h"
10#include "chrome/common/deprecated/event_sys-inl.h"
11
12namespace browser_sync {
13
14SyncerEndCommand::SyncerEndCommand() {}
15SyncerEndCommand::~SyncerEndCommand() {}
16
17void SyncerEndCommand::ExecuteImpl(sessions::SyncSession* session) {
18  sessions::StatusController* status(session->status_controller());
19  status->set_syncing(false);
20  session->context()->set_previous_session_routing_info(
21      session->routing_info());
22  session->context()->set_last_snapshot(session->TakeSnapshot());
23
24  // This might be the first time we've fully completed a sync cycle, for
25  // some subset of the currently synced datatypes.
26  if (!session->HasMoreToSync() &&
27      status->ServerSaysNothingMoreToDownload()) {
28    syncable::ScopedDirLookup dir(session->context()->directory_manager(),
29                                  session->context()->account_name());
30    if (!dir.good()) {
31      LOG(ERROR) << "Scoped dir lookup failed!";
32      return;
33    }
34
35    for (int i = 0; i < syncable::MODEL_TYPE_COUNT; ++i) {
36      syncable::ModelType model_type = syncable::ModelTypeFromInt(i);
37      if (status->updates_request_parameters().data_types[i]) {
38        // This gets persisted to the directory's backing store.
39        dir->set_initial_sync_ended_for_type(model_type, true);
40      }
41    }
42  }
43
44  SyncEngineEvent event(SyncEngineEvent::SYNC_CYCLE_ENDED);
45  sessions::SyncSessionSnapshot snapshot(session->TakeSnapshot());
46  event.snapshot = &snapshot;
47  session->context()->NotifyListeners(event);
48}
49
50}  // namespace browser_sync
51