Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: chrome/browser/sync/internal_api/sync_manager.cc

Issue 7918001: [Sync] Move ChangeRecord into its own file (change_record.{h,cc}) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 22 matching lines...) Expand all
41 #include "chrome/browser/sync/syncable/directory_change_delegate.h" 40 #include "chrome/browser/sync/syncable/directory_change_delegate.h"
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/common/chrome_switches.h" 46 #include "chrome/common/chrome_switches.h"
48 #include "net/base/network_change_notifier.h" 47 #include "net/base/network_change_notifier.h"
49 48
50 using std::string; 49 using std::string;
51 using std::vector;
52 50
53 using base::TimeDelta; 51 using base::TimeDelta;
54 using browser_sync::AllStatus; 52 using browser_sync::AllStatus;
55 using browser_sync::Cryptographer; 53 using browser_sync::Cryptographer;
56 using browser_sync::JsArgList; 54 using browser_sync::JsArgList;
57 using browser_sync::JsBackend; 55 using browser_sync::JsBackend;
58 using browser_sync::JsEventDetails; 56 using browser_sync::JsEventDetails;
59 using browser_sync::JsEventHandler; 57 using browser_sync::JsEventHandler;
60 using browser_sync::JsEventHandler; 58 using browser_sync::JsEventHandler;
61 using browser_sync::JsReplyHandler; 59 using browser_sync::JsReplyHandler;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 NOTREACHED(); 103 NOTREACHED();
106 } 104 }
107 105
108 return GetUpdatesCallerInfo::UNKNOWN; 106 return GetUpdatesCallerInfo::UNKNOWN;
109 } 107 }
110 108
111 } // namespace 109 } // namespace
112 110
113 namespace sync_api { 111 namespace sync_api {
114 112
115 SyncManager::ChangeRecord::ChangeRecord()
116 : id(kInvalidId), action(ACTION_ADD) {}
117
118 SyncManager::ChangeRecord::~ChangeRecord() {}
119
120 DictionaryValue* SyncManager::ChangeRecord::ToValue(
121 const BaseTransaction* trans) const {
122 DictionaryValue* value = new DictionaryValue();
123 std::string action_str;
124 switch (action) {
125 case ACTION_ADD:
126 action_str = "Add";
127 break;
128 case ACTION_DELETE:
129 action_str = "Delete";
130 break;
131 case ACTION_UPDATE:
132 action_str = "Update";
133 break;
134 default:
135 NOTREACHED();
136 action_str = "Unknown";
137 break;
138 }
139 value->SetString("action", action_str);
140 Value* node_value = NULL;
141 if (action == ACTION_DELETE) {
142 DictionaryValue* node_dict = new DictionaryValue();
143 node_dict->SetString("id", base::Int64ToString(id));
144 node_dict->Set("specifics",
145 browser_sync::EntitySpecificsToValue(specifics));
146 if (extra.get()) {
147 node_dict->Set("extra", extra->ToValue());
148 }
149 node_value = node_dict;
150 } else {
151 ReadNode node(trans);
152 if (node.InitByIdLookup(id)) {
153 node_value = node.GetDetailsAsValue();
154 }
155 }
156 if (!node_value) {
157 NOTREACHED();
158 node_value = Value::CreateNullValue();
159 }
160 value->Set("node", node_value);
161 return value;
162 }
163
164 SyncManager::ExtraPasswordChangeRecordData::ExtraPasswordChangeRecordData() {}
165
166 SyncManager::ExtraPasswordChangeRecordData::ExtraPasswordChangeRecordData(
167 const sync_pb::PasswordSpecificsData& data)
168 : unencrypted_(data) {
169 }
170
171 SyncManager::ExtraPasswordChangeRecordData::~ExtraPasswordChangeRecordData() {}
172
173 DictionaryValue* SyncManager::ExtraPasswordChangeRecordData::ToValue() const {
174 return browser_sync::PasswordSpecificsDataToValue(unencrypted_);
175 }
176
177 const sync_pb::PasswordSpecificsData&
178 SyncManager::ExtraPasswordChangeRecordData::unencrypted() const {
179 return unencrypted_;
180 }
181
182 ////////////////////////////////////////////////////////////////////////// 113 //////////////////////////////////////////////////////////////////////////
183 // SyncManager's implementation: SyncManager::SyncInternal 114 // SyncManager's implementation: SyncManager::SyncInternal
184 class SyncManager::SyncInternal 115 class SyncManager::SyncInternal
185 : public net::NetworkChangeNotifier::IPAddressObserver, 116 : public net::NetworkChangeNotifier::IPAddressObserver,
186 public sync_notifier::SyncNotifierObserver, 117 public sync_notifier::SyncNotifierObserver,
187 public JsBackend, 118 public JsBackend,
188 public SyncEngineEventListener, 119 public SyncEngineEventListener,
189 public ServerConnectionEventListener, 120 public ServerConnectionEventListener,
190 public syncable::DirectoryChangeDelegate { 121 public syncable::DirectoryChangeDelegate {
191 static const int kDefaultNudgeDelayMilliseconds; 122 static const int kDefaultNudgeDelayMilliseconds;
(...skipping 1232 matching lines...) Expand 10 before | Expand all | Expand 10 after
1424 // This is the last chance for read to occur in the WriteTransaction 1355 // This is the last chance for read to occur in the WriteTransaction
1425 // that's closing. This special ReadTransaction will not close the 1356 // that's closing. This special ReadTransaction will not close the
1426 // underlying transaction. 1357 // underlying transaction.
1427 ReadTransaction read_trans(GetUserShare(), trans); 1358 ReadTransaction read_trans(GetUserShare(), trans);
1428 1359
1429 syncable::ModelTypeBitSet models_with_changes; 1360 syncable::ModelTypeBitSet models_with_changes;
1430 for (int i = 0; i < syncable::MODEL_TYPE_COUNT; ++i) { 1361 for (int i = 0; i < syncable::MODEL_TYPE_COUNT; ++i) {
1431 if (change_buffers_[i].IsEmpty()) 1362 if (change_buffers_[i].IsEmpty())
1432 continue; 1363 continue;
1433 1364
1434 vector<ChangeRecord> ordered_changes; 1365 ImmutableChangeRecordList ordered_changes =
1435 change_buffers_[i].GetAllChangesInTreeOrder(&read_trans, &ordered_changes); 1366 change_buffers_[i].GetAllChangesInTreeOrder(&read_trans);
1436 if (!ordered_changes.empty()) { 1367 if (!ordered_changes.Get().empty()) {
1437 ObserverList<SyncManager::Observer> temp_obs_list; 1368 ObserverList<SyncManager::Observer> temp_obs_list;
1438 CopyObservers(&temp_obs_list); 1369 CopyObservers(&temp_obs_list);
1439 FOR_EACH_OBSERVER(SyncManager::Observer, temp_obs_list, 1370 FOR_EACH_OBSERVER(SyncManager::Observer, temp_obs_list,
1440 OnChangesApplied(syncable::ModelTypeFromInt(i), &read_trans, 1371 OnChangesApplied(syncable::ModelTypeFromInt(i),
1441 &ordered_changes[0], ordered_changes.size())); 1372 &read_trans, ordered_changes));
1442 models_with_changes.set(i, true); 1373 models_with_changes.set(i, true);
1443 } 1374 }
1444 change_buffers_[i].Clear(); 1375 change_buffers_[i].Clear();
1445 } 1376 }
1446 return models_with_changes; 1377 return models_with_changes;
1447 } 1378 }
1448 1379
1449 void SyncManager::SyncInternal::HandleCalculateChangesChangeEventFromSyncApi( 1380 void SyncManager::SyncInternal::HandleCalculateChangesChangeEventFromSyncApi(
1450 const EntryKernelMutationMap& mutations, 1381 const EntryKernelMutationMap& mutations,
1451 syncable::BaseTransaction* trans) { 1382 syncable::BaseTransaction* trans) {
(...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after
2147 2078
2148 for (syncable::ModelTypeSet::const_iterator i = types.begin(); 2079 for (syncable::ModelTypeSet::const_iterator i = types.begin();
2149 i != types.end(); ++i) { 2080 i != types.end(); ++i) {
2150 if (!lookup->initial_sync_ended_for_type(*i)) 2081 if (!lookup->initial_sync_ended_for_type(*i))
2151 return false; 2082 return false;
2152 } 2083 }
2153 return true; 2084 return true;
2154 } 2085 }
2155 2086
2156 } // namespace sync_api 2087 } // namespace sync_api
OLDNEW
« no previous file with comments | « chrome/browser/sync/internal_api/sync_manager.h ('k') | chrome/browser/sync/internal_api/syncapi_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698