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

Side by Side Diff: chrome/browser/sync/sessions/sync_session.cc

Issue 6182004: [SYNC] Refactor SyncSourceInfo and add support in chrome invalidation client ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Feedback Created 9 years, 10 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/sessions/sync_session.h" 5 #include "chrome/browser/sync/sessions/sync_session.h"
6 #include "chrome/browser/sync/syncable/directory_manager.h" 6 #include "chrome/browser/sync/syncable/directory_manager.h"
7 #include "chrome/browser/sync/syncable/model_type.h" 7 #include "chrome/browser/sync/syncable/model_type.h"
8 8
9 namespace browser_sync { 9 namespace browser_sync {
10 namespace sessions { 10 namespace sessions {
11 11
12 TypePayloadMap ModelTypeBitSetToTypePayloadMap(
13 const syncable::ModelTypeBitSet& types,
14 const std::string& payload) {
15 TypePayloadMap map;
16 for (size_t i = syncable::FIRST_REAL_MODEL_TYPE;
17 i < types.size(); ++i) {
18 if (types[i]) {
19 map[syncable::ModelTypeFromInt(i)] = payload;
20 }
21 }
22 return map;
23 }
24
25 TypePayloadMap RoutingInfoToTypePayloadMap(const ModelSafeRoutingInfo& routes,
26 const std::string& payload) {
27 TypePayloadMap map;
28 for (ModelSafeRoutingInfo::const_iterator i = routes.begin();
29 i != routes.end(); ++i) {
30 map[i->first] = payload;
31 }
32 return map;
33 }
34
35 void CoalescePayloads(TypePayloadMap* original,
36 const TypePayloadMap& update) {
37 for (TypePayloadMap::const_iterator i = update.begin();
38 i != update.end(); ++i) {
39 if (original->count(i->first) == 0) {
40 // If this datatype isn't already in our map, add it with whatever payload
41 // it has.
42 (*original)[i->first] = i->second;
43 } else if (i->second.length() > 0) {
44 // If this datatype is already in our map, we only overwrite the payload
45 // if the new one is non-empty.
46 (*original)[i->first] = i->second;
47 }
48 }
49 }
50
51 SyncSourceInfo::SyncSourceInfo()
52 : updates_source(sync_pb::GetUpdatesCallerInfo::UNKNOWN) {}
53
54 SyncSourceInfo::SyncSourceInfo(
55 const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource& u,
56 const TypePayloadMap& t)
57 : updates_source(u), types(t) {}
58
12 SyncSession::SyncSession(SyncSessionContext* context, Delegate* delegate, 59 SyncSession::SyncSession(SyncSessionContext* context, Delegate* delegate,
13 SyncSourceInfo source, 60 SyncSourceInfo source,
14 const ModelSafeRoutingInfo& routing_info, 61 const ModelSafeRoutingInfo& routing_info,
15 const std::vector<ModelSafeWorker*>& workers) 62 const std::vector<ModelSafeWorker*>& workers)
16 : context_(context), 63 : context_(context),
17 source_(source), 64 source_(source),
18 write_transaction_(NULL), 65 write_transaction_(NULL),
19 delegate_(delegate), 66 delegate_(delegate),
20 workers_(workers), 67 workers_(workers),
21 routing_info_(routing_info) { 68 routing_info_(routing_info) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 delegate_->IsSyncingCurrentlySilenced(), 102 delegate_->IsSyncingCurrentlySilenced(),
56 status_controller_->unsynced_handles().size(), 103 status_controller_->unsynced_handles().size(),
57 status_controller_->TotalNumConflictingItems(), 104 status_controller_->TotalNumConflictingItems(),
58 status_controller_->did_commit_items()); 105 status_controller_->did_commit_items());
59 } 106 }
60 107
61 SyncSourceInfo SyncSession::TestAndSetSource() { 108 SyncSourceInfo SyncSession::TestAndSetSource() {
62 SyncSourceInfo old_source = source_; 109 SyncSourceInfo old_source = source_;
63 source_ = SyncSourceInfo( 110 source_ = SyncSourceInfo(
64 sync_pb::GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION, 111 sync_pb::GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION,
65 source_.second); 112 source_.types);
66 return old_source; 113 return old_source;
67 } 114 }
68 115
69 bool SyncSession::HasMoreToSync() const { 116 bool SyncSession::HasMoreToSync() const {
70 const StatusController* status = status_controller_.get(); 117 const StatusController* status = status_controller_.get();
71 return ((status->commit_ids().size() < status->unsynced_handles().size()) && 118 return ((status->commit_ids().size() < status->unsynced_handles().size()) &&
72 status->syncer_status().num_successful_commits > 0) || 119 status->syncer_status().num_successful_commits > 0) ||
73 status->conflict_sets_built() || 120 status->conflict_sets_built() ||
74 status->conflicts_resolved(); 121 status->conflicts_resolved();
75 // Or, we have conflicting updates, but we're making progress on 122 // Or, we have conflicting updates, but we're making progress on
76 // resolving them... 123 // resolving them...
77 } 124 }
78 125
79 } // namespace sessions 126 } // namespace sessions
80 } // namespace browser_sync 127 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698