OLD | NEW |
---|---|
(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/net/blimp_connection_details.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/logging.h" | |
9 #include "base/threading/thread.h" | |
10 | |
11 namespace blimp { | |
12 | |
13 BlimpConnectionDetails::BlimpConnectionDetails( | |
14 const scoped_refptr<base::TaskRunner>& main_thread_task_runner, | |
15 const scoped_refptr<base::TaskRunner>& io_thread_task_runner) | |
16 : debug_info_enabled_(false), | |
17 bytes_received_(0), | |
18 bytes_sent_(0), | |
19 commits_(0), | |
20 main_thread_task_runner_(main_thread_task_runner), | |
21 io_thread_task_runner_(io_thread_task_runner) {} | |
Khushal
2016/05/18 00:23:00
DCHECK that this is created on the correct thread.
| |
22 | |
23 BlimpConnectionDetails::~BlimpConnectionDetails() {} | |
Khushal
2016/05/18 00:23:00
ditto for the dtor.
| |
24 | |
25 void BlimpConnectionDetails::EnableDebugInfo(bool enable) { | |
Khushal
2016/05/18 00:23:00
Since this class is used on multiple threads, plea
| |
26 debug_info_enabled_ = enable; | |
27 } | |
28 | |
29 void BlimpConnectionDetails::OnPacketReceived(int bytes) { | |
30 bytes_received_ += bytes; | |
31 if (debug_info_enabled_) { | |
32 main_thread_task_runner_->PostTask( | |
33 FROM_HERE, | |
34 base::Bind(&NetworkActivityObserver::UpdateDebugInfo, observer_, | |
35 bytes_received_, bytes_sent_, commits_)); | |
36 } | |
37 } | |
38 | |
39 void BlimpConnectionDetails::OnPacketSent(int bytes) { | |
40 bytes_sent_ += bytes; | |
41 if (debug_info_enabled_) { | |
42 main_thread_task_runner_->PostTask( | |
43 FROM_HERE, | |
44 base::Bind(&NetworkActivityObserver::UpdateDebugInfo, observer_, | |
45 bytes_received_, bytes_sent_, commits_)); | |
46 } | |
47 } | |
48 | |
49 void BlimpConnectionDetails::OnCommit() { | |
50 commits_++; | |
51 if (debug_info_enabled_) { | |
52 main_thread_task_runner_->PostTask( | |
53 FROM_HERE, | |
54 base::Bind(&NetworkActivityObserver::UpdateDebugInfo, observer_, | |
55 bytes_received_, bytes_sent_, commits_)); | |
56 } | |
57 } | |
58 | |
59 void BlimpConnectionDetails::ResetStats() { | |
60 io_thread_task_runner_->PostTask( | |
61 FROM_HERE, base::Bind(&BlimpConnectionDetails::ResetStatsOnIOThread, | |
62 base::Unretained(this))); | |
Khushal
2016/05/18 00:23:01
Are you sure its safe to use Unretained here? Can
shaktisahu
2016/05/19 21:39:18
Acknowledged.
| |
63 commits_ = 0; | |
64 } | |
65 | |
66 void BlimpConnectionDetails::ResetStatsOnIOThread() { | |
67 bytes_received_ = 0; | |
68 bytes_sent_ = 0; | |
69 } | |
70 | |
71 } // namespace blimp | |
OLD | NEW |