Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Issue 29332848: Issue #3432 - Manage COM events with a resource class

Created:
Dec. 17, 2015, 11:41 a.m. by Eric
Modified:
July 27, 2016, 8:55 p.m.
Reviewers:
sergei, Oleksandr
CC:
Felix Dahlke
Visibility:
Public.

Description

Issue #3432 - Manage COM events with a resource class Add 'AtlEventRegistration', a resource class that registers for events in its constructor and unregisters in it destructor. Add 'AtlEventRegistrationHolder' which hold an event resource, exposing 'Start()' and 'Stop()' methods instead. Add 'CPluginClass::browserEvents' to encapsulate these events and remove the superseded flag 'm_isAdvised' and member function 'Unadvise()'. Call 'Start()' and 'Stop()' once each in 'SetSite()'. Add 'CPluginClass::detachedInitializationFailed' to capture the state of a possible failure. Added a guards to check this flag at the beginning of each event handler, having the same effect as if events were not being received. Remove call to disable events when the initialization does fail. Removed 'CPluginClass::OnOnQuit' entirely. It's only code was to deregister events. Deregistering now works reliably in both 'SetSite()' and in the destructor, so there's no need for special handling.

Patch Set 1 : #

Patch Set 2 : rebase #

Total comments: 34

Patch Set 3 : rebase, address comments #

Total comments: 4

Patch Set 4 : rebase only #

Unified diffs Side-by-side diffs Delta from patch set Stats (+119 lines, -69 lines) Patch
M src/plugin/PluginClass.h View 1 2 3 5 chunks +96 lines, -5 lines 0 comments Download
M src/plugin/PluginClass.cpp View 1 2 3 15 chunks +23 lines, -64 lines 0 comments Download

Messages

Total messages: 10
Eric
Dec. 17, 2015, 6:11 p.m. (2015-12-17 18:11:42 UTC) #1
sergei
https://codereview.adblockplus.org/29332848/diff/29333238/src/plugin/PluginClass.cpp File src/plugin/PluginClass.cpp (right): https://codereview.adblockplus.org/29332848/diff/29333238/src/plugin/PluginClass.cpp#newcode261 src/plugin/PluginClass.cpp:261: // Start event last, after everything is ready to ...
Jan. 6, 2016, 8:41 a.m. (2016-01-06 08:41:59 UTC) #2
Eric
Patch set 3 includes rebase and addresses Sergei's comments. https://codereview.adblockplus.org/29332848/diff/29333238/src/plugin/PluginClass.cpp File src/plugin/PluginClass.cpp (right): https://codereview.adblockplus.org/29332848/diff/29333238/src/plugin/PluginClass.cpp#newcode261 src/plugin/PluginClass.cpp:261: ...
Jan. 7, 2016, 4:24 p.m. (2016-01-07 16:24:49 UTC) #3
sergei
I'm waiting for the opinion of others
Jan. 8, 2016, 10:14 a.m. (2016-01-08 10:14:29 UTC) #4
Eric
On 2016/01/08 10:14:29, sergei wrote: > I'm waiting for the opinion of others I'm waiting ...
Jan. 29, 2016, 2:20 p.m. (2016-01-29 14:20:12 UTC) #5
sergei
Let's compare the case with AtlEventRegistrationHolder and without. `connection` refers to `std::unique_ptr<AtlEventRegistration<Sink, Source>>` with without ...
Feb. 4, 2016, 1:45 p.m. (2016-02-04 13:45:51 UTC) #6
sergei
One can find formatted message here http://pastebin.com/raw/brdxwVpw
Feb. 4, 2016, 1:56 p.m. (2016-02-04 13:56:29 UTC) #7
Eric
On 2016/02/04 13:45:51, sergei wrote: > Let's compare the case with AtlEventRegistrationHolder and without. You ...
Feb. 4, 2016, 5 p.m. (2016-02-04 17:00:28 UTC) #8
sergei
I see the point. You want to have some class which is instantiated when SetSite(not ...
Feb. 4, 2016, 7:41 p.m. (2016-02-04 19:41:58 UTC) #9
Eric
Feb. 4, 2016, 8:13 p.m. (2016-02-04 20:13:25 UTC) #10
On 2016/02/04 19:41:58, sergei wrote:
> I see the point. You want to have some class which is instantiated when
> SetSite(not nullptr) is called and destroyed when SetSite(nullptr) is called.

That is _one_ of the desiderata. If that's all that you see, you are indeed
missing the whole point.

> thus it should throw an exception in constructor, and
> just drop AtlEventRegistrationHolder later.
> That's fine 

OK. Seems like progress. You've said you're OK with 'AtlEventRegistration'. So
the real question is then whether we need a separate class or whether we would
inline its code. I admit that inlining its code would work, because each of
those functions is only called once. I believe having a second class is better
because it clarifies the code to 'SetSite()', which is still something of an
unholy mess and greatly benefits from clarity. Removing the details of lifecycle
management out of 'SetSite()' is a benefit worth paying for by having a new
class.

I'll note for Oleksandr's benefit that you don't seem to have identified any
defects with the code and that your only remaining concerns are with code style,
broadly construed.

https://codereview.adblockplus.org/29332848/diff/29333238/src/plugin/PluginCl...
File src/plugin/PluginClass.h (right):

https://codereview.adblockplus.org/29332848/diff/29333238/src/plugin/PluginCl...
src/plugin/PluginClass.h:54: class AtlEventRegistration
On 2016/02/04 19:41:57, sergei wrote:
> I don't want to debate here

I don't want to debate here either, so I'll forgo a response.

https://codereview.adblockplus.org/29332848/diff/29333238/src/plugin/PluginCl...
src/plugin/PluginClass.h:74: throw std::runtime_error("DispEventAdvise()
failed");
On 2016/02/04 19:41:57, sergei wrote:
> I have not said whether I like exceptions or not, I said that I don't like
when
> they are used to build some logic. 

You'll have to tell me what "logic" you're talking about then. The constructor
of this class throws when it fails to acquire a resource. If you have a problem
with that, you have a problem with RAII generally.

https://codereview.adblockplus.org/29332848/diff/29333294/src/plugin/PluginCl...
File src/plugin/PluginClass.h (right):

https://codereview.adblockplus.org/29332848/diff/29333294/src/plugin/PluginCl...
src/plugin/PluginClass.h:67: AtlEventRegistration(Sink* consumer, Source*
producer)
We've entered bikeshedding territory here. You have a personal preference that
differs from mine.

Suggestion rejected.

Powered by Google App Engine
This is Rietveld