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

Unified Diff: components/data_usage/core/data_use_aggregator.cc

Issue 1421983002: Include tab IDs when reporting data use accounting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@data_use_scoped_vector
Patch Set: Created 5 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: components/data_usage/core/data_use_aggregator.cc
diff --git a/components/data_usage/core/data_use_aggregator.cc b/components/data_usage/core/data_use_aggregator.cc
index 39ba128ab345a4f394df6821ae7706ceb1b12a38..763b1dcd3920d74fa4e686b705819562b0c65d2b 100644
--- a/components/data_usage/core/data_use_aggregator.cc
+++ b/components/data_usage/core/data_use_aggregator.cc
@@ -4,8 +4,10 @@
#include "components/data_usage/core/data_use_aggregator.h"
+#include <sstream>
tbansal1 2015/10/26 22:24:30 why is sstream required?
sclittle 2015/10/26 23:56:01 <sstream> and <string> are just included right now
+#include <string>
+
#include "base/bind.h"
-#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/single_thread_task_runner.h"
#include "base/stl_util.h"
@@ -15,6 +17,39 @@
namespace data_usage {
+namespace {
+
+// Observer for debug logging.
+// TODO in this CL: Remove this before landing.
bengr 2015/10/27 00:01:47 Please do remove it.
sclittle 2015/10/28 22:30:45 Done.
+class LoggingObserver : public DataUseAggregator::Observer {
+ public:
+ LoggingObserver(DataUseAggregator* aggregator) : aggregator_(aggregator) {
+ DCHECK(aggregator_);
+ aggregator_->AddObserver(this);
+ }
+
+ ~LoggingObserver() override { aggregator_->RemoveObserver(this); }
+
+ void OnDataUse(
+ const std::vector<const DataUse*>& data_use_sequence) override {
+ std::ostringstream os;
+ for (const DataUse* data_use : data_use_sequence) {
+ os << "\n["
+ << "url=" << data_use->url << " rt=" << data_use->request_time
+ << " fp=" << data_use->first_party_for_cookies
+ << " tab_id=" << data_use->tab_id
+ << " ctype=" << data_use->connection_type
+ << " tx=" << data_use->tx_bytes << " rx=" << data_use->rx_bytes << "]";
+ }
+ LOG(WARNING) << "OnDataUse:" << os.str();
+ }
+
+ private:
+ DataUseAggregator* aggregator_;
+};
+
+} // namespace
+
DataUseAggregator::DataUseAggregator()
: off_the_record_tx_bytes_since_last_flush_(0),
off_the_record_rx_bytes_since_last_flush_(0),
@@ -33,24 +68,25 @@ void DataUseAggregator::RemoveObserver(Observer* observer) {
observer_list_.RemoveObserver(observer);
}
-void DataUseAggregator::ReportDataUse(const net::URLRequest& request,
- int32_t tab_id,
- int64_t tx_bytes,
- int64_t rx_bytes) {
+void DataUseAggregator::ReportDataUse(int64_t tx_bytes,
+ int64_t rx_bytes,
+ const GURL& url,
+ const base::Time& request_time,
+ const GURL& first_party_for_cookies,
+ int32_t tab_id) {
DCHECK(thread_checker_.CalledOnValidThread());
scoped_ptr<DataUse> data_use(new DataUse(
- request.url(), request.request_time(), request.first_party_for_cookies(),
- tab_id, net::NetworkChangeNotifier::GetConnectionType(), tx_bytes,
- rx_bytes));
+ url, request_time, first_party_for_cookies, tab_id,
+ net::NetworkChangeNotifier::GetConnectionType(), tx_bytes, rx_bytes));
// As an optimization, attempt to combine the newly reported data use with the
// most recent buffered data use, if the annotations on the data use are the
// same.
if (!buffered_data_use_.empty() &&
buffered_data_use_.back()->CanCombineWith(*data_use)) {
- buffered_data_use_.back()->tx_bytes += tx_bytes;
- buffered_data_use_.back()->rx_bytes += rx_bytes;
+ buffered_data_use_.back()->tx_bytes += data_use->tx_bytes;
+ buffered_data_use_.back()->rx_bytes += data_use->rx_bytes;
} else {
buffered_data_use_.push_back(data_use.Pass());
}
@@ -80,6 +116,9 @@ base::WeakPtr<DataUseAggregator> DataUseAggregator::GetWeakPtr() {
void DataUseAggregator::FlushBufferedDataUse() {
DCHECK(thread_checker_.CalledOnValidThread());
+ // TODO in this CL: Remove this debug logging observer.
bengr 2015/10/27 00:01:47 And this too.
sclittle 2015/10/28 22:30:45 Done.
+ LoggingObserver logging_observer(this);
+
// TODO(sclittle): Amortize data use on supported platforms before notifying
// observers.

Powered by Google App Engine
This is Rietveld 408576698