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

Side by Side Diff: ui/display/chromeos/configure_displays_task.cc

Issue 800143002: Reland: Update DisplayConfigurator to use the asynchronous tasks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@async-refactor4
Patch Set: Fix heap use after free issue Created 6 years 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
« no previous file with comments | « no previous file | ui/display/chromeos/display_configurator.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "ui/display/chromeos/configure_displays_task.h" 5 #include "ui/display/chromeos/configure_displays_task.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "ui/display/types/display_snapshot.h" 9 #include "ui/display/types/display_snapshot.h"
10 #include "ui/display/types/native_display_delegate.h" 10 #include "ui/display/types/native_display_delegate.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 } 58 }
59 59
60 void ConfigureDisplaysTask::Run() { 60 void ConfigureDisplaysTask::Run() {
61 // Synchronous configurators will recursively call Run(). In that case just 61 // Synchronous configurators will recursively call Run(). In that case just
62 // defer their call to the next iteration in the while-loop. This is done to 62 // defer their call to the next iteration in the while-loop. This is done to
63 // guard against stack overflows if the display has a large list of broken 63 // guard against stack overflows if the display has a large list of broken
64 // modes. 64 // modes.
65 if (is_configuring_) 65 if (is_configuring_)
66 return; 66 return;
67 67
68 base::AutoReset<bool> recursivity_guard(&is_configuring_, true); 68 {
69 while (!pending_request_indexes_.empty()) { 69 base::AutoReset<bool> recursivity_guard(&is_configuring_, true);
70 size_t index = pending_request_indexes_.front(); 70 while (!pending_request_indexes_.empty()) {
71 DisplayConfigureRequest* request = &requests_[index]; 71 size_t index = pending_request_indexes_.front();
72 pending_request_indexes_.pop(); 72 DisplayConfigureRequest* request = &requests_[index];
73 delegate_->Configure(*request->display, request->mode, request->origin, 73 pending_request_indexes_.pop();
74 base::Bind(&ConfigureDisplaysTask::OnConfigured, 74 delegate_->Configure(*request->display, request->mode, request->origin,
75 weak_ptr_factory_.GetWeakPtr(), index)); 75 base::Bind(&ConfigureDisplaysTask::OnConfigured,
76 weak_ptr_factory_.GetWeakPtr(), index));
77 }
76 } 78 }
77 79
78 // Nothing should be modified after the |callback_| is called since thie 80 // Nothing should be modified after the |callback_| is called since the
79 // task may be deleted in the callback. 81 // task may be deleted in the callback.
80 if (num_displays_configured_ == requests_.size()) 82 if (num_displays_configured_ == requests_.size())
81 callback_.Run(task_status_); 83 callback_.Run(task_status_);
82 } 84 }
83 85
84 void ConfigureDisplaysTask::OnConfigured(size_t index, bool success) { 86 void ConfigureDisplaysTask::OnConfigured(size_t index, bool success) {
85 DisplayConfigureRequest* request = &requests_[index]; 87 DisplayConfigureRequest* request = &requests_[index];
86 VLOG(2) << "Configured status=" << success 88 VLOG(2) << "Configured status=" << success
87 << " display=" << request->display->display_id() 89 << " display=" << request->display->display_id()
88 << " origin=" << request->origin.ToString() 90 << " origin=" << request->origin.ToString()
(...skipping 14 matching lines...) Expand all
103 } 105 }
104 106
105 num_displays_configured_++; 107 num_displays_configured_++;
106 if (!success) 108 if (!success)
107 task_status_ = ERROR; 109 task_status_ = ERROR;
108 110
109 Run(); 111 Run();
110 } 112 }
111 113
112 } // namespace ui 114 } // namespace ui
OLDNEW
« no previous file with comments | « no previous file | ui/display/chromeos/display_configurator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698