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

Side by Side Diff: blimp/helium/update_scheduler.cc

Issue 2602103002: Delete blimp/helium and remove references to it from dependent targets (Closed)
Patch Set: . Created 3 years, 11 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
« no previous file with comments | « blimp/helium/update_scheduler.h ('k') | blimp/helium/update_scheduler_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 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 "blimp/helium/update_scheduler.h"
6
7 #include <map>
8 #include <set>
9
10 #include "base/memory/ptr_util.h"
11 #include "blimp/helium/object_sync_state.h"
12 #include "blimp/helium/syncable.h"
13
14 namespace blimp {
15 namespace helium {
16 namespace {
17
18 class UpdateSchedulerImpl : public UpdateScheduler {
19 public:
20 UpdateSchedulerImpl() = default;
21 ~UpdateSchedulerImpl() override = default;
22
23 // UpdateScheduler implementation.
24 void AddObject(HeliumObjectId object_id, ObjectSyncState* object) override;
25 void RemoveObject(HeliumObjectId object_id) override;
26 bool HasMessageReady() const override;
27 void PrepareMessage(MessagePreparedCallback callback) override;
28 void OnLocalUpdate(HeliumObjectId object_id) override;
29 void OnNeedsAck(HeliumObjectId object_id) override;
30 void OnStreamConnected(StreamPump* pump) override;
31
32 private:
33 StreamPump* pump_ = nullptr;
34
35 // TODO(steimel): replace with to-be-created ObjectDirectory.
36 std::map<HeliumObjectId, ObjectSyncState*> objects_;
37 std::set<HeliumObjectId> dirty_;
38 std::set<HeliumObjectId> needs_ack_;
39
40 DISALLOW_COPY_AND_ASSIGN(UpdateSchedulerImpl);
41 };
42
43 void UpdateSchedulerImpl::AddObject(HeliumObjectId object_id,
44 ObjectSyncState* object_sync_state) {
45 DCHECK(object_sync_state);
46
47 objects_[object_id] = object_sync_state;
48 }
49
50 void UpdateSchedulerImpl::RemoveObject(HeliumObjectId object_id) {
51 auto object_iterator = objects_.find(object_id);
52 DCHECK(object_iterator != objects_.end());
53 object_iterator->second->OnStreamDisconnected();
54
55 objects_.erase(object_id);
56 dirty_.erase(object_id);
57 needs_ack_.erase(object_id);
58 }
59
60 bool UpdateSchedulerImpl::HasMessageReady() const {
61 return !dirty_.empty() || !needs_ack_.empty();
62 }
63
64 void UpdateSchedulerImpl::PrepareMessage(MessagePreparedCallback callback) {
65 if (!dirty_.empty()) {
66 HeliumObjectId object_id = *(dirty_.begin());
67 dirty_.erase(object_id);
68 needs_ack_.erase(object_id);
69
70 auto object_iterator = objects_.find(object_id);
71 DCHECK(object_iterator != objects_.end());
72 object_iterator->second->PrepareChangesetMessage(std::move(callback));
73 } else if (!needs_ack_.empty()) {
74 HeliumObjectId object_id = *(needs_ack_.begin());
75 needs_ack_.erase(object_id);
76
77 auto object_iterator = objects_.find(object_id);
78 DCHECK(object_iterator != objects_.end());
79 object_iterator->second->PrepareAckMessage(std::move(callback));
80 } else {
81 NOTREACHED();
82 }
83 }
84
85 void UpdateSchedulerImpl::OnLocalUpdate(HeliumObjectId object_id) {
86 DCHECK_EQ(1u, objects_.count(object_id));
87
88 dirty_.insert(object_id);
89 if (pump_) {
90 pump_->OnMessageAvailable();
91 }
92 }
93
94 void UpdateSchedulerImpl::OnNeedsAck(HeliumObjectId object_id) {
95 DCHECK_EQ(1u, objects_.count(object_id));
96
97 needs_ack_.insert(object_id);
98 if (pump_) {
99 pump_->OnMessageAvailable();
100 }
101 }
102
103 void UpdateSchedulerImpl::OnStreamConnected(StreamPump* pump) {
104 pump_ = pump;
105
106 for (auto object : objects_) {
107 object.second->OnStreamConnected(this);
108 }
109
110 pump_->OnMessageAvailable();
111 }
112
113 } // namespace
114
115 // static
116 std::unique_ptr<UpdateScheduler> UpdateScheduler::Create() {
117 return base::MakeUnique<UpdateSchedulerImpl>();
118 }
119
120 } // namespace helium
121 } // namespace blimp
OLDNEW
« no previous file with comments | « blimp/helium/update_scheduler.h ('k') | blimp/helium/update_scheduler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698