OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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/api/sync_event.h" |
| 6 |
| 7 #include "chrome/browser/sync/api/sync_data.h" |
| 8 |
| 9 SyncEvent::SyncEvent() : event_type_(ACTION_INVALID) { |
| 10 } |
| 11 |
| 12 SyncEvent::SyncEvent(SyncEventType event_type, const SyncData& sync_data) |
| 13 : event_type_(event_type), |
| 14 sync_data_(sync_data) { |
| 15 DCHECK(IsValid()); |
| 16 } |
| 17 |
| 18 SyncEvent::~SyncEvent() {} |
| 19 |
| 20 bool SyncEvent::IsValid() const { |
| 21 if (event_type_ == ACTION_INVALID || !sync_data_.IsValid()) |
| 22 return false; |
| 23 |
| 24 // Data from the syncer must always have specifics. |
| 25 if (!sync_data_.IsLocal()) { |
| 26 if (sync_data_.GetDataType() == syncable::UNSPECIFIED) |
| 27 return false; |
| 28 else |
| 29 return true; |
| 30 } |
| 31 |
| 32 // Local events must always have a tag. |
| 33 if (sync_data_.GetTag().empty()) |
| 34 return false; |
| 35 |
| 36 // Adds and updates must have valid specifics (checked by GetDataType()) |
| 37 if (event_type_ == ACTION_ADD || event_type_ == ACTION_UPDATE) { |
| 38 if (sync_data_.GetDataType() != syncable::UNSPECIFIED) |
| 39 return true; |
| 40 else |
| 41 return false; |
| 42 } else { // ACTION_DELETE only requires tag. |
| 43 return true; |
| 44 } |
| 45 |
| 46 return true; |
| 47 } |
| 48 |
| 49 SyncEvent::SyncEventType SyncEvent::event_type() const { |
| 50 return event_type_; |
| 51 } |
| 52 |
| 53 SyncData SyncEvent::sync_data() const { |
| 54 return sync_data_; |
| 55 } |
OLD | NEW |