-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathD192208.1699444906.diff
201 lines (179 loc) · 6.6 KB
/
D192208.1699444906.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
diff --git a/widget/gtk/nsUserIdleServiceGTK.h b/widget/gtk/nsUserIdleServiceGTK.h
--- a/widget/gtk/nsUserIdleServiceGTK.h
+++ b/widget/gtk/nsUserIdleServiceGTK.h
@@ -14,18 +14,20 @@
class nsUserIdleServiceGTK;
class UserIdleServiceImpl {
public:
- NS_INLINE_DECL_REFCOUNTING(UserIdleServiceImpl);
+ explicit UserIdleServiceImpl(nsUserIdleServiceGTK* aUserIdleService)
+ : mUserIdleServiceGTK(aUserIdleService){};
virtual bool PollIdleTime(uint32_t* aIdleTime) = 0;
- virtual bool ProbeImplementation(
- RefPtr<nsUserIdleServiceGTK> aUserIdleServiceGTK) = 0;
+ virtual bool ProbeImplementation() = 0;
+
+ virtual ~UserIdleServiceImpl() = default;
protected:
- virtual ~UserIdleServiceImpl() = default;
+ nsUserIdleServiceGTK* mUserIdleServiceGTK;
};
#define IDLE_SERVICE_MUTTER 0
#define IDLE_SERVICE_XSCREENSAVER 1
#define IDLE_SERVICE_NONE 2
@@ -61,11 +63,11 @@
nsUserIdleServiceGTK() = default;
private:
~nsUserIdleServiceGTK() = default;
- RefPtr<UserIdleServiceImpl> mIdleService;
+ mozilla::UniquePtr<UserIdleServiceImpl> mIdleService;
#ifdef MOZ_ENABLE_DBUS
int mIdleServiceType = IDLE_SERVICE_MUTTER;
#else
int mIdleServiceType = IDLE_SERVICE_XSCREENSAVER;
#endif
diff --git a/widget/gtk/nsUserIdleServiceGTK.cpp b/widget/gtk/nsUserIdleServiceGTK.cpp
--- a/widget/gtk/nsUserIdleServiceGTK.cpp
+++ b/widget/gtk/nsUserIdleServiceGTK.cpp
@@ -74,12 +74,11 @@
MOZ_LOG(sIdleLog, LogLevel::Warning,
("XSSQueryExtension returned false!\n"));
return false;
}
- bool ProbeImplementation(
- RefPtr<nsUserIdleServiceGTK> aUserIdleServiceGTK) override {
+ bool ProbeImplementation() override {
MOZ_LOG(sIdleLog, LogLevel::Info,
("UserIdleServiceX11::UserIdleServiceX11()\n"));
if (!mozilla::widget::GdkIsX11Display()) {
return false;
@@ -114,15 +113,17 @@
// We're missing X11 symbols
return false;
}
// UserIdleServiceX11 uses sync init, confirm it now.
- aUserIdleServiceGTK->AcceptServiceCallback();
+ mUserIdleServiceGTK->AcceptServiceCallback();
return true;
}
- protected:
+ explicit UserIdleServiceX11(nsUserIdleServiceGTK* aUserIdleService)
+ : UserIdleServiceImpl(aUserIdleService){};
+
~UserIdleServiceX11() {
# ifdef MOZ_X11
if (mXssInfo) {
XFree(mXssInfo);
}
@@ -164,11 +165,11 @@
mCancellable)
->Then(
GetCurrentSerialEventTarget(), __func__,
// It's safe to capture this as we use mCancellable to stop
// listening.
- [self = RefPtr{this}, this](RefPtr<GVariant>&& aResult) {
+ [this](RefPtr<GVariant>&& aResult) {
if (!g_variant_is_of_type(aResult, G_VARIANT_TYPE_TUPLE) ||
g_variant_n_children(aResult) != 1) {
MOZ_LOG(sIdleLog, LogLevel::Info,
("PollIdleTime() Unexpected params type: %s\n",
g_variant_get_type_string(aResult)));
@@ -191,25 +192,25 @@
mLastIdleTime = idleTime;
mPollInProgress = false;
MOZ_LOG(sIdleLog, LogLevel::Info,
("Async handler got %d\n", mLastIdleTime));
},
- [self = RefPtr{this}, this](GUniquePtr<GError>&& aError) {
+ [this](GUniquePtr<GError>&& aError) {
mPollInProgress = false;
g_warning("Failed to call GetIdletime(): %s\n",
aError->message);
+ mUserIdleServiceGTK->RejectAndTryNextServiceCallback();
});
}
*aIdleTime = mLastIdleTime;
MOZ_LOG(sIdleLog, LogLevel::Info,
("PollIdleTime() returns %d\n", *aIdleTime));
return true;
}
- bool ProbeImplementation(
- RefPtr<nsUserIdleServiceGTK> aUserIdleServiceGTK) override {
+ bool ProbeImplementation() override {
MOZ_LOG(sIdleLog, LogLevel::Info,
("UserIdleServiceMutter::UserIdleServiceMutter()\n"));
mCancellable = dont_AddRef(g_cancellable_new());
CreateDBusProxyForBus(
@@ -219,23 +220,23 @@
nullptr, "org.gnome.Mutter.IdleMonitor",
"/org/gnome/Mutter/IdleMonitor/Core", "org.gnome.Mutter.IdleMonitor",
mCancellable)
->Then(
GetCurrentSerialEventTarget(), __func__,
- [self = RefPtr{this}, service = RefPtr{aUserIdleServiceGTK}](
- RefPtr<GDBusProxy>&& aProxy) {
- self->mProxy = std::move(aProxy);
- service->AcceptServiceCallback();
+ [this](RefPtr<GDBusProxy>&& aProxy) {
+ mProxy = std::move(aProxy);
+ mUserIdleServiceGTK->AcceptServiceCallback();
},
- [self = RefPtr{this}, service = RefPtr{aUserIdleServiceGTK}](
- GUniquePtr<GError>&& aError) {
- service->RejectAndTryNextServiceCallback();
+ [this](GUniquePtr<GError>&& aError) {
+ mUserIdleServiceGTK->RejectAndTryNextServiceCallback();
});
return true;
}
- protected:
+ explicit UserIdleServiceMutter(nsUserIdleServiceGTK* aUserIdleService)
+ : UserIdleServiceImpl(aUserIdleService){};
+
~UserIdleServiceMutter() {
if (mCancellable) {
g_cancellable_cancel(mCancellable);
mCancellable = nullptr;
}
@@ -257,23 +258,23 @@
MOZ_ASSERT(!mIdleService);
switch (mIdleServiceType) {
#ifdef MOZ_ENABLE_DBUS
case IDLE_SERVICE_MUTTER:
- mIdleService = new UserIdleServiceMutter();
+ mIdleService = MakeUnique<UserIdleServiceMutter>(this);
break;
#endif
#ifdef MOZ_X11
case IDLE_SERVICE_XSCREENSAVER:
- mIdleService = new UserIdleServiceX11();
+ mIdleService = MakeUnique<UserIdleServiceX11>(this);
break;
#endif
default:
return;
}
- if (!mIdleService->ProbeImplementation(this)) {
+ if (!mIdleService->ProbeImplementation()) {
RejectAndTryNextServiceCallback();
}
}
void nsUserIdleServiceGTK::AcceptServiceCallback() {
@@ -289,19 +290,19 @@
mIdleServiceType));
// Delete recent non-working service
MOZ_ASSERT(mIdleService, "Nothing to reject?");
mIdleService = nullptr;
+ mIdleServiceInitialized = false;
mIdleServiceType++;
if (mIdleServiceType < IDLE_SERVICE_NONE) {
MOZ_LOG(sIdleLog, LogLevel::Info,
("nsUserIdleServiceGTK try next idle service\n"));
ProbeService();
} else {
MOZ_LOG(sIdleLog, LogLevel::Info, ("nsUserIdleServiceGTK failed\n"));
- mIdleServiceInitialized = false;
}
}
bool nsUserIdleServiceGTK::PollIdleTime(uint32_t* aIdleTime) {
if (!mIdleServiceInitialized) {