Home | History | Annotate | Download | only in engine
      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_PROCESS_COMMIT_RESPONSE_COMMAND_H_
      6 #define CHROME_BROWSER_SYNC_ENGINE_PROCESS_COMMIT_RESPONSE_COMMAND_H_
      7 #pragma once
      8 
      9 #include <set>
     10 #include <string>
     11 
     12 #include "base/basictypes.h"
     13 #include "chrome/browser/sync/engine/model_changing_syncer_command.h"
     14 #include "chrome/browser/sync/engine/syncproto.h"
     15 
     16 namespace syncable {
     17 class Id;
     18 class WriteTransaction;
     19 class MutableEntry;
     20 }
     21 
     22 namespace browser_sync {
     23 
     24 class ProcessCommitResponseCommand : public ModelChangingSyncerCommand {
     25  public:
     26 
     27   ProcessCommitResponseCommand();
     28   virtual ~ProcessCommitResponseCommand();
     29 
     30   // ModelChangingSyncerCommand implementation.
     31   virtual bool ModelNeutralExecuteImpl(sessions::SyncSession* session);
     32   virtual void ModelChangingExecuteImpl(sessions::SyncSession* session);
     33 
     34  private:
     35   CommitResponse::ResponseType ProcessSingleCommitResponse(
     36       syncable::WriteTransaction* trans,
     37       const sync_pb::CommitResponse_EntryResponse& pb_commit_response,
     38       const sync_pb::SyncEntity& pb_committed_entry,
     39       const syncable::Id& pre_commit_id,
     40       std::set<syncable::Id>* conflicting_new_directory_ids,
     41       std::set<syncable::Id>* deleted_folders);
     42 
     43   // Actually does the work of execute.
     44   void ProcessCommitResponse(sessions::SyncSession* session);
     45 
     46   void ProcessSuccessfulCommitResponse(
     47       const sync_pb::SyncEntity& committed_entry,
     48       const CommitResponse_EntryResponse& entry_response,
     49       const syncable::Id& pre_commit_id, syncable::MutableEntry* local_entry,
     50       bool syncing_was_set, std::set<syncable::Id>* deleted_folders);
     51 
     52   // Update the BASE_VERSION and SERVER_VERSION, post-commit.
     53   // Helper for ProcessSuccessfulCommitResponse.
     54   bool UpdateVersionAfterCommit(
     55       const sync_pb::SyncEntity& committed_entry,
     56       const CommitResponse_EntryResponse& entry_response,
     57       const syncable::Id& pre_commit_id,
     58       syncable::MutableEntry* local_entry);
     59 
     60   // If the server generated an ID for us during a commit, apply the new ID.
     61   // Helper for ProcessSuccessfulCommitResponse.
     62   bool ChangeIdAfterCommit(
     63       const CommitResponse_EntryResponse& entry_response,
     64       const syncable::Id& pre_commit_id,
     65       syncable::MutableEntry* local_entry);
     66 
     67   // Update the SERVER_ fields to reflect the server state after committing.
     68   // Helper for ProcessSuccessfulCommitResponse.
     69   void UpdateServerFieldsAfterCommit(
     70       const sync_pb::SyncEntity& committed_entry,
     71       const CommitResponse_EntryResponse& entry_response,
     72       syncable::MutableEntry* local_entry);
     73 
     74   // The server can override some values during a commit; the overridden values
     75   // are returned as fields in the CommitResponse_EntryResponse.  This method
     76   // stores the fields back in the client-visible (i.e. not the SERVER_* fields)
     77   // fields of the entry.  This should only be done if the item did not change
     78   // locally while the commit was in flight.
     79   // Helper for ProcessSuccessfulCommitResponse.
     80   void OverrideClientFieldsAfterCommit(
     81       const sync_pb::SyncEntity& committed_entry,
     82       const CommitResponse_EntryResponse& entry_response,
     83       syncable::MutableEntry* local_entry);
     84 
     85   // Helper to extract the final name from the protobufs.
     86   const std::string& GetResultingPostCommitName(
     87       const sync_pb::SyncEntity& committed_entry,
     88       const CommitResponse_EntryResponse& entry_response);
     89 
     90   DISALLOW_COPY_AND_ASSIGN(ProcessCommitResponseCommand);
     91 };
     92 
     93 }  // namespace browser_sync
     94 
     95 #endif  // CHROME_BROWSER_SYNC_ENGINE_PROCESS_COMMIT_RESPONSE_COMMAND_H_
     96