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

Side by Side Diff: components/physical_web/data_source/physical_web_data_source_impl.cc

Issue 2765713002: Associate a scan mode with Physical Web listeners (Closed)
Patch Set: Remove logging include Created 3 years, 9 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 2016 The Chromium Authors. All rights reserved. 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 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 "base/observer_list.h" 5 #include "base/observer_list.h"
6 #include "components/physical_web/data_source/physical_web_data_source.h" 6 #include "components/physical_web/data_source/physical_web_data_source.h"
7 #include "components/physical_web/data_source/physical_web_data_source_impl.h" 7 #include "components/physical_web/data_source/physical_web_data_source_impl.h"
8 #include "components/physical_web/data_source/physical_web_listener.h" 8 #include "components/physical_web/data_source/physical_web_listener.h"
9 9
10 namespace physical_web { 10 namespace physical_web {
11 11
12 PhysicalWebDataSourceImpl::PhysicalWebDataSourceImpl() {} 12 PhysicalWebDataSourceImpl::PhysicalWebDataSourceImpl() {}
13 13
14 PhysicalWebDataSourceImpl::~PhysicalWebDataSourceImpl() {} 14 PhysicalWebDataSourceImpl::~PhysicalWebDataSourceImpl() {}
15 15
16 void PhysicalWebDataSourceImpl::RegisterListener( 16 void PhysicalWebDataSourceImpl::RegisterListener(
17 PhysicalWebListener* physical_web_listener) { 17 PhysicalWebListener* physical_web_listener, ScanMode scan_mode) {
18 observer_list_.AddObserver(physical_web_listener); 18 if (!observer_list_.HasObserver(physical_web_listener)) {
19 observer_list_.AddObserver(physical_web_listener);
20 }
21 scan_modes_[physical_web_listener] = scan_mode;
19 } 22 }
20 23
21 void PhysicalWebDataSourceImpl::UnregisterListener( 24 void PhysicalWebDataSourceImpl::UnregisterListener(
22 PhysicalWebListener* physical_web_listener) { 25 PhysicalWebListener* physical_web_listener) {
26 if (!observer_list_.HasObserver(physical_web_listener)) return;
27
23 observer_list_.RemoveObserver(physical_web_listener); 28 observer_list_.RemoveObserver(physical_web_listener);
29 scan_modes_.erase(scan_modes_.find(physical_web_listener));
vitaliii 2017/03/24 09:41:49 Nit: unordered_map.erase seems to accept key type
24 } 30 }
25 31
26 void PhysicalWebDataSourceImpl::NotifyOnFound(const GURL& url) { 32 void PhysicalWebDataSourceImpl::NotifyOnFound(const GURL& url) {
27 for (PhysicalWebListener& observer : observer_list_) 33 for (PhysicalWebListener& observer : observer_list_)
28 observer.OnFound(url); 34 observer.OnFound(url);
29 } 35 }
30 36
31 void PhysicalWebDataSourceImpl::NotifyOnLost(const GURL& url) { 37 void PhysicalWebDataSourceImpl::NotifyOnLost(const GURL& url) {
32 for (PhysicalWebListener& observer : observer_list_) 38 for (PhysicalWebListener& observer : observer_list_)
33 observer.OnLost(url); 39 observer.OnLost(url);
34 } 40 }
35 41
36 void PhysicalWebDataSourceImpl::NotifyOnDistanceChanged( 42 void PhysicalWebDataSourceImpl::NotifyOnDistanceChanged(
37 const GURL& url, 43 const GURL& url,
38 double distance_estimate) { 44 double distance_estimate) {
39 for (PhysicalWebListener& observer : observer_list_) 45 for (PhysicalWebListener& observer : observer_list_)
40 observer.OnDistanceChanged(url, distance_estimate); 46 observer.OnDistanceChanged(url, distance_estimate);
41 } 47 }
42 48
43 } // namespace physical_web 49 } // namespace physical_web
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698