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

Side by Side Diff: dbus/test_service.h

Issue 1559873005: dbus: Use randomly generated string as a TestService's service name (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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 | « dbus/signal_sender_verification_unittest.cc ('k') | dbus/test_service.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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 DBUS_TEST_SERVICE_H_ 5 #ifndef DBUS_TEST_SERVICE_H_
6 #define DBUS_TEST_SERVICE_H_ 6 #define DBUS_TEST_SERVICE_H_
7 7
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/threading/thread.h" 10 #include "base/threading/thread.h"
(...skipping 22 matching lines...) Expand all
33 // Options for the test service. 33 // Options for the test service.
34 struct Options { 34 struct Options {
35 Options(); 35 Options();
36 ~Options(); 36 ~Options();
37 37
38 // NULL by default (i.e. don't use the D-Bus thread). 38 // NULL by default (i.e. don't use the D-Bus thread).
39 scoped_refptr<base::SequencedTaskRunner> dbus_task_runner; 39 scoped_refptr<base::SequencedTaskRunner> dbus_task_runner;
40 40
41 // Flags governing parameters of service ownership request. 41 // Flags governing parameters of service ownership request.
42 Bus::ServiceOwnershipOptions request_ownership_options; 42 Bus::ServiceOwnershipOptions request_ownership_options;
43
44 // Name of this service (randomly generated name will be used if empty).
45 std::string service_name;
43 }; 46 };
44 47
45 // The number of methods we'll export. 48 // The number of methods we'll export.
46 static const int kNumMethodsToExport; 49 static const int kNumMethodsToExport;
47 50
48 explicit TestService(const Options& options); 51 explicit TestService(const Options& options);
49 ~TestService() override; 52 ~TestService() override;
50 53
51 // Starts the service in a separate thread. 54 // Starts the service in a separate thread.
52 // Returns true if the thread is started successfully. 55 // Returns true if the thread is started successfully.
(...skipping 18 matching lines...) Expand all
71 74
72 // Request the ownership of a well-known name "TestService". 75 // Request the ownership of a well-known name "TestService".
73 // |callback| will be called with the result when an ownership request is 76 // |callback| will be called with the result when an ownership request is
74 // completed. 77 // completed.
75 void RequestOwnership(base::Callback<void(bool)> callback); 78 void RequestOwnership(base::Callback<void(bool)> callback);
76 79
77 // Release the ownership of the well-known name "TestService". 80 // Release the ownership of the well-known name "TestService".
78 // |callback| will be called when the ownership has been released. 81 // |callback| will be called when the ownership has been released.
79 void ReleaseOwnership(base::Closure callback); 82 void ReleaseOwnership(base::Closure callback);
80 83
84 // Returns the name of this service.
85 const std::string& service_name() const { return service_name_; }
86
81 // Returns whether this instance has the name ownership or not. 87 // Returns whether this instance has the name ownership or not.
82 bool has_ownership() const { return has_ownership_; } 88 bool has_ownership() const { return has_ownership_; }
83 89
84 private: 90 private:
85 // Helper function for SendTestSignal(). 91 // Helper function for SendTestSignal().
86 void SendTestSignalInternal(const std::string& message); 92 void SendTestSignalInternal(const std::string& message);
87 93
88 // Helper function for SendTestSignalFromRoot. 94 // Helper function for SendTestSignalFromRoot.
89 void SendTestSignalFromRootInternal(const std::string& message); 95 void SendTestSignalFromRootInternal(const std::string& message);
90 96
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 void OwnershipReleased( 198 void OwnershipReleased(
193 MethodCall* method_call, 199 MethodCall* method_call,
194 dbus::ExportedObject::ResponseSender response_sender); 200 dbus::ExportedObject::ResponseSender response_sender);
195 201
196 // Sends the action response after regaining the well-known name. 202 // Sends the action response after regaining the well-known name.
197 void OwnershipRegained( 203 void OwnershipRegained(
198 MethodCall* method_call, 204 MethodCall* method_call,
199 dbus::ExportedObject::ResponseSender response_sender, 205 dbus::ExportedObject::ResponseSender response_sender,
200 bool success); 206 bool success);
201 207
208 // Name of this service.
209 std::string service_name_;
210
202 // Options to use when requesting service ownership. 211 // Options to use when requesting service ownership.
203 Bus::ServiceOwnershipOptions request_ownership_options_; 212 Bus::ServiceOwnershipOptions request_ownership_options_;
204 213
205 scoped_refptr<base::SequencedTaskRunner> dbus_task_runner_; 214 scoped_refptr<base::SequencedTaskRunner> dbus_task_runner_;
206 base::WaitableEvent on_name_obtained_; 215 base::WaitableEvent on_name_obtained_;
207 // The number of methods actually exported. 216 // The number of methods actually exported.
208 int num_exported_methods_; 217 int num_exported_methods_;
209 218
210 // True if a PropertiesChanged signal for the "Name" property should be sent 219 // True if a PropertiesChanged signal for the "Name" property should be sent
211 // immediately following a call to GetManagedObjects. 220 // immediately following a call to GetManagedObjects.
212 bool send_immediate_properties_changed_; 221 bool send_immediate_properties_changed_;
213 222
214 // True iff this instance has successfully acquired the name ownership. 223 // True iff this instance has successfully acquired the name ownership.
215 bool has_ownership_; 224 bool has_ownership_;
216 225
217 scoped_refptr<Bus> bus_; 226 scoped_refptr<Bus> bus_;
218 ExportedObject* exported_object_; 227 ExportedObject* exported_object_;
219 ExportedObject* exported_object_manager_; 228 ExportedObject* exported_object_manager_;
220 }; 229 };
221 230
222 } // namespace dbus 231 } // namespace dbus
223 232
224 #endif // DBUS_TEST_SERVICE_H_ 233 #endif // DBUS_TEST_SERVICE_H_
OLDNEW
« no previous file with comments | « dbus/signal_sender_verification_unittest.cc ('k') | dbus/test_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698