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

Side by Side Diff: third_party/WebKit/Source/modules/storage/InspectorDOMStorageAgent.cpp

Issue 2004313003: DevTools: migrate from OwnPtr to std::unique_ptr for inspector protocol classes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebaselined Created 4 years, 7 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 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * Copyright (C) 2013 Samsung Electronics. All rights reserved. 3 * Copyright (C) 2013 Samsung Electronics. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 void InspectorDOMStorageAgent::disable(ErrorString*) 100 void InspectorDOMStorageAgent::disable(ErrorString*)
101 { 101 {
102 if (!m_isEnabled) 102 if (!m_isEnabled)
103 return; 103 return;
104 m_isEnabled = false; 104 m_isEnabled = false;
105 m_state->setBoolean(DOMStorageAgentState::domStorageAgentEnabled, false); 105 m_state->setBoolean(DOMStorageAgentState::domStorageAgentEnabled, false);
106 if (StorageNamespaceController* controller = StorageNamespaceController::fro m(m_page)) 106 if (StorageNamespaceController* controller = StorageNamespaceController::fro m(m_page))
107 controller->setInspectorAgent(nullptr); 107 controller->setInspectorAgent(nullptr);
108 } 108 }
109 109
110 void InspectorDOMStorageAgent::getDOMStorageItems(ErrorString* errorString, Pass OwnPtr<protocol::DOMStorage::StorageId> storageId, OwnPtr<protocol::Array<protoc ol::Array<String>>>* items) 110 void InspectorDOMStorageAgent::getDOMStorageItems(ErrorString* errorString, std: :unique_ptr<protocol::DOMStorage::StorageId> storageId, std::unique_ptr<protocol ::Array<protocol::Array<String>>>* items)
111 { 111 {
112 LocalFrame* frame; 112 LocalFrame* frame;
113 StorageArea* storageArea = findStorageArea(errorString, std::move(storageId) , frame); 113 StorageArea* storageArea = findStorageArea(errorString, std::move(storageId) , frame);
114 if (!storageArea) 114 if (!storageArea)
115 return; 115 return;
116 116
117 OwnPtr<protocol::Array<protocol::Array<String>>> storageItems = protocol::Ar ray<protocol::Array<String>>::create(); 117 std::unique_ptr<protocol::Array<protocol::Array<String>>> storageItems = pro tocol::Array<protocol::Array<String>>::create();
118 118
119 TrackExceptionState exceptionState; 119 TrackExceptionState exceptionState;
120 for (unsigned i = 0; i < storageArea->length(exceptionState, frame); ++i) { 120 for (unsigned i = 0; i < storageArea->length(exceptionState, frame); ++i) {
121 String name(storageArea->key(i, exceptionState, frame)); 121 String name(storageArea->key(i, exceptionState, frame));
122 if (hadException(exceptionState, errorString)) 122 if (hadException(exceptionState, errorString))
123 return; 123 return;
124 String value(storageArea->getItem(name, exceptionState, frame)); 124 String value(storageArea->getItem(name, exceptionState, frame));
125 if (hadException(exceptionState, errorString)) 125 if (hadException(exceptionState, errorString))
126 return; 126 return;
127 OwnPtr<protocol::Array<String>> entry = protocol::Array<String>::create( ); 127 std::unique_ptr<protocol::Array<String>> entry = protocol::Array<String> ::create();
128 entry->addItem(name); 128 entry->addItem(name);
129 entry->addItem(value); 129 entry->addItem(value);
130 storageItems->addItem(std::move(entry)); 130 storageItems->addItem(std::move(entry));
131 } 131 }
132 *items = std::move(storageItems); 132 *items = std::move(storageItems);
133 } 133 }
134 134
135 static String toErrorString(ExceptionState& exceptionState) 135 static String toErrorString(ExceptionState& exceptionState)
136 { 136 {
137 if (exceptionState.hadException()) 137 if (exceptionState.hadException())
138 return DOMException::getErrorName(exceptionState.code()); 138 return DOMException::getErrorName(exceptionState.code());
139 return ""; 139 return "";
140 } 140 }
141 141
142 void InspectorDOMStorageAgent::setDOMStorageItem(ErrorString* errorString, PassO wnPtr<protocol::DOMStorage::StorageId> storageId, const String& key, const Strin g& value) 142 void InspectorDOMStorageAgent::setDOMStorageItem(ErrorString* errorString, std:: unique_ptr<protocol::DOMStorage::StorageId> storageId, const String& key, const String& value)
143 { 143 {
144 LocalFrame* frame; 144 LocalFrame* frame;
145 StorageArea* storageArea = findStorageArea(0, std::move(storageId), frame); 145 StorageArea* storageArea = findStorageArea(0, std::move(storageId), frame);
146 if (!storageArea) { 146 if (!storageArea) {
147 *errorString = "Storage not found"; 147 *errorString = "Storage not found";
148 return; 148 return;
149 } 149 }
150 150
151 TrackExceptionState exceptionState; 151 TrackExceptionState exceptionState;
152 storageArea->setItem(key, value, exceptionState, frame); 152 storageArea->setItem(key, value, exceptionState, frame);
153 *errorString = toErrorString(exceptionState); 153 *errorString = toErrorString(exceptionState);
154 } 154 }
155 155
156 void InspectorDOMStorageAgent::removeDOMStorageItem(ErrorString* errorString, Pa ssOwnPtr<protocol::DOMStorage::StorageId> storageId, const String& key) 156 void InspectorDOMStorageAgent::removeDOMStorageItem(ErrorString* errorString, st d::unique_ptr<protocol::DOMStorage::StorageId> storageId, const String& key)
157 { 157 {
158 LocalFrame* frame; 158 LocalFrame* frame;
159 StorageArea* storageArea = findStorageArea(0, std::move(storageId), frame); 159 StorageArea* storageArea = findStorageArea(0, std::move(storageId), frame);
160 if (!storageArea) { 160 if (!storageArea) {
161 *errorString = "Storage not found"; 161 *errorString = "Storage not found";
162 return; 162 return;
163 } 163 }
164 164
165 TrackExceptionState exceptionState; 165 TrackExceptionState exceptionState;
166 storageArea->removeItem(key, exceptionState, frame); 166 storageArea->removeItem(key, exceptionState, frame);
167 *errorString = toErrorString(exceptionState); 167 *errorString = toErrorString(exceptionState);
168 } 168 }
169 169
170 PassOwnPtr<protocol::DOMStorage::StorageId> InspectorDOMStorageAgent::storageId( SecurityOrigin* securityOrigin, bool isLocalStorage) 170 std::unique_ptr<protocol::DOMStorage::StorageId> InspectorDOMStorageAgent::stora geId(SecurityOrigin* securityOrigin, bool isLocalStorage)
171 { 171 {
172 return protocol::DOMStorage::StorageId::create() 172 return protocol::DOMStorage::StorageId::create()
173 .setSecurityOrigin(securityOrigin->toRawString()) 173 .setSecurityOrigin(securityOrigin->toRawString())
174 .setIsLocalStorage(isLocalStorage).build(); 174 .setIsLocalStorage(isLocalStorage).build();
175 } 175 }
176 176
177 void InspectorDOMStorageAgent::didDispatchDOMStorageEvent(const String& key, con st String& oldValue, const String& newValue, StorageType storageType, SecurityOr igin* securityOrigin) 177 void InspectorDOMStorageAgent::didDispatchDOMStorageEvent(const String& key, con st String& oldValue, const String& newValue, StorageType storageType, SecurityOr igin* securityOrigin)
178 { 178 {
179 if (!frontend()) 179 if (!frontend())
180 return; 180 return;
181 181
182 OwnPtr<protocol::DOMStorage::StorageId> id = storageId(securityOrigin, stora geType == LocalStorage); 182 std::unique_ptr<protocol::DOMStorage::StorageId> id = storageId(securityOrig in, storageType == LocalStorage);
183 183
184 if (key.isNull()) 184 if (key.isNull())
185 frontend()->domStorageItemsCleared(std::move(id)); 185 frontend()->domStorageItemsCleared(std::move(id));
186 else if (newValue.isNull()) 186 else if (newValue.isNull())
187 frontend()->domStorageItemRemoved(std::move(id), key); 187 frontend()->domStorageItemRemoved(std::move(id), key);
188 else if (oldValue.isNull()) 188 else if (oldValue.isNull())
189 frontend()->domStorageItemAdded(std::move(id), key, newValue); 189 frontend()->domStorageItemAdded(std::move(id), key, newValue);
190 else 190 else
191 frontend()->domStorageItemUpdated(std::move(id), key, oldValue, newValue ); 191 frontend()->domStorageItemUpdated(std::move(id), key, oldValue, newValue );
192 } 192 }
193 193
194 StorageArea* InspectorDOMStorageAgent::findStorageArea(ErrorString* errorString, PassOwnPtr<protocol::DOMStorage::StorageId> storageId, LocalFrame*& targetFrame ) 194 StorageArea* InspectorDOMStorageAgent::findStorageArea(ErrorString* errorString, std::unique_ptr<protocol::DOMStorage::StorageId> storageId, LocalFrame*& target Frame)
195 { 195 {
196 String securityOrigin = storageId->getSecurityOrigin(); 196 String securityOrigin = storageId->getSecurityOrigin();
197 bool isLocalStorage = storageId->getIsLocalStorage(); 197 bool isLocalStorage = storageId->getIsLocalStorage();
198 198
199 if (!m_page->mainFrame()->isLocalFrame()) 199 if (!m_page->mainFrame()->isLocalFrame())
200 return nullptr; 200 return nullptr;
201 201
202 InspectedFrames* inspectedFrames = InspectedFrames::create(m_page->deprecate dLocalMainFrame()); 202 InspectedFrames* inspectedFrames = InspectedFrames::create(m_page->deprecate dLocalMainFrame());
203 LocalFrame* frame = inspectedFrames->frameWithSecurityOrigin(securityOrigin) ; 203 LocalFrame* frame = inspectedFrames->frameWithSecurityOrigin(securityOrigin) ;
204 if (!frame) { 204 if (!frame) {
205 if (errorString) 205 if (errorString)
206 *errorString = "LocalFrame not found for the given security origin"; 206 *errorString = "LocalFrame not found for the given security origin";
207 return nullptr; 207 return nullptr;
208 } 208 }
209 targetFrame = frame; 209 targetFrame = frame;
210 210
211 if (isLocalStorage) 211 if (isLocalStorage)
212 return StorageNamespace::localStorageArea(frame->document()->getSecurity Origin()); 212 return StorageNamespace::localStorageArea(frame->document()->getSecurity Origin());
213 StorageNamespace* sessionStorage = StorageNamespaceController::from(m_page)- >sessionStorage(); 213 StorageNamespace* sessionStorage = StorageNamespaceController::from(m_page)- >sessionStorage();
214 if (!sessionStorage) { 214 if (!sessionStorage) {
215 if (errorString) 215 if (errorString)
216 *errorString = "SessionStorage is not supported"; 216 *errorString = "SessionStorage is not supported";
217 return nullptr; 217 return nullptr;
218 } 218 }
219 return sessionStorage->storageArea(frame->document()->getSecurityOrigin()); 219 return sessionStorage->storageArea(frame->document()->getSecurityOrigin());
220 } 220 }
221 221
222 } // namespace blink 222 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698