| OLD | NEW | 
|   1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |   1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 
|   2 // Use of this source code is governed by a BSD-style license that can be |   2 // Use of this source code is governed by a BSD-style license that can be | 
|   3 // found in the LICENSE file. |   3 // found in the LICENSE file. | 
|   4  |   4  | 
|   5 #include "sync/engine/store_timestamps_command.h" |   5 #include "sync/engine/store_timestamps_command.h" | 
|   6  |   6  | 
|   7 #include "sync/internal_api/public/base/model_type.h" |   7 #include "base/logging.h" | 
|   8 #include "sync/sessions/status_controller.h" |   8 #include "sync/sessions/status_controller.h" | 
|   9 #include "sync/sessions/sync_session.h" |   9 #include "sync/sessions/sync_session.h" | 
|  10 #include "sync/syncable/directory.h" |  10 #include "sync/syncable/directory.h" | 
|  11  |  11  | 
|  12 namespace syncer { |  12 namespace syncer { | 
|  13  |  13  | 
 |  14 ModelTypeSet ProcessNewProgressMarkers( | 
 |  15     const sync_pb::GetUpdatesResponse& response, | 
 |  16     syncable::Directory* dir) { | 
 |  17   ModelTypeSet forward_progress_types; | 
 |  18   // If a marker was omitted for any one type, that indicates no | 
 |  19   // change from the previous state. | 
 |  20   for (int i = 0; i < response.new_progress_marker_size(); ++i) { | 
 |  21     int field_number = response.new_progress_marker(i).data_type_id(); | 
 |  22     ModelType model_type = GetModelTypeFromSpecificsFieldNumber(field_number); | 
 |  23     if (!IsRealDataType(model_type)) { | 
 |  24       DLOG(WARNING) << "Unknown field number " << field_number; | 
 |  25       continue; | 
 |  26     } | 
 |  27     forward_progress_types.Put(model_type); | 
 |  28     dir->SetDownloadProgress(model_type, response.new_progress_marker(i)); | 
 |  29   } | 
 |  30   return forward_progress_types; | 
 |  31 } | 
 |  32  | 
|  14 StoreTimestampsCommand::StoreTimestampsCommand() {} |  33 StoreTimestampsCommand::StoreTimestampsCommand() {} | 
|  15 StoreTimestampsCommand::~StoreTimestampsCommand() {} |  34 StoreTimestampsCommand::~StoreTimestampsCommand() {} | 
|  16  |  35  | 
|  17 SyncerError StoreTimestampsCommand::ExecuteImpl( |  36 SyncerError StoreTimestampsCommand::ExecuteImpl( | 
|  18     sessions::SyncSession* session) { |  37     sessions::SyncSession* session) { | 
|  19   syncable::Directory* dir = session->context()->directory(); |  | 
|  20  |  | 
|  21   const sync_pb::GetUpdatesResponse& updates = |  38   const sync_pb::GetUpdatesResponse& updates = | 
|  22       session->status_controller().updates_response().get_updates(); |  39       session->status_controller().updates_response().get_updates(); | 
|  23  |  40  | 
|  24   sessions::StatusController* status = session->mutable_status_controller(); |  41   sessions::StatusController* status = session->mutable_status_controller(); | 
|  25  |  42  | 
|  26   // Update the progress marker tokens from the server result.  If a marker |  43   ModelTypeSet forward_progress_types = | 
|  27   // was omitted for any one type, that indicates no change from the previous |  44       ProcessNewProgressMarkers(updates, session->context()->directory()); | 
|  28   // state. |  | 
|  29   ModelTypeSet forward_progress_types; |  | 
|  30   for (int i = 0; i < updates.new_progress_marker_size(); ++i) { |  | 
|  31     int field_number = updates.new_progress_marker(i).data_type_id(); |  | 
|  32     ModelType model_type = GetModelTypeFromSpecificsFieldNumber(field_number); |  | 
|  33     if (!IsRealDataType(model_type)) { |  | 
|  34       NOTREACHED() << "Unknown field number " << field_number; |  | 
|  35       continue; |  | 
|  36     } |  | 
|  37     forward_progress_types.Put(model_type); |  | 
|  38     dir->SetDownloadProgress(model_type, updates.new_progress_marker(i)); |  | 
|  39   } |  | 
|  40   DCHECK(!forward_progress_types.Empty() || |  45   DCHECK(!forward_progress_types.Empty() || | 
|  41          updates.changes_remaining() == 0); |  46          updates.changes_remaining() == 0); | 
|  42   if (VLOG_IS_ON(1)) { |  47   if (VLOG_IS_ON(1)) { | 
|  43     DVLOG_IF(1, !forward_progress_types.Empty()) |  48     DVLOG_IF(1, !forward_progress_types.Empty()) | 
|  44         << "Get Updates got new progress marker for types: " |  49         << "Get Updates got new progress marker for types: " | 
|  45         << ModelTypeSetToString(forward_progress_types) |  50         << ModelTypeSetToString(forward_progress_types) | 
|  46         << " out of possible: " |  51         << " out of possible: " | 
|  47         << ModelTypeSetToString(status->updates_request_types()); |  52         << ModelTypeSetToString(status->updates_request_types()); | 
|  48   } |  53   } | 
|  49   if (updates.has_changes_remaining()) { |  54   if (updates.has_changes_remaining()) { | 
|  50     int64 changes_left = updates.changes_remaining(); |  55     int64 changes_left = updates.changes_remaining(); | 
|  51     DVLOG(1) << "Changes remaining: " << changes_left; |  56     DVLOG(1) << "Changes remaining: " << changes_left; | 
|  52     status->set_num_server_changes_remaining(changes_left); |  57     status->set_num_server_changes_remaining(changes_left); | 
|  53   } |  58   } | 
|  54  |  59  | 
|  55   return SYNCER_OK; |  60   return SYNCER_OK; | 
|  56 } |  61 } | 
|  57  |  62  | 
|  58 }  // namespace syncer |  63 }  // namespace syncer | 
| OLD | NEW |