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

Side by Side Diff: dbus/bus.cc

Issue 9582044: Convert uses of int ms to TimeDelta in dbus. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix mock PostDelayedTask function interface. Created 8 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
« no previous file with comments | « dbus/bus.h ('k') | dbus/end_to_end_async_unittest.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 // TODO(satorux): 5 // TODO(satorux):
6 // - Handle "disconnected" signal. 6 // - Handle "disconnected" signal.
7 7
8 #include "dbus/bus.h" 8 #include "dbus/bus.h"
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 // Returns true if the timeout is ready to be monitored. 110 // Returns true if the timeout is ready to be monitored.
111 bool IsReadyToBeMonitored() { 111 bool IsReadyToBeMonitored() {
112 return dbus_timeout_get_enabled(raw_timeout_); 112 return dbus_timeout_get_enabled(raw_timeout_);
113 } 113 }
114 114
115 // Starts monitoring the timeout. 115 // Starts monitoring the timeout.
116 void StartMonitoring(dbus::Bus* bus) { 116 void StartMonitoring(dbus::Bus* bus) {
117 bus->PostDelayedTaskToDBusThread(FROM_HERE, 117 bus->PostDelayedTaskToDBusThread(FROM_HERE,
118 base::Bind(&Timeout::HandleTimeout, 118 base::Bind(&Timeout::HandleTimeout,
119 this), 119 this),
120 GetIntervalInMs()); 120 GetInterval());
121 monitoring_is_active_ = true; 121 monitoring_is_active_ = true;
122 } 122 }
123 123
124 // Stops monitoring the timeout. 124 // Stops monitoring the timeout.
125 void StopMonitoring() { 125 void StopMonitoring() {
126 // We cannot take back the delayed task we posted in 126 // We cannot take back the delayed task we posted in
127 // StartMonitoring(), so we just mark the monitoring is inactive now. 127 // StartMonitoring(), so we just mark the monitoring is inactive now.
128 monitoring_is_active_ = false; 128 monitoring_is_active_ = false;
129 } 129 }
130 130
131 // Returns the interval in milliseconds. 131 // Returns the interval.
132 int GetIntervalInMs() { 132 base::TimeDelta GetInterval() {
133 return dbus_timeout_get_interval(raw_timeout_); 133 return base::TimeDelta::FromMilliseconds(
134 dbus_timeout_get_interval(raw_timeout_));
134 } 135 }
135 136
136 // Cleans up the raw_timeout and marks that timeout is completed. 137 // Cleans up the raw_timeout and marks that timeout is completed.
137 // See the class comment above for why we are doing this. 138 // See the class comment above for why we are doing this.
138 void Complete() { 139 void Complete() {
139 dbus_timeout_set_data(raw_timeout_, NULL, NULL); 140 dbus_timeout_set_data(raw_timeout_, NULL, NULL);
140 is_completed = true; 141 is_completed = true;
141 Release(); 142 Release();
142 } 143 }
143 144
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 DCHECK(origin_message_loop_proxy_.get()); 605 DCHECK(origin_message_loop_proxy_.get());
605 if (!origin_message_loop_proxy_->PostTask(from_here, task)) { 606 if (!origin_message_loop_proxy_->PostTask(from_here, task)) {
606 LOG(WARNING) << "Failed to post a task to the origin message loop"; 607 LOG(WARNING) << "Failed to post a task to the origin message loop";
607 } 608 }
608 } 609 }
609 } 610 }
610 611
611 void Bus::PostDelayedTaskToDBusThread( 612 void Bus::PostDelayedTaskToDBusThread(
612 const tracked_objects::Location& from_here, 613 const tracked_objects::Location& from_here,
613 const base::Closure& task, 614 const base::Closure& task,
614 int delay_ms) { 615 base::TimeDelta delay) {
615 if (dbus_thread_message_loop_proxy_.get()) { 616 if (dbus_thread_message_loop_proxy_.get()) {
616 if (!dbus_thread_message_loop_proxy_->PostDelayedTask( 617 if (!dbus_thread_message_loop_proxy_->PostDelayedTask(
617 from_here, task, delay_ms)) { 618 from_here, task, delay)) {
618 LOG(WARNING) << "Failed to post a task to the D-Bus thread message loop"; 619 LOG(WARNING) << "Failed to post a task to the D-Bus thread message loop";
619 } 620 }
620 } else { 621 } else {
621 DCHECK(origin_message_loop_proxy_.get()); 622 DCHECK(origin_message_loop_proxy_.get());
622 if (!origin_message_loop_proxy_->PostDelayedTask( 623 if (!origin_message_loop_proxy_->PostDelayedTask(
623 from_here, task, delay_ms)) { 624 from_here, task, delay)) {
624 LOG(WARNING) << "Failed to post a task to the origin message loop"; 625 LOG(WARNING) << "Failed to post a task to the origin message loop";
625 } 626 }
626 } 627 }
627 } 628 }
628 629
629 bool Bus::HasDBusThread() { 630 bool Bus::HasDBusThread() {
630 return dbus_thread_message_loop_proxy_.get() != NULL; 631 return dbus_thread_message_loop_proxy_.get() != NULL;
631 } 632 }
632 633
633 void Bus::AssertOnOriginThread() { 634 void Bus::AssertOnOriginThread() {
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 } 758 }
758 759
759 void Bus::OnDispatchStatusChangedThunk(DBusConnection* connection, 760 void Bus::OnDispatchStatusChangedThunk(DBusConnection* connection,
760 DBusDispatchStatus status, 761 DBusDispatchStatus status,
761 void* data) { 762 void* data) {
762 Bus* self = static_cast<Bus*>(data); 763 Bus* self = static_cast<Bus*>(data);
763 return self->OnDispatchStatusChanged(connection, status); 764 return self->OnDispatchStatusChanged(connection, status);
764 } 765 }
765 766
766 } // namespace dbus 767 } // namespace dbus
OLDNEW
« no previous file with comments | « dbus/bus.h ('k') | dbus/end_to_end_async_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698