| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/sync/internal_api/sync_manager.h" | 5 #include "chrome/browser/sync/internal_api/sync_manager.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | |
| 9 | 8 |
| 10 #include "base/base64.h" | 9 #include "base/base64.h" |
| 11 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 12 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
| 13 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
| 14 #include "base/values.h" | 13 #include "base/values.h" |
| 15 #include "chrome/browser/sync/engine/all_status.h" | 14 #include "chrome/browser/sync/engine/all_status.h" |
| 16 #include "chrome/browser/sync/engine/net/server_connection_manager.h" | 15 #include "chrome/browser/sync/engine/net/server_connection_manager.h" |
| 17 #include "chrome/browser/sync/engine/nigori_util.h" | 16 #include "chrome/browser/sync/engine/nigori_util.h" |
| 18 #include "chrome/browser/sync/engine/syncapi_internal.h" | 17 #include "chrome/browser/sync/engine/syncapi_internal.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 42 #include "chrome/browser/sync/syncable/directory_manager.h" | 41 #include "chrome/browser/sync/syncable/directory_manager.h" |
| 43 #include "chrome/browser/sync/syncable/model_type.h" | 42 #include "chrome/browser/sync/syncable/model_type.h" |
| 44 #include "chrome/browser/sync/syncable/model_type_payload_map.h" | 43 #include "chrome/browser/sync/syncable/model_type_payload_map.h" |
| 45 #include "chrome/browser/sync/syncable/syncable.h" | 44 #include "chrome/browser/sync/syncable/syncable.h" |
| 46 #include "chrome/browser/sync/util/cryptographer.h" | 45 #include "chrome/browser/sync/util/cryptographer.h" |
| 47 #include "chrome/browser/sync/weak_handle.h" | 46 #include "chrome/browser/sync/weak_handle.h" |
| 48 #include "chrome/common/chrome_switches.h" | 47 #include "chrome/common/chrome_switches.h" |
| 49 #include "net/base/network_change_notifier.h" | 48 #include "net/base/network_change_notifier.h" |
| 50 | 49 |
| 51 using std::string; | 50 using std::string; |
| 52 using std::vector; | |
| 53 | 51 |
| 54 using base::TimeDelta; | 52 using base::TimeDelta; |
| 55 using browser_sync::AllStatus; | 53 using browser_sync::AllStatus; |
| 56 using browser_sync::Cryptographer; | 54 using browser_sync::Cryptographer; |
| 57 using browser_sync::JsArgList; | 55 using browser_sync::JsArgList; |
| 58 using browser_sync::JsBackend; | 56 using browser_sync::JsBackend; |
| 59 using browser_sync::JsEventDetails; | 57 using browser_sync::JsEventDetails; |
| 60 using browser_sync::JsEventHandler; | 58 using browser_sync::JsEventHandler; |
| 61 using browser_sync::JsEventHandler; | 59 using browser_sync::JsEventHandler; |
| 62 using browser_sync::JsReplyHandler; | 60 using browser_sync::JsReplyHandler; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 NOTREACHED(); | 104 NOTREACHED(); |
| 107 } | 105 } |
| 108 | 106 |
| 109 return GetUpdatesCallerInfo::UNKNOWN; | 107 return GetUpdatesCallerInfo::UNKNOWN; |
| 110 } | 108 } |
| 111 | 109 |
| 112 } // namespace | 110 } // namespace |
| 113 | 111 |
| 114 namespace sync_api { | 112 namespace sync_api { |
| 115 | 113 |
| 116 SyncManager::ChangeRecord::ChangeRecord() | |
| 117 : id(kInvalidId), action(ACTION_ADD) {} | |
| 118 | |
| 119 SyncManager::ChangeRecord::~ChangeRecord() {} | |
| 120 | |
| 121 DictionaryValue* SyncManager::ChangeRecord::ToValue( | |
| 122 const BaseTransaction* trans) const { | |
| 123 DictionaryValue* value = new DictionaryValue(); | |
| 124 std::string action_str; | |
| 125 switch (action) { | |
| 126 case ACTION_ADD: | |
| 127 action_str = "Add"; | |
| 128 break; | |
| 129 case ACTION_DELETE: | |
| 130 action_str = "Delete"; | |
| 131 break; | |
| 132 case ACTION_UPDATE: | |
| 133 action_str = "Update"; | |
| 134 break; | |
| 135 default: | |
| 136 NOTREACHED(); | |
| 137 action_str = "Unknown"; | |
| 138 break; | |
| 139 } | |
| 140 value->SetString("action", action_str); | |
| 141 Value* node_value = NULL; | |
| 142 if (action == ACTION_DELETE) { | |
| 143 DictionaryValue* node_dict = new DictionaryValue(); | |
| 144 node_dict->SetString("id", base::Int64ToString(id)); | |
| 145 node_dict->Set("specifics", | |
| 146 browser_sync::EntitySpecificsToValue(specifics)); | |
| 147 if (extra.get()) { | |
| 148 node_dict->Set("extra", extra->ToValue()); | |
| 149 } | |
| 150 node_value = node_dict; | |
| 151 } else { | |
| 152 ReadNode node(trans); | |
| 153 if (node.InitByIdLookup(id)) { | |
| 154 node_value = node.GetDetailsAsValue(); | |
| 155 } | |
| 156 } | |
| 157 if (!node_value) { | |
| 158 NOTREACHED(); | |
| 159 node_value = Value::CreateNullValue(); | |
| 160 } | |
| 161 value->Set("node", node_value); | |
| 162 return value; | |
| 163 } | |
| 164 | |
| 165 SyncManager::ExtraPasswordChangeRecordData::ExtraPasswordChangeRecordData() {} | |
| 166 | |
| 167 SyncManager::ExtraPasswordChangeRecordData::ExtraPasswordChangeRecordData( | |
| 168 const sync_pb::PasswordSpecificsData& data) | |
| 169 : unencrypted_(data) { | |
| 170 } | |
| 171 | |
| 172 SyncManager::ExtraPasswordChangeRecordData::~ExtraPasswordChangeRecordData() {} | |
| 173 | |
| 174 DictionaryValue* SyncManager::ExtraPasswordChangeRecordData::ToValue() const { | |
| 175 return browser_sync::PasswordSpecificsDataToValue(unencrypted_); | |
| 176 } | |
| 177 | |
| 178 const sync_pb::PasswordSpecificsData& | |
| 179 SyncManager::ExtraPasswordChangeRecordData::unencrypted() const { | |
| 180 return unencrypted_; | |
| 181 } | |
| 182 | |
| 183 ////////////////////////////////////////////////////////////////////////// | 114 ////////////////////////////////////////////////////////////////////////// |
| 184 // SyncManager's implementation: SyncManager::SyncInternal | 115 // SyncManager's implementation: SyncManager::SyncInternal |
| 185 class SyncManager::SyncInternal | 116 class SyncManager::SyncInternal |
| 186 : public net::NetworkChangeNotifier::IPAddressObserver, | 117 : public net::NetworkChangeNotifier::IPAddressObserver, |
| 187 public sync_notifier::SyncNotifierObserver, | 118 public sync_notifier::SyncNotifierObserver, |
| 188 public JsBackend, | 119 public JsBackend, |
| 189 public SyncEngineEventListener, | 120 public SyncEngineEventListener, |
| 190 public ServerConnectionEventListener, | 121 public ServerConnectionEventListener, |
| 191 public syncable::DirectoryChangeDelegate { | 122 public syncable::DirectoryChangeDelegate { |
| 192 static const int kDefaultNudgeDelayMilliseconds; | 123 static const int kDefaultNudgeDelayMilliseconds; |
| (...skipping 1232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1425 // This is the last chance for read to occur in the WriteTransaction | 1356 // This is the last chance for read to occur in the WriteTransaction |
| 1426 // that's closing. This special ReadTransaction will not close the | 1357 // that's closing. This special ReadTransaction will not close the |
| 1427 // underlying transaction. | 1358 // underlying transaction. |
| 1428 ReadTransaction read_trans(GetUserShare(), trans); | 1359 ReadTransaction read_trans(GetUserShare(), trans); |
| 1429 | 1360 |
| 1430 syncable::ModelTypeBitSet models_with_changes; | 1361 syncable::ModelTypeBitSet models_with_changes; |
| 1431 for (int i = 0; i < syncable::MODEL_TYPE_COUNT; ++i) { | 1362 for (int i = 0; i < syncable::MODEL_TYPE_COUNT; ++i) { |
| 1432 if (change_buffers_[i].IsEmpty()) | 1363 if (change_buffers_[i].IsEmpty()) |
| 1433 continue; | 1364 continue; |
| 1434 | 1365 |
| 1435 vector<ChangeRecord> ordered_changes; | 1366 ImmutableChangeRecordList ordered_changes = |
| 1436 change_buffers_[i].GetAllChangesInTreeOrder(&read_trans, &ordered_changes); | 1367 change_buffers_[i].GetAllChangesInTreeOrder(&read_trans); |
| 1437 if (!ordered_changes.empty()) { | 1368 if (!ordered_changes.Get().empty()) { |
| 1438 ObserverList<SyncManager::Observer> temp_obs_list; | 1369 ObserverList<SyncManager::Observer> temp_obs_list; |
| 1439 CopyObservers(&temp_obs_list); | 1370 CopyObservers(&temp_obs_list); |
| 1440 FOR_EACH_OBSERVER(SyncManager::Observer, temp_obs_list, | 1371 FOR_EACH_OBSERVER(SyncManager::Observer, temp_obs_list, |
| 1441 OnChangesApplied(syncable::ModelTypeFromInt(i), &read_trans, | 1372 OnChangesApplied(syncable::ModelTypeFromInt(i), |
| 1442 &ordered_changes[0], ordered_changes.size())); | 1373 &read_trans, ordered_changes)); |
| 1443 models_with_changes.set(i, true); | 1374 models_with_changes.set(i, true); |
| 1444 } | 1375 } |
| 1445 change_buffers_[i].Clear(); | 1376 change_buffers_[i].Clear(); |
| 1446 } | 1377 } |
| 1447 return models_with_changes; | 1378 return models_with_changes; |
| 1448 } | 1379 } |
| 1449 | 1380 |
| 1450 void SyncManager::SyncInternal::HandleCalculateChangesChangeEventFromSyncApi( | 1381 void SyncManager::SyncInternal::HandleCalculateChangesChangeEventFromSyncApi( |
| 1451 const EntryKernelMutationMap& mutations, | 1382 const EntryKernelMutationMap& mutations, |
| 1452 syncable::BaseTransaction* trans) { | 1383 syncable::BaseTransaction* trans) { |
| (...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2148 | 2079 |
| 2149 for (syncable::ModelTypeSet::const_iterator i = types.begin(); | 2080 for (syncable::ModelTypeSet::const_iterator i = types.begin(); |
| 2150 i != types.end(); ++i) { | 2081 i != types.end(); ++i) { |
| 2151 if (!lookup->initial_sync_ended_for_type(*i)) | 2082 if (!lookup->initial_sync_ended_for_type(*i)) |
| 2152 return false; | 2083 return false; |
| 2153 } | 2084 } |
| 2154 return true; | 2085 return true; |
| 2155 } | 2086 } |
| 2156 | 2087 |
| 2157 } // namespace sync_api | 2088 } // namespace sync_api |
| OLD | NEW |