OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "content/shell/browser/layout_test/layout_test_bluetooth_chooser_factor
y.h" | 5 #include "content/shell/browser/layout_test/layout_test_bluetooth_chooser_factor
y.h" |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/memory/ptr_util.h" |
8 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
9 #include "content/public/browser/render_frame_host.h" | 10 #include "content/public/browser/render_frame_host.h" |
10 #include "url/origin.h" | 11 #include "url/origin.h" |
11 | 12 |
12 namespace content { | 13 namespace content { |
13 | 14 |
14 class WebContents; | 15 class WebContents; |
15 | 16 |
16 // Implements a Bluetooth chooser that records events it's sent, instead of | 17 // Implements a Bluetooth chooser that records events it's sent, instead of |
17 // showing a dialog. It allows tests to control how the chooser responds. | 18 // showing a dialog. It allows tests to control how the chooser responds. |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 DISALLOW_COPY_AND_ASSIGN(Chooser); | 93 DISALLOW_COPY_AND_ASSIGN(Chooser); |
93 }; | 94 }; |
94 | 95 |
95 LayoutTestBluetoothChooserFactory::LayoutTestBluetoothChooserFactory() | 96 LayoutTestBluetoothChooserFactory::LayoutTestBluetoothChooserFactory() |
96 : weak_this_(this) {} | 97 : weak_this_(this) {} |
97 | 98 |
98 LayoutTestBluetoothChooserFactory::~LayoutTestBluetoothChooserFactory() { | 99 LayoutTestBluetoothChooserFactory::~LayoutTestBluetoothChooserFactory() { |
99 SendEvent(BluetoothChooser::Event::CANCELLED, ""); | 100 SendEvent(BluetoothChooser::Event::CANCELLED, ""); |
100 } | 101 } |
101 | 102 |
102 scoped_ptr<BluetoothChooser> | 103 std::unique_ptr<BluetoothChooser> |
103 LayoutTestBluetoothChooserFactory::RunBluetoothChooser( | 104 LayoutTestBluetoothChooserFactory::RunBluetoothChooser( |
104 RenderFrameHost* frame, | 105 RenderFrameHost* frame, |
105 const BluetoothChooser::EventHandler& event_handler) { | 106 const BluetoothChooser::EventHandler& event_handler) { |
106 const url::Origin origin = frame->GetLastCommittedOrigin(); | 107 const url::Origin origin = frame->GetLastCommittedOrigin(); |
107 DCHECK(!origin.unique()); | 108 DCHECK(!origin.unique()); |
108 std::string event = "chooser-opened("; | 109 std::string event = "chooser-opened("; |
109 event += origin.Serialize(); | 110 event += origin.Serialize(); |
110 event += ")"; | 111 event += ")"; |
111 events_.push_back(event); | 112 events_.push_back(event); |
112 return make_scoped_ptr(new Chooser(weak_this_.GetWeakPtr(), event_handler)); | 113 return base::WrapUnique(new Chooser(weak_this_.GetWeakPtr(), event_handler)); |
113 } | 114 } |
114 | 115 |
115 std::vector<std::string> | 116 std::vector<std::string> |
116 LayoutTestBluetoothChooserFactory::GetAndResetEvents() { | 117 LayoutTestBluetoothChooserFactory::GetAndResetEvents() { |
117 std::vector<std::string> result; | 118 std::vector<std::string> result; |
118 result.swap(events_); | 119 result.swap(events_); |
119 return result; | 120 return result; |
120 } | 121 } |
121 | 122 |
122 void LayoutTestBluetoothChooserFactory::SendEvent( | 123 void LayoutTestBluetoothChooserFactory::SendEvent( |
123 BluetoothChooser::Event event, | 124 BluetoothChooser::Event event, |
124 const std::string& device_id) { | 125 const std::string& device_id) { |
125 // Copy |choosers_| to make sure event handler executions that modify | 126 // Copy |choosers_| to make sure event handler executions that modify |
126 // |choosers_| don't invalidate iterators. | 127 // |choosers_| don't invalidate iterators. |
127 std::vector<Chooser*> choosers_copy(choosers_.begin(), choosers_.end()); | 128 std::vector<Chooser*> choosers_copy(choosers_.begin(), choosers_.end()); |
128 for (Chooser* chooser : choosers_copy) { | 129 for (Chooser* chooser : choosers_copy) { |
129 chooser->event_handler.Run(event, device_id); | 130 chooser->event_handler.Run(event, device_id); |
130 } | 131 } |
131 } | 132 } |
132 | 133 |
133 } // namespace content | 134 } // namespace content |
OLD | NEW |