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
3 // found in the LICENSE file.
5 #ifndef UI_DISPLAY_CHROMEOS_CONFIGURATION_TASK_H_
6 #define UI_DISPLAY_CHROMEOS_CONFIGURATION_TASK_H_
11 #include "base/callback.h"
12 #include "base/memory/weak_ptr.h"
13 #include "ui/display/display_export.h"
14 #include "ui/gfx/geometry/point.h"
19 class DisplaySnapshot
;
20 class NativeDisplayDelegate
;
22 struct DISPLAY_EXPORT DisplayConfigureRequest
{
23 DisplayConfigureRequest(DisplaySnapshot
* display
,
24 const DisplayMode
* mode
,
25 const gfx::Point
& origin
);
27 DisplaySnapshot
* display
;
28 const DisplayMode
* mode
;
32 // Applies the display configuration asynchronously.
33 class DISPLAY_EXPORT ConfigureDisplaysTask
{
36 // At least one of the displays failed to apply any mode it supports.
39 // The requested configuration was applied.
42 // At least one of the displays failed to apply the requested
43 // configuration, but it managed to fall back to another mode.
47 typedef base::Callback
<void(Status
)> ResponseCallback
;
49 ConfigureDisplaysTask(NativeDisplayDelegate
* delegate
,
50 const std::vector
<DisplayConfigureRequest
>& requests
,
51 const ResponseCallback
& callback
);
52 ~ConfigureDisplaysTask();
54 // Starts the configuration task.
58 void OnConfigured(size_t index
, bool success
);
60 NativeDisplayDelegate
* delegate_
; // Not owned.
62 std::vector
<DisplayConfigureRequest
> requests_
;
64 // When the task finishes executing it runs the callback to notify that the
65 // task is done and the task status.
66 ResponseCallback callback_
;
68 // Stores the indexes of pending requests in |requests_|.
69 std::queue
<size_t> pending_request_indexes_
;
71 // Used to keep make sure that synchronous executions do not recurse during
75 // Number of display configured. This is used to check whether there are
77 size_t num_displays_configured_
;
81 base::WeakPtrFactory
<ConfigureDisplaysTask
> weak_ptr_factory_
;
83 DISALLOW_COPY_AND_ASSIGN(ConfigureDisplaysTask
);
88 #endif // UI_DISPLAY_CHROMEOS_CONFIGURATION_TASK_H_