Home | History | Annotate | Download | only in engine
      1 // Copyright (c) 2010 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/store_timestamps_command.h"
      6 
      7 #include "chrome/browser/sync/sessions/status_controller.h"
      8 #include "chrome/browser/sync/sessions/sync_session.h"
      9 #include "chrome/browser/sync/syncable/directory_manager.h"
     10 #include "chrome/browser/sync/syncable/model_type.h"
     11 #include "chrome/browser/sync/syncable/syncable.h"
     12 
     13 namespace browser_sync {
     14 
     15 StoreTimestampsCommand::StoreTimestampsCommand() {}
     16 StoreTimestampsCommand::~StoreTimestampsCommand() {}
     17 
     18 void StoreTimestampsCommand::ExecuteImpl(sessions::SyncSession* session) {
     19   syncable::ScopedDirLookup dir(session->context()->directory_manager(),
     20                                 session->context()->account_name());
     21 
     22   if (!dir.good()) {
     23     LOG(ERROR) << "Scoped dir lookup failed!";
     24     return;
     25   }
     26 
     27   const GetUpdatesResponse& updates =
     28       session->status_controller()->updates_response().get_updates();
     29 
     30   sessions::StatusController* status = session->status_controller();
     31 
     32   // Update the progress marker tokens from the server result.  If a marker
     33   // was omitted for any one type, that indicates no change from the previous
     34   // state.
     35   syncable::ModelTypeBitSet forward_progress_types;
     36   for (int i = 0; i < updates.new_progress_marker_size(); ++i) {
     37     syncable::ModelType model =
     38         syncable::GetModelTypeFromExtensionFieldNumber(
     39             updates.new_progress_marker(i).data_type_id());
     40     if (model == syncable::UNSPECIFIED || model == syncable::TOP_LEVEL_FOLDER) {
     41       NOTREACHED() << "Unintelligible server response.";
     42       continue;
     43     }
     44     forward_progress_types[model] = true;
     45     dir->SetDownloadProgress(model, updates.new_progress_marker(i));
     46   }
     47   DCHECK(forward_progress_types.any() ||
     48          updates.changes_remaining() == 0);
     49   if (VLOG_IS_ON(1)) {
     50     VLOG_IF(1, forward_progress_types.any())
     51         << "Get Updates got new progress marker for types: "
     52         << forward_progress_types.to_string() << " out of possible: "
     53         << status->updates_request_types().to_string();
     54   }
     55   if (updates.has_changes_remaining()) {
     56     int64 changes_left = updates.changes_remaining();
     57     VLOG(1) << "Changes remaining: " << changes_left;
     58     status->set_num_server_changes_remaining(changes_left);
     59   }
     60 }
     61 
     62 }  // namespace browser_sync
     63