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

Side by Side Diff: app/gtk_signal_registrar.cc

Issue 6257006: Move a bunch of random other files to src/ui/base... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 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 | Annotate | Revision Log
« no previous file with comments | « app/gtk_signal_registrar.h ('k') | app/message_box_flags.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "app/gtk_signal_registrar.h"
6
7 #include <glib-object.h>
8
9 #include "base/logging.h"
10
11 GtkSignalRegistrar::GtkSignalRegistrar() {
12 }
13
14 GtkSignalRegistrar::~GtkSignalRegistrar() {
15 for (HandlerMap::iterator list_iter = handler_lists_.begin();
16 list_iter != handler_lists_.end(); ++list_iter) {
17 GObject* object = list_iter->first;
18 g_object_weak_unref(object, WeakNotifyThunk, this);
19
20 HandlerList& handlers = list_iter->second;
21 for (HandlerList::iterator ids_iter = handlers.begin();
22 ids_iter != handlers.end(); ids_iter++) {
23 g_signal_handler_disconnect(list_iter->first, *ids_iter);
24 }
25 }
26 }
27
28 glong GtkSignalRegistrar::Connect(gpointer instance,
29 const gchar* detailed_signal,
30 GCallback signal_handler,
31 gpointer data) {
32 return ConnectInternal(instance, detailed_signal, signal_handler, data,
33 false);
34 }
35
36 glong GtkSignalRegistrar::ConnectAfter(gpointer instance,
37 const gchar* detailed_signal,
38 GCallback signal_handler,
39 gpointer data) {
40 return ConnectInternal(instance, detailed_signal, signal_handler, data, true);
41 }
42
43 glong GtkSignalRegistrar::ConnectInternal(gpointer instance,
44 const gchar* detailed_signal,
45 GCallback signal_handler,
46 gpointer data,
47 bool after) {
48 GObject* object = G_OBJECT(instance);
49
50 HandlerMap::iterator iter = handler_lists_.find(object);
51 if (iter == handler_lists_.end()) {
52 g_object_weak_ref(object, WeakNotifyThunk, this);
53 handler_lists_[object] = HandlerList();
54 iter = handler_lists_.find(object);
55 }
56
57 glong handler_id = after ?
58 g_signal_connect_after(instance, detailed_signal, signal_handler, data) :
59 g_signal_connect(instance, detailed_signal, signal_handler, data);
60 iter->second.push_back(handler_id);
61
62 return handler_id;
63 }
64
65 void GtkSignalRegistrar::WeakNotify(GObject* where_the_object_was) {
66 HandlerMap::iterator iter = handler_lists_.find(where_the_object_was);
67 if (iter == handler_lists_.end()) {
68 NOTREACHED();
69 return;
70 }
71 // The signal handlers will be disconnected automatically. Just erase the
72 // handler id list.
73 handler_lists_.erase(iter);
74 }
OLDNEW
« no previous file with comments | « app/gtk_signal_registrar.h ('k') | app/message_box_flags.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698