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

Side by Side Diff: third_party/WebKit/Source/platform/inspector_protocol/DispatcherBase.cpp

Issue 2087953004: Switch v8 inspector to stl collections (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 5 months 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "platform/inspector_protocol/DispatcherBase.h" 5 #include "platform/inspector_protocol/DispatcherBase.h"
6 6
7 #include "platform/inspector_protocol/FrontendChannel.h" 7 #include "platform/inspector_protocol/FrontendChannel.h"
8 #include "platform/inspector_protocol/Parser.h" 8 #include "platform/inspector_protocol/Parser.h"
9 9
10 namespace blink { 10 namespace blink {
11 namespace protocol { 11 namespace protocol {
12 12
13 // static 13 // static
14 const char DispatcherBase::kInvalidRequest[] = "Invalid request"; 14 const char DispatcherBase::kInvalidRequest[] = "Invalid request";
15 15
16 DispatcherBase::WeakPtr::WeakPtr(DispatcherBase* dispatcher) : m_dispatcher(disp atcher) { } 16 DispatcherBase::WeakPtr::WeakPtr(DispatcherBase* dispatcher) : m_dispatcher(disp atcher) { }
17 17
18 DispatcherBase::WeakPtr::~WeakPtr() 18 DispatcherBase::WeakPtr::~WeakPtr()
19 { 19 {
20 if (m_dispatcher) 20 if (m_dispatcher)
21 m_dispatcher->m_weakPtrs.remove(this); 21 m_dispatcher->m_weakPtrs.erase(this);
22 } 22 }
23 23
24 DispatcherBase::Callback::Callback(std::unique_ptr<DispatcherBase::WeakPtr> back endImpl, int callId) 24 DispatcherBase::Callback::Callback(std::unique_ptr<DispatcherBase::WeakPtr> back endImpl, int callId)
25 : m_backendImpl(std::move(backendImpl)) 25 : m_backendImpl(std::move(backendImpl))
26 , m_callId(callId) { } 26 , m_callId(callId) { }
27 27
28 DispatcherBase::Callback::~Callback() = default; 28 DispatcherBase::Callback::~Callback() = default;
29 29
30 void DispatcherBase::Callback::dispose() 30 void DispatcherBase::Callback::dispose()
31 { 31 {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 void DispatcherBase::reportProtocolError(int callId, CommonErrorCode code, const String16& errorMessage, ErrorSupport* errors) 106 void DispatcherBase::reportProtocolError(int callId, CommonErrorCode code, const String16& errorMessage, ErrorSupport* errors)
107 { 107 {
108 if (m_frontendChannel) 108 if (m_frontendChannel)
109 ::blink::protocol::reportProtocolError(m_frontendChannel, callId, code, errorMessage, errors); 109 ::blink::protocol::reportProtocolError(m_frontendChannel, callId, code, errorMessage, errors);
110 } 110 }
111 111
112 void DispatcherBase::clearFrontend() 112 void DispatcherBase::clearFrontend()
113 { 113 {
114 m_frontendChannel = nullptr; 114 m_frontendChannel = nullptr;
115 for (auto& weak : m_weakPtrs) 115 for (auto& weak : m_weakPtrs)
116 weak.first->dispose(); 116 weak->dispose();
117 m_weakPtrs.clear(); 117 m_weakPtrs.clear();
118 } 118 }
119 119
120 std::unique_ptr<DispatcherBase::WeakPtr> DispatcherBase::weakPtr() 120 std::unique_ptr<DispatcherBase::WeakPtr> DispatcherBase::weakPtr()
121 { 121 {
122 std::unique_ptr<DispatcherBase::WeakPtr> weak(new DispatcherBase::WeakPtr(th is)); 122 std::unique_ptr<DispatcherBase::WeakPtr> weak(new DispatcherBase::WeakPtr(th is));
123 m_weakPtrs.add(weak.get()); 123 m_weakPtrs.insert(weak.get());
124 return weak; 124 return weak;
125 } 125 }
126 126
127 UberDispatcher::UberDispatcher(FrontendChannel* frontendChannel) 127 UberDispatcher::UberDispatcher(FrontendChannel* frontendChannel)
128 : m_frontendChannel(frontendChannel) { } 128 : m_frontendChannel(frontendChannel) { }
129 129
130 void UberDispatcher::registerBackend(const String16& name, std::unique_ptr<proto col::DispatcherBase> dispatcher) 130 void UberDispatcher::registerBackend(const String16& name, std::unique_ptr<proto col::DispatcherBase> dispatcher)
131 { 131 {
132 m_dispatchers.set(name, std::move(dispatcher)); 132 m_dispatchers[name] = std::move(dispatcher);
133 } 133 }
134 134
135 void UberDispatcher::dispatch(const String16& message) 135 void UberDispatcher::dispatch(const String16& message)
136 { 136 {
137 std::unique_ptr<protocol::Value> parsedMessage = parseJSON(message); 137 std::unique_ptr<protocol::Value> parsedMessage = parseJSON(message);
138 if (!parsedMessage) 138 if (!parsedMessage)
139 return; 139 return;
140 std::unique_ptr<protocol::DictionaryValue> messageObject = DictionaryValue:: cast(std::move(parsedMessage)); 140 std::unique_ptr<protocol::DictionaryValue> messageObject = DictionaryValue:: cast(std::move(parsedMessage));
141 if (!messageObject) 141 if (!messageObject)
142 return; 142 return;
(...skipping 21 matching lines...) Expand all
164 reportProtocolError(m_frontendChannel, callId, DispatcherBase::MethodNot Found, "'" + method + "' wasn't found", nullptr); 164 reportProtocolError(m_frontendChannel, callId, DispatcherBase::MethodNot Found, "'" + method + "' wasn't found", nullptr);
165 return; 165 return;
166 } 166 }
167 it->second->dispatch(callId, method, std::move(messageObject)); 167 it->second->dispatch(callId, method, std::move(messageObject));
168 } 168 }
169 169
170 UberDispatcher::~UberDispatcher() = default; 170 UberDispatcher::~UberDispatcher() = default;
171 171
172 } // namespace protocol 172 } // namespace protocol
173 } // namespace blink 173 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698