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

Side by Side Diff: chrome/browser/android/data_usage/external_data_use_observer.cc

Issue 2158913002: Make DataUseTabModel and DataUseMatcher more independent (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: minor fix Created 4 years, 5 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
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 #include "chrome/browser/android/data_usage/external_data_use_observer.h" 5 #include "chrome/browser/android/data_usage/external_data_use_observer.h"
6 6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
7 #include "base/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
8 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
9 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
10 #include "chrome/browser/android/data_usage/data_use_tab_model.h" 12 #include "chrome/browser/android/data_usage/data_use_tab_model.h"
11 #include "chrome/browser/android/data_usage/external_data_use_observer_bridge.h" 13 #include "chrome/browser/android/data_usage/external_data_use_observer_bridge.h"
12 #include "chrome/browser/android/data_usage/external_data_use_reporter.h" 14 #include "chrome/browser/android/data_usage/external_data_use_reporter.h"
13 #include "components/data_usage/core/data_use.h" 15 #include "components/data_usage/core/data_use.h"
14 #include "components/variations/variations_associated_data.h" 16 #include "components/variations/variations_associated_data.h"
15 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
16 18
(...skipping 27 matching lines...) Expand all
44 // static 46 // static
45 const char ExternalDataUseObserver::kExternalDataUseObserverFieldTrial[] = 47 const char ExternalDataUseObserver::kExternalDataUseObserverFieldTrial[] =
46 "ExternalDataUseObserver"; 48 "ExternalDataUseObserver";
47 49
48 ExternalDataUseObserver::ExternalDataUseObserver( 50 ExternalDataUseObserver::ExternalDataUseObserver(
49 data_usage::DataUseAggregator* data_use_aggregator, 51 data_usage::DataUseAggregator* data_use_aggregator,
50 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, 52 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner,
51 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner) 53 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner)
52 : data_use_aggregator_(data_use_aggregator), 54 : data_use_aggregator_(data_use_aggregator),
53 external_data_use_observer_bridge_(new ExternalDataUseObserverBridge()), 55 external_data_use_observer_bridge_(new ExternalDataUseObserverBridge()),
54 data_use_tab_model_(new DataUseTabModel()), 56 // It is okay to use base::Unretained for the callbacks, since
57 // |external_data_use_observer_bridge_| is owned by |this|, and is
58 // destroyed on UI thread after |this| and |data_use_tab_model_| are
59 // destroyed.
60 data_use_tab_model_(new DataUseTabModel(
61 base::Bind(&ExternalDataUseObserverBridge::FetchMatchingRules,
62 base::Unretained(external_data_use_observer_bridge_)),
63 base::Bind(
64 &ExternalDataUseObserverBridge::ShouldRegisterAsDataUseObserver,
65 base::Unretained(external_data_use_observer_bridge_)))),
55 external_data_use_reporter_( 66 external_data_use_reporter_(
56 new ExternalDataUseReporter(kExternalDataUseObserverFieldTrial, 67 new ExternalDataUseReporter(kExternalDataUseObserverFieldTrial,
57 data_use_tab_model_, 68 data_use_tab_model_,
58 external_data_use_observer_bridge_)), 69 external_data_use_observer_bridge_)),
59 ui_task_runner_(ui_task_runner), 70 ui_task_runner_(ui_task_runner),
60 last_matching_rules_fetch_time_(base::TimeTicks::Now()), 71 last_matching_rules_fetch_time_(base::TimeTicks::Now()),
61 fetch_matching_rules_duration_( 72 fetch_matching_rules_duration_(
62 base::TimeDelta::FromSeconds(GetFetchMatchingRulesDurationSeconds())), 73 base::TimeDelta::FromSeconds(GetFetchMatchingRulesDurationSeconds())),
63 registered_as_data_use_observer_(false), 74 registered_as_data_use_observer_(false),
64 weak_factory_(this) { 75 weak_factory_(this) {
65 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 76 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
66 DCHECK(data_use_aggregator_); 77 DCHECK(data_use_aggregator_);
67 DCHECK(io_task_runner); 78 DCHECK(io_task_runner);
68 DCHECK(ui_task_runner_); 79 DCHECK(ui_task_runner_);
69 80
70 // Initialize the ExternalDataUseReporter object. It is okay to use 81 // Initialize the ExternalDataUseReporter object. It is okay to use
71 // base::Unretained here since |external_data_use_reporter_| is owned by 82 // base::Unretained here since |external_data_use_reporter_| is owned by
72 // |this|, and is destroyed on UI thread when |this| is destroyed. 83 // |this|, and is destroyed on UI thread when |this| is destroyed.
73 ui_task_runner_->PostTask( 84 ui_task_runner_->PostTask(
74 FROM_HERE, base::Bind(&ExternalDataUseReporter::InitOnUIThread, 85 FROM_HERE, base::Bind(&ExternalDataUseReporter::InitOnUIThread,
75 base::Unretained(external_data_use_reporter_))); 86 base::Unretained(external_data_use_reporter_)));
76 87
77 ui_task_runner_->PostTask(FROM_HERE,
78 base::Bind(&DataUseTabModel::InitOnUIThread,
79 base::Unretained(data_use_tab_model_),
80 external_data_use_observer_bridge_));
81
82 // Initialize the ExternalDataUseObserverBridge object. It is okay to use 88 // Initialize the ExternalDataUseObserverBridge object. It is okay to use
83 // base::Unretained here since |external_data_use_observer_bridge_| is owned 89 // base::Unretained here since |external_data_use_observer_bridge_| is owned
84 // by |this|, and is destroyed on UI thread when |this| is destroyed. 90 // by |this|, and is destroyed on UI thread when |this| is destroyed.
85 ui_task_runner_->PostTask( 91 ui_task_runner_->PostTask(
86 FROM_HERE, 92 FROM_HERE,
87 base::Bind(&ExternalDataUseObserverBridge::Init, 93 base::Bind(&ExternalDataUseObserverBridge::Init,
88 base::Unretained(external_data_use_observer_bridge_), 94 base::Unretained(external_data_use_observer_bridge_),
89 io_task_runner, GetWeakPtr(), data_use_tab_model_)); 95 io_task_runner, GetWeakPtr(), data_use_tab_model_));
90 } 96 }
91 97
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 } 189 }
184 190
185 DataUseTabModel* ExternalDataUseObserver::GetDataUseTabModel() const { 191 DataUseTabModel* ExternalDataUseObserver::GetDataUseTabModel() const {
186 DCHECK(thread_checker_.CalledOnValidThread()); 192 DCHECK(thread_checker_.CalledOnValidThread());
187 return data_use_tab_model_; 193 return data_use_tab_model_;
188 } 194 }
189 195
190 } // namespace android 196 } // namespace android
191 197
192 } // namespace chrome 198 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698