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

Side by Side Diff: chromeos/dbus/fake_bluetooth_profile_manager_client.cc

Issue 851123002: Manage profiles in BluetoothAdapter on ChromeOS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix profile memory leaks when adapter is gone Created 5 years, 10 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
« no previous file with comments | « no previous file | chromeos/dbus/fake_bluetooth_profile_service_provider.h » ('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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "chromeos/dbus/fake_bluetooth_profile_manager_client.h" 5 #include "chromeos/dbus/fake_bluetooth_profile_manager_client.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/message_loop/message_loop.h"
12 #include "chromeos/dbus/fake_bluetooth_profile_service_provider.h" 13 #include "chromeos/dbus/fake_bluetooth_profile_service_provider.h"
13 #include "dbus/bus.h" 14 #include "dbus/bus.h"
14 #include "dbus/message.h" 15 #include "dbus/message.h"
15 #include "dbus/object_path.h" 16 #include "dbus/object_path.h"
16 #include "dbus/object_proxy.h" 17 #include "dbus/object_proxy.h"
17 #include "third_party/cros_system_api/dbus/service_constants.h" 18 #include "third_party/cros_system_api/dbus/service_constants.h"
18 19
19 namespace chromeos { 20 namespace chromeos {
20 21
21 const char FakeBluetoothProfileManagerClient::kL2capUuid[] = 22 const char FakeBluetoothProfileManagerClient::kL2capUuid[] =
(...skipping 24 matching lines...) Expand all
46 if (iter == service_provider_map_.end()) { 47 if (iter == service_provider_map_.end()) {
47 error_callback.Run(bluetooth_profile_manager::kErrorInvalidArguments, 48 error_callback.Run(bluetooth_profile_manager::kErrorInvalidArguments,
48 "No profile created"); 49 "No profile created");
49 } else { 50 } else {
50 ProfileMap::iterator piter = profile_map_.find(uuid); 51 ProfileMap::iterator piter = profile_map_.find(uuid);
51 if (piter != profile_map_.end()) { 52 if (piter != profile_map_.end()) {
52 error_callback.Run(bluetooth_profile_manager::kErrorAlreadyExists, 53 error_callback.Run(bluetooth_profile_manager::kErrorAlreadyExists,
53 "Profile already registered"); 54 "Profile already registered");
54 } else { 55 } else {
55 profile_map_[uuid] = profile_path; 56 profile_map_[uuid] = profile_path;
56 callback.Run(); 57 base::MessageLoop::current()->PostTask(FROM_HERE, callback);
57 } 58 }
58 } 59 }
59 } 60 }
60 61
61 void FakeBluetoothProfileManagerClient::UnregisterProfile( 62 void FakeBluetoothProfileManagerClient::UnregisterProfile(
62 const dbus::ObjectPath& profile_path, 63 const dbus::ObjectPath& profile_path,
63 const base::Closure& callback, 64 const base::Closure& callback,
64 const ErrorCallback& error_callback) { 65 const ErrorCallback& error_callback) {
65 VLOG(1) << "UnregisterProfile: " << profile_path.value(); 66 VLOG(1) << "UnregisterProfile: " << profile_path.value();
66 67
67 ServiceProviderMap::iterator iter = service_provider_map_.find(profile_path); 68 ServiceProviderMap::iterator iter = service_provider_map_.find(profile_path);
68 if (iter == service_provider_map_.end()) { 69 if (iter == service_provider_map_.end()) {
69 error_callback.Run(bluetooth_profile_manager::kErrorInvalidArguments, 70 error_callback.Run(bluetooth_profile_manager::kErrorInvalidArguments,
70 "Profile not registered"); 71 "Profile not registered");
71 } else { 72 } else {
72 for (ProfileMap::iterator piter = profile_map_.begin(); 73 for (ProfileMap::iterator piter = profile_map_.begin();
73 piter != profile_map_.end(); ++piter) { 74 piter != profile_map_.end(); ++piter) {
74 if (piter->second == profile_path) { 75 if (piter->second == profile_path) {
75 profile_map_.erase(piter); 76 profile_map_.erase(piter);
76 break; 77 break;
77 } 78 }
78 } 79 }
79 80
80 callback.Run(); 81 base::MessageLoop::current()->PostTask(FROM_HERE, callback);
81 } 82 }
82 } 83 }
83 84
84 void FakeBluetoothProfileManagerClient::RegisterProfileServiceProvider( 85 void FakeBluetoothProfileManagerClient::RegisterProfileServiceProvider(
85 FakeBluetoothProfileServiceProvider* service_provider) { 86 FakeBluetoothProfileServiceProvider* service_provider) {
86 service_provider_map_[service_provider->object_path_] = service_provider; 87 service_provider_map_[service_provider->object_path_] = service_provider;
87 } 88 }
88 89
89 void FakeBluetoothProfileManagerClient::UnregisterProfileServiceProvider( 90 void FakeBluetoothProfileManagerClient::UnregisterProfileServiceProvider(
90 FakeBluetoothProfileServiceProvider* service_provider) { 91 FakeBluetoothProfileServiceProvider* service_provider) {
91 ServiceProviderMap::iterator iter = 92 ServiceProviderMap::iterator iter =
92 service_provider_map_.find(service_provider->object_path_); 93 service_provider_map_.find(service_provider->object_path_);
93 if (iter != service_provider_map_.end() && iter->second == service_provider) 94 if (iter != service_provider_map_.end() && iter->second == service_provider)
94 service_provider_map_.erase(iter); 95 service_provider_map_.erase(iter);
95 } 96 }
96 97
97 FakeBluetoothProfileServiceProvider* 98 FakeBluetoothProfileServiceProvider*
98 FakeBluetoothProfileManagerClient::GetProfileServiceProvider( 99 FakeBluetoothProfileManagerClient::GetProfileServiceProvider(
99 const std::string& uuid) { 100 const std::string& uuid) {
100 ProfileMap::iterator iter = profile_map_.find(uuid); 101 ProfileMap::iterator iter = profile_map_.find(uuid);
101 if (iter == profile_map_.end()) 102 if (iter == profile_map_.end())
102 return NULL; 103 return NULL;
103 return service_provider_map_[iter->second]; 104 return service_provider_map_[iter->second];
104 } 105 }
105 106
106 } // namespace chromeos 107 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | chromeos/dbus/fake_bluetooth_profile_service_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698