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

Side by Side Diff: ui/display/display_list.h

Issue 2378923002: Adds ability to suspend notifying observers when display list is changed (Closed)
Patch Set: cleanup Created 4 years, 2 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 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #ifndef UI_DISPLAY_DISPLAY_LIST_H_ 5 #ifndef UI_DISPLAY_DISPLAY_LIST_H_
6 #define UI_DISPLAY_DISPLAY_LIST_H_ 6 #define UI_DISPLAY_DISPLAY_LIST_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory>
10 #include <vector> 11 #include <vector>
11 12
12 #include "base/observer_list.h" 13 #include "base/observer_list.h"
13 #include "ui/display/display.h" 14 #include "ui/display/display.h"
14 #include "ui/display/display_export.h" 15 #include "ui/display/display_export.h"
15 16
16 namespace display { 17 namespace display {
17 18
18 class Display; 19 class Display;
20 class DisplayList;
19 class DisplayObserver; 21 class DisplayObserver;
20 22
23 // See description in DisplayLock::SuspendObserverUpdates.
24 class DISPLAY_EXPORT DisplayListObserverLock {
James Cook 2016/09/29 04:15:05 I like lock objects.
25 public:
26 ~DisplayListObserverLock();
27
28 private:
29 friend class DisplayList;
30
31 explicit DisplayListObserverLock(DisplayList* display_list);
32
33 DisplayList* display_list_;
34
35 DISALLOW_COPY_AND_ASSIGN(DisplayListObserverLock);
36 };
37
21 // Maintains an ordered list of display::Displays as well as operations to add, 38 // Maintains an ordered list of display::Displays as well as operations to add,
22 // remove and update said list. Additionally maintains display::DisplayObservers 39 // remove and update said list. Additionally maintains display::DisplayObservers
23 // and updates them as appropriate. 40 // and updates them as appropriate.
24 class DISPLAY_EXPORT DisplayList { 41 class DISPLAY_EXPORT DisplayList {
25 public: 42 public:
26 using Displays = std::vector<display::Display>; 43 using Displays = std::vector<display::Display>;
27 44
28 enum class Type { 45 enum class Type {
29 PRIMARY, 46 PRIMARY,
30 NOT_PRIMARY, 47 NOT_PRIMARY,
31 }; 48 };
32 49
33 DisplayList(); 50 DisplayList();
34 ~DisplayList(); 51 ~DisplayList();
35 52
36 void AddObserver(display::DisplayObserver* observer); 53 void AddObserver(display::DisplayObserver* observer);
37 void RemoveObserver(display::DisplayObserver* observer); 54 void RemoveObserver(display::DisplayObserver* observer);
38 55
39 const Displays& displays() const { return displays_; } 56 const Displays& displays() const { return displays_; }
40 57
41 Displays::const_iterator FindDisplayById(int64_t id) const; 58 Displays::const_iterator FindDisplayById(int64_t id) const;
42 Displays::iterator FindDisplayById(int64_t id); 59 Displays::iterator FindDisplayById(int64_t id);
43 60
44 Displays::const_iterator GetPrimaryDisplayIterator() const; 61 Displays::const_iterator GetPrimaryDisplayIterator() const;
45 62
63 // Internally increments a counter that while non-zero results in observers
64 // not being called for any changes to the displays. When
65 // DisplayListObserverLock is destroyed the counter is decremented. When the
66 // count reaches zero observers are notified of any pending changes.
67 //
68 // NOTE: this only supports suspsending followed by a single add and any
James Cook 2016/09/29 04:15:05 nit: suspending
69 // number of updates to the added display.
70 std::unique_ptr<DisplayListObserverLock> SuspendObserverUpdates();
71
46 // Updates the cached id based on display.id() as well as whether the Display 72 // Updates the cached id based on display.id() as well as whether the Display
47 // is the primary display. 73 // is the primary display.
48 void UpdateDisplay(const display::Display& display, Type type); 74 void UpdateDisplay(const display::Display& display, Type type);
49 75
50 // Adds a new Display. 76 // Adds a new Display.
51 void AddDisplay(const display::Display& display, Type type); 77 void AddDisplay(const display::Display& display, Type type);
52 78
53 // Removes the Display with the specified id. 79 // Removes the Display with the specified id.
54 void RemoveDisplay(int64_t id); 80 void RemoveDisplay(int64_t id);
55 81
56 private: 82 private:
83 friend class DisplayListObserverLock;
84
85 struct SuspendObserverState {
86 // Number of times SuspendObserverState() has been called.
87 int count = 0;
88
89 // displays_.size() at the time of the first call to SuspendObserverState().
90 size_t original_display_count = 0u;
James Cook 2016/09/29 04:15:05 Unused?
91
92 // Whether AddDisplay() was called while the lock was held.
93 bool display_added = false;
94 };
95
96 void IncrementObserverSuspendLockCount();
97 void DecrementObserverSuspendLockCount();
98
57 std::vector<display::Display> displays_; 99 std::vector<display::Display> displays_;
58 int primary_display_index_ = -1; 100 int primary_display_index_ = -1;
59 base::ObserverList<display::DisplayObserver> observers_; 101 base::ObserverList<display::DisplayObserver> observers_;
60 102
103 // Tracks state associated with calls to SuspendObserverState(). Non-null
104 // while SuspendObserverState::count is > 0.
105 std::unique_ptr<SuspendObserverState> suspend_observer_state_;
106
61 DISALLOW_COPY_AND_ASSIGN(DisplayList); 107 DISALLOW_COPY_AND_ASSIGN(DisplayList);
62 }; 108 };
63 109
64 } // namespace display 110 } // namespace display
65 111
66 #endif // UI_DISPLAY_DISPLAY_LIST_H_ 112 #endif // UI_DISPLAY_DISPLAY_LIST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698