| OLD | NEW |
| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/containers/hash_tables.h" | 9 #include "base/containers/hash_tables.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 weak_factory_(this) { | 155 weak_factory_(this) { |
| 156 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 156 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 157 DCHECK(data_use_aggregator_); | 157 DCHECK(data_use_aggregator_); |
| 158 DCHECK(io_task_runner); | 158 DCHECK(io_task_runner); |
| 159 DCHECK(ui_task_runner_); | 159 DCHECK(ui_task_runner_); |
| 160 DCHECK(last_data_report_submitted_ticks_.is_null()); | 160 DCHECK(last_data_report_submitted_ticks_.is_null()); |
| 161 | 161 |
| 162 ui_task_runner_->PostTask(FROM_HERE, | 162 ui_task_runner_->PostTask(FROM_HERE, |
| 163 base::Bind(&DataUseTabModel::InitOnUIThread, | 163 base::Bind(&DataUseTabModel::InitOnUIThread, |
| 164 base::Unretained(data_use_tab_model_), | 164 base::Unretained(data_use_tab_model_), |
| 165 io_task_runner, GetWeakPtr())); | 165 external_data_use_observer_bridge_)); |
| 166 | 166 |
| 167 // Initialize the ExternalDataUseObserverBridge object. Initialization will | 167 // Initialize the ExternalDataUseObserverBridge object. It is okay to use |
| 168 // also trigger the fetching of matching rules. It is okay to use | 168 // base::Unretained here since |external_data_use_observer_bridge_| is owned |
| 169 // base::Unretained here since |external_data_use_observer_bridge_| is | 169 // by |this|, and is destroyed on UI thread when |this| is destroyed. |
| 170 // owned by |this|, and is destroyed on UI thread when |this| is destroyed. | |
| 171 ui_task_runner_->PostTask( | 170 ui_task_runner_->PostTask( |
| 172 FROM_HERE, | 171 FROM_HERE, |
| 173 base::Bind(&ExternalDataUseObserverBridge::Init, | 172 base::Bind(&ExternalDataUseObserverBridge::Init, |
| 174 base::Unretained(external_data_use_observer_bridge_), | 173 base::Unretained(external_data_use_observer_bridge_), |
| 175 io_task_runner, GetWeakPtr(), data_use_tab_model_)); | 174 io_task_runner, GetWeakPtr(), data_use_tab_model_)); |
| 176 } | 175 } |
| 177 | 176 |
| 178 ExternalDataUseObserver::~ExternalDataUseObserver() { | 177 ExternalDataUseObserver::~ExternalDataUseObserver() { |
| 179 DCHECK(thread_checker_.CalledOnValidThread()); | 178 DCHECK(thread_checker_.CalledOnValidThread()); |
| 180 | 179 |
| 181 if (registered_as_data_use_observer_) | 180 if (registered_as_data_use_observer_) |
| 182 data_use_aggregator_->RemoveObserver(this); | 181 data_use_aggregator_->RemoveObserver(this); |
| 183 | 182 |
| 183 // Delete |data_use_tab_model_| on the UI thread. |data_use_tab_model_| should |
| 184 // be deleted before |external_data_use_observer_bridge_|. |
| 185 if (!ui_task_runner_->DeleteSoon(FROM_HERE, data_use_tab_model_)) { |
| 186 NOTIMPLEMENTED() << " DataUseTabModel was not deleted successfully"; |
| 187 } |
| 188 |
| 184 // Delete |external_data_use_observer_bridge_| on the UI thread. | 189 // Delete |external_data_use_observer_bridge_| on the UI thread. |
| 185 if (!ui_task_runner_->DeleteSoon(FROM_HERE, | 190 if (!ui_task_runner_->DeleteSoon(FROM_HERE, |
| 186 external_data_use_observer_bridge_)) { | 191 external_data_use_observer_bridge_)) { |
| 187 NOTIMPLEMENTED() | 192 NOTIMPLEMENTED() |
| 188 << " ExternalDataUseObserverBridge was not deleted successfully"; | 193 << " ExternalDataUseObserverBridge was not deleted successfully"; |
| 189 } | 194 } |
| 190 | |
| 191 // Delete |data_use_tab_model_| on the UI thread. | |
| 192 if (!ui_task_runner_->DeleteSoon(FROM_HERE, data_use_tab_model_)) { | |
| 193 NOTIMPLEMENTED() << " DataUseTabModel was not deleted successfully"; | |
| 194 } | |
| 195 } | 195 } |
| 196 | 196 |
| 197 void ExternalDataUseObserver::OnReportDataUseDone(bool success) { | 197 void ExternalDataUseObserver::OnReportDataUseDone(bool success) { |
| 198 DCHECK(thread_checker_.CalledOnValidThread()); | 198 DCHECK(thread_checker_.CalledOnValidThread()); |
| 199 DCHECK(!last_data_report_submitted_ticks_.is_null()); | 199 DCHECK(!last_data_report_submitted_ticks_.is_null()); |
| 200 | 200 |
| 201 if (success) { | 201 if (success) { |
| 202 RecordDataUsageReportSubmission(DATAUSAGE_REPORT_SUBMISSION_SUCCESSFUL, | 202 RecordDataUsageReportSubmission(DATAUSAGE_REPORT_SUBMISSION_SUCCESSFUL, |
| 203 pending_report_bytes_); | 203 pending_report_bytes_); |
| 204 } else { | 204 } else { |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 size_t hash = 1; | 441 size_t hash = 1; |
| 442 hash = hash * 23 + hash_function(k.label); | 442 hash = hash * 23 + hash_function(k.label); |
| 443 hash = hash * 43 + k.connection_type; | 443 hash = hash * 43 + k.connection_type; |
| 444 hash = hash * 83 + hash_function(k.mcc_mnc); | 444 hash = hash * 83 + hash_function(k.mcc_mnc); |
| 445 return hash; | 445 return hash; |
| 446 } | 446 } |
| 447 | 447 |
| 448 } // namespace android | 448 } // namespace android |
| 449 | 449 |
| 450 } // namespace chrome | 450 } // namespace chrome |
| OLD | NEW |