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

Side by Side Diff: third_party/WebKit/Source/platform/testing/weburl_loader_mock_factory_impl.cc

Issue 2831033002: Use unique_ptr for Platform::CreateURLLoader (Closed)
Patch Set: Created 3 years, 8 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/testing/weburl_loader_mock_factory_impl.h" 5 #include "platform/testing/weburl_loader_mock_factory_impl.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/memory/ptr_util.h"
10 #include "base/run_loop.h" 11 #include "base/run_loop.h"
11 #include "platform/loader/fetch/MemoryCache.h" 12 #include "platform/loader/fetch/MemoryCache.h"
12 #include "platform/testing/TestingPlatformSupport.h" 13 #include "platform/testing/TestingPlatformSupport.h"
13 #include "platform/testing/UnitTestHelpers.h" 14 #include "platform/testing/UnitTestHelpers.h"
14 #include "platform/testing/weburl_loader_mock.h" 15 #include "platform/testing/weburl_loader_mock.h"
15 #include "platform/wtf/PtrUtil.h" 16 #include "platform/wtf/PtrUtil.h"
16 #include "public/platform/FilePathConversion.h" 17 #include "public/platform/FilePathConversion.h"
17 #include "public/platform/Platform.h" 18 #include "public/platform/Platform.h"
18 #include "public/platform/WebString.h" 19 #include "public/platform/WebString.h"
19 #include "public/platform/WebURLError.h" 20 #include "public/platform/WebURLError.h"
20 #include "public/platform/WebURLRequest.h" 21 #include "public/platform/WebURLRequest.h"
21 #include "public/platform/WebURLResponse.h" 22 #include "public/platform/WebURLResponse.h"
22 23
23 namespace blink { 24 namespace blink {
24 25
25 std::unique_ptr<WebURLLoaderMockFactory> WebURLLoaderMockFactory::Create() { 26 std::unique_ptr<WebURLLoaderMockFactory> WebURLLoaderMockFactory::Create() {
26 return WTF::WrapUnique(new WebURLLoaderMockFactoryImpl(nullptr)); 27 return WTF::WrapUnique(new WebURLLoaderMockFactoryImpl(nullptr));
27 } 28 }
28 29
29 WebURLLoaderMockFactoryImpl::WebURLLoaderMockFactoryImpl( 30 WebURLLoaderMockFactoryImpl::WebURLLoaderMockFactoryImpl(
30 TestingPlatformSupport* platform) 31 TestingPlatformSupport* platform)
31 : platform_(platform) {} 32 : platform_(platform) {}
32 33
33 WebURLLoaderMockFactoryImpl::~WebURLLoaderMockFactoryImpl() {} 34 WebURLLoaderMockFactoryImpl::~WebURLLoaderMockFactoryImpl() {}
34 35
35 WebURLLoader* WebURLLoaderMockFactoryImpl::CreateURLLoader( 36 std::unique_ptr<WebURLLoader> WebURLLoaderMockFactoryImpl::CreateURLLoader(
36 WebURLLoader* default_loader) { 37 std::unique_ptr<WebURLLoader> default_loader) {
37 return new WebURLLoaderMock(this, default_loader); 38 return base::MakeUnique<WebURLLoaderMock>(this, std::move(default_loader));
38 } 39 }
39 40
40 void WebURLLoaderMockFactoryImpl::RegisterURL(const WebURL& url, 41 void WebURLLoaderMockFactoryImpl::RegisterURL(const WebURL& url,
41 const WebURLResponse& response, 42 const WebURLResponse& response,
42 const WebString& file_path) { 43 const WebString& file_path) {
43 ResponseInfo response_info; 44 ResponseInfo response_info;
44 response_info.response = response; 45 response_info.response = response;
45 if (!file_path.IsNull() && !file_path.IsEmpty()) { 46 if (!file_path.IsNull() && !file_path.IsEmpty()) {
46 response_info.file_path = blink::WebStringToFilePath(file_path); 47 response_info.file_path = blink::WebStringToFilePath(file_path);
47 DCHECK(base::PathExists(response_info.file_path)) 48 DCHECK(base::PathExists(response_info.file_path))
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 176
176 std::string buffer; 177 std::string buffer;
177 if (!base::ReadFileToString(file_path, &buffer)) 178 if (!base::ReadFileToString(file_path, &buffer))
178 return false; 179 return false;
179 180
180 data->Assign(buffer.data(), buffer.size()); 181 data->Assign(buffer.data(), buffer.size());
181 return true; 182 return true;
182 } 183 }
183 184
184 } // namespace blink 185 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698