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

Side by Side Diff: Source/core/dom/SimpleLifecycleNotifier.h

Issue 18777003: Extract simpler classes for observing context lifecycle and observe Page lifecycle inNavigatorVibra… (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Use SimpleLifecycleObserver in addObserver / removeObserver. Created 7 years, 5 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3 * Copyright (C) 2013 Google Inc. All Rights Reserved.
3 * 4 *
4 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
6 * are met: 7 * are met:
7 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 11 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 12 * documentation and/or other materials provided with the distribution.
12 * 13 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 * 25 *
25 */ 26 */
27 #ifndef SimpleLifecycleNotifier_h
28 #define SimpleLifecycleNotifier_h
26 29
27 #ifndef ContextLifecycleObserver_h 30 #include "core/dom/SimpleLifecycleObserver.h"
28 #define ContextLifecycleObserver_h 31 #include "wtf/HashSet.h"
32 #include "wtf/PassOwnPtr.h"
29 33
30 namespace WebCore { 34 namespace WebCore {
31 35
32 class ScriptExecutionContext; 36 class SimpleLifecycleContext;
37 class SimpleLifecycleObserver;
33 38
34 class ContextLifecycleObserver { 39 class SimpleLifecycleNotifier {
35 public: 40 public:
36 enum Type { 41 static PassOwnPtr<SimpleLifecycleNotifier> create(SimpleLifecycleContext*);
37 ActiveDOMObjectType, 42
38 DocumentLifecycleObserverType, 43 virtual ~SimpleLifecycleNotifier();
39 GenericType 44
45 typedef HashSet<SimpleLifecycleObserver*> SimpleObserverSet;
46
47 virtual void addObserver(SimpleLifecycleObserver*, SimpleLifecycleObserver:: Type);
48 virtual void removeObserver(SimpleLifecycleObserver*, SimpleLifecycleObserve r::Type);
49
50 protected:
51 explicit SimpleLifecycleNotifier(SimpleLifecycleContext*);
52
53 SimpleLifecycleContext* context();
54
55 enum IterationType {
56 IteratingNone,
57 IteratingOverActiveDOMObjects,
58 IteratingOverContextObservers,
59 IteratingOverDocumentObservers,
60 IteratingOverPageObservers
abarth-chromium 2013/07/08 21:25:24 I'm not sure it's worth abstracting the SimpleLife
Michael van Ouwerkerk 2013/07/09 17:09:12 The file branch detection may be confusing here -
40 }; 61 };
41 62
42 explicit ContextLifecycleObserver(ScriptExecutionContext*, Type = GenericTyp e); 63 IterationType m_iterating;
43 virtual void contextDestroyed();
44 64
45 ScriptExecutionContext* scriptExecutionContext() const { return m_scriptExec utionContext; } 65 private:
66 SimpleObserverSet m_observers;
67 SimpleLifecycleContext* m_context;
68 bool m_inDestructor;
69 };
46 70
47 protected: 71 inline PassOwnPtr<SimpleLifecycleNotifier> SimpleLifecycleNotifier::create(Simpl eLifecycleContext* context)
48 virtual ~ContextLifecycleObserver(); 72 {
49 void observeContext(ScriptExecutionContext*, Type); 73 return adoptPtr(new SimpleLifecycleNotifier(context));
50 74 }
51 ScriptExecutionContext* m_scriptExecutionContext;
52 };
53 75
54 } // namespace WebCore 76 } // namespace WebCore
55 77
56 #endif // ContextLifecycleObserver_h 78 #endif // SimpleLifecycleNotifier_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698