Sort unlaunched apps on app list start page by apps grid order.
[chromium-blink-merge.git] / ui / display / chromeos / configure_displays_task.h
blob1d8991558f768c32cbf3553cacdacb91d0b094aa
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_
8 #include <queue>
9 #include <vector>
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"
16 namespace ui {
18 class DisplayMode;
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;
29 gfx::Point origin;
32 // Applies the display configuration asynchronously.
33 class DISPLAY_EXPORT ConfigureDisplaysTask {
34 public:
35 enum Status {
36 // At least one of the displays failed to apply any mode it supports.
37 ERROR,
39 // The requested configuration was applied.
40 SUCCESS,
42 // At least one of the displays failed to apply the requested
43 // configuration, but it managed to fall back to another mode.
44 PARTIAL_SUCCESS,
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.
55 void Run();
57 private:
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
72 // the configuration.
73 bool is_configuring_;
75 // Number of display configured. This is used to check whether there are
76 // pending requests.
77 size_t num_displays_configured_;
79 Status task_status_;
81 base::WeakPtrFactory<ConfigureDisplaysTask> weak_ptr_factory_;
83 DISALLOW_COPY_AND_ASSIGN(ConfigureDisplaysTask);
86 } // namespace ui
88 #endif // UI_DISPLAY_CHROMEOS_CONFIGURATION_TASK_H_