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/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "url/origin.h" | 9 #include "url/origin.h" |
10 | 10 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 | 93 |
94 LayoutTestBluetoothChooserFactory::LayoutTestBluetoothChooserFactory() | 94 LayoutTestBluetoothChooserFactory::LayoutTestBluetoothChooserFactory() |
95 : weak_this_(this) {} | 95 : weak_this_(this) {} |
96 | 96 |
97 LayoutTestBluetoothChooserFactory::~LayoutTestBluetoothChooserFactory() { | 97 LayoutTestBluetoothChooserFactory::~LayoutTestBluetoothChooserFactory() { |
98 SendEvent(BluetoothChooser::Event::CANCELLED, ""); | 98 SendEvent(BluetoothChooser::Event::CANCELLED, ""); |
99 } | 99 } |
100 | 100 |
101 scoped_ptr<BluetoothChooser> | 101 scoped_ptr<BluetoothChooser> |
102 LayoutTestBluetoothChooserFactory::RunBluetoothChooser( | 102 LayoutTestBluetoothChooserFactory::RunBluetoothChooser( |
103 WebContents* web_contents, | 103 RenderFrameHost* frame, |
104 const BluetoothChooser::EventHandler& event_handler, | 104 const BluetoothChooser::EventHandler& event_handler, |
105 const url::Origin& origin) { | 105 const url::Origin& origin) { |
106 DCHECK(!origin.unique()); | 106 DCHECK(!origin.unique()); |
107 std::string event = "chooser-opened("; | 107 std::string event = "chooser-opened("; |
108 event += origin.Serialize(); | 108 event += origin.Serialize(); |
109 event += ")"; | 109 event += ")"; |
110 events_.push_back(event); | 110 events_.push_back(event); |
111 return make_scoped_ptr(new Chooser(weak_this_.GetWeakPtr(), event_handler)); | 111 return make_scoped_ptr(new Chooser(weak_this_.GetWeakPtr(), event_handler)); |
112 } | 112 } |
113 | 113 |
114 std::vector<std::string> | 114 std::vector<std::string> |
115 LayoutTestBluetoothChooserFactory::GetAndResetEvents() { | 115 LayoutTestBluetoothChooserFactory::GetAndResetEvents() { |
116 std::vector<std::string> result; | 116 std::vector<std::string> result; |
117 result.swap(events_); | 117 result.swap(events_); |
118 return result; | 118 return result; |
119 } | 119 } |
120 | 120 |
121 void LayoutTestBluetoothChooserFactory::SendEvent( | 121 void LayoutTestBluetoothChooserFactory::SendEvent( |
122 BluetoothChooser::Event event, | 122 BluetoothChooser::Event event, |
123 const std::string& device_id) { | 123 const std::string& device_id) { |
124 // Copy |choosers_| to make sure event handler executions that modify | 124 // Copy |choosers_| to make sure event handler executions that modify |
125 // |choosers_| don't invalidate iterators. | 125 // |choosers_| don't invalidate iterators. |
126 std::vector<Chooser*> choosers_copy(choosers_.begin(), choosers_.end()); | 126 std::vector<Chooser*> choosers_copy(choosers_.begin(), choosers_.end()); |
127 for (Chooser* chooser : choosers_copy) { | 127 for (Chooser* chooser : choosers_copy) { |
128 chooser->event_handler.Run(event, device_id); | 128 chooser->event_handler.Run(event, device_id); |
129 } | 129 } |
130 } | 130 } |
131 | 131 |
132 } // namespace content | 132 } // namespace content |
OLD | NEW |