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

Side by Side Diff: components/data_usage/core/data_use_aggregator.h

Issue 1456793003: Re-use callback objects in the DataUseAggregator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed WeakPtr threading issue. Created 5 years, 1 month 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 | « no previous file | components/data_usage/core/data_use_aggregator.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #ifndef COMPONENTS_DATA_USAGE_CORE_DATA_USE_AGGREGATOR_H_ 5 #ifndef COMPONENTS_DATA_USAGE_CORE_DATA_USE_AGGREGATOR_H_
6 #define COMPONENTS_DATA_USAGE_CORE_DATA_USE_AGGREGATOR_H_ 6 #define COMPONENTS_DATA_USAGE_CORE_DATA_USE_AGGREGATOR_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "base/observer_list.h" 16 #include "base/observer_list.h"
17 #include "base/threading/thread_checker.h" 17 #include "base/threading/thread_checker.h"
18 #include "components/data_usage/core/data_use_amortizer.h"
19 #include "components/data_usage/core/data_use_annotator.h"
18 #include "net/base/network_change_notifier.h" 20 #include "net/base/network_change_notifier.h"
19 21
20 namespace net { 22 namespace net {
21 class URLRequest; 23 class URLRequest;
22 } 24 }
23 25
24 namespace data_usage { 26 namespace data_usage {
25 27
26 class DataUseAmortizer;
27 class DataUseAnnotator;
28 struct DataUse; 28 struct DataUse;
29 29
30 // Class that collects and aggregates network usage, reporting the usage to 30 // Class that collects and aggregates network usage, reporting the usage to
31 // observers. Should only be used on the IO thread. 31 // observers. Should only be used on the IO thread.
32 class DataUseAggregator 32 class DataUseAggregator
33 : public net::NetworkChangeNotifier::ConnectionTypeObserver { 33 : public net::NetworkChangeNotifier::ConnectionTypeObserver {
34 public: 34 public:
35 class Observer { 35 class Observer {
36 public: 36 public:
37 virtual ~Observer() {} 37 virtual ~Observer() {}
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 base::ObserverList<Observer> observer_list_; 89 base::ObserverList<Observer> observer_list_;
90 90
91 // Current connection type as notified by NetworkChangeNotifier. 91 // Current connection type as notified by NetworkChangeNotifier.
92 net::NetworkChangeNotifier::ConnectionType connection_type_; 92 net::NetworkChangeNotifier::ConnectionType connection_type_;
93 93
94 // MCC+MNC (mobile country code + mobile network code) of the current SIM 94 // MCC+MNC (mobile country code + mobile network code) of the current SIM
95 // provider. Set to empty string if SIM is not present. |mcc_mnc_| is set 95 // provider. Set to empty string if SIM is not present. |mcc_mnc_| is set
96 // even if the current active network is not a cellular network. 96 // even if the current active network is not a cellular network.
97 std::string mcc_mnc_; 97 std::string mcc_mnc_;
98 98
99 // As an optimization, re-use the same callbacks to avoid creating and
100 // allocating a new Callback object for each call into the |annotator_| or
101 // |amortizer_|. These callbacks are lazily initialized.
102 DataUseAnnotator::DataUseConsumerCallback annotation_callback_;
103 DataUseAmortizer::AmortizationCompleteCallback amortization_callback_;
104
99 base::WeakPtrFactory<DataUseAggregator> weak_ptr_factory_; 105 base::WeakPtrFactory<DataUseAggregator> weak_ptr_factory_;
100 106
101 DISALLOW_COPY_AND_ASSIGN(DataUseAggregator); 107 DISALLOW_COPY_AND_ASSIGN(DataUseAggregator);
102 }; 108 };
103 109
104 } // namespace data_usage 110 } // namespace data_usage
105 111
106 #endif // COMPONENTS_DATA_USAGE_CORE_DATA_USE_AGGREGATOR_H_ 112 #endif // COMPONENTS_DATA_USAGE_CORE_DATA_USE_AGGREGATOR_H_
OLDNEW
« no previous file with comments | « no previous file | components/data_usage/core/data_use_aggregator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698