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

Side by Side Diff: third_party/WebKit/Source/core/fileapi/FileReaderLoader.cpp

Issue 2837873007: Tell V8 about the extra memory being held by FileReader objects. (Closed)
Patch Set: rebase Created 3 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
« no previous file with comments | « third_party/WebKit/Source/core/fileapi/FileReaderLoader.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #include "platform/loader/fetch/ResourceError.h" 43 #include "platform/loader/fetch/ResourceError.h"
44 #include "platform/loader/fetch/ResourceRequest.h" 44 #include "platform/loader/fetch/ResourceRequest.h"
45 #include "platform/loader/fetch/ResourceResponse.h" 45 #include "platform/loader/fetch/ResourceResponse.h"
46 #include "platform/wtf/PassRefPtr.h" 46 #include "platform/wtf/PassRefPtr.h"
47 #include "platform/wtf/PtrUtil.h" 47 #include "platform/wtf/PtrUtil.h"
48 #include "platform/wtf/RefPtr.h" 48 #include "platform/wtf/RefPtr.h"
49 #include "platform/wtf/Vector.h" 49 #include "platform/wtf/Vector.h"
50 #include "platform/wtf/text/Base64.h" 50 #include "platform/wtf/text/Base64.h"
51 #include "platform/wtf/text/StringBuilder.h" 51 #include "platform/wtf/text/StringBuilder.h"
52 #include "public/platform/WebURLRequest.h" 52 #include "public/platform/WebURLRequest.h"
53 #include "v8/include/v8.h"
53 54
54 namespace blink { 55 namespace blink {
55 56
56 FileReaderLoader::FileReaderLoader(ReadType read_type, 57 FileReaderLoader::FileReaderLoader(ReadType read_type,
57 FileReaderLoaderClient* client) 58 FileReaderLoaderClient* client)
58 : read_type_(read_type), 59 : read_type_(read_type),
59 client_(client), 60 client_(client),
60 is_raw_data_converted_(false), 61 is_raw_data_converted_(false),
61 string_result_(""), 62 string_result_(""),
62 finished_loading_(false), 63 finished_loading_(false),
63 bytes_loaded_(0), 64 bytes_loaded_(0),
64 total_bytes_(-1), 65 total_bytes_(-1),
65 has_range_(false), 66 has_range_(false),
66 range_start_(0), 67 range_start_(0),
67 range_end_(0), 68 range_end_(0),
68 error_code_(FileError::kOK) {} 69 error_code_(FileError::kOK) {}
69 70
70 FileReaderLoader::~FileReaderLoader() { 71 FileReaderLoader::~FileReaderLoader() {
71 Cleanup(); 72 Cleanup();
73 UnreportMemoryUsageToV8();
72 if (!url_for_reading_.IsEmpty()) { 74 if (!url_for_reading_.IsEmpty()) {
73 BlobRegistry::RevokePublicBlobURL(url_for_reading_); 75 BlobRegistry::RevokePublicBlobURL(url_for_reading_);
74 } 76 }
75 } 77 }
76 78
77 void FileReaderLoader::Start(ExecutionContext* execution_context, 79 void FileReaderLoader::Start(ExecutionContext* execution_context,
78 PassRefPtr<BlobDataHandle> blob_data) { 80 PassRefPtr<BlobDataHandle> blob_data) {
79 DCHECK(execution_context); 81 DCHECK(execution_context);
80 // The blob is read by routing through the request handling layer given a 82 // The blob is read by routing through the request handling layer given a
81 // temporary public url. 83 // temporary public url.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 loader_->Cancel(); 138 loader_->Cancel();
137 loader_ = nullptr; 139 loader_ = nullptr;
138 } 140 }
139 141
140 // If we get any error, we do not need to keep a buffer around. 142 // If we get any error, we do not need to keep a buffer around.
141 if (error_code_) { 143 if (error_code_) {
142 raw_data_.reset(); 144 raw_data_.reset();
143 string_result_ = ""; 145 string_result_ = "";
144 is_raw_data_converted_ = true; 146 is_raw_data_converted_ = true;
145 decoder_.reset(); 147 decoder_.reset();
148 UnreportMemoryUsageToV8();
146 } 149 }
147 } 150 }
148 151
152 void FileReaderLoader::ReportAdditionalMemoryUsageToV8(int64_t usage) {
153 memory_usage_reported_to_v8_ += usage;
154 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(usage);
155 }
156
157 void FileReaderLoader::UnreportMemoryUsageToV8() {
158 if (!memory_usage_reported_to_v8_)
159 return;
160 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(
161 -memory_usage_reported_to_v8_);
162 memory_usage_reported_to_v8_ = 0;
163 }
164
149 void FileReaderLoader::DidReceiveResponse( 165 void FileReaderLoader::DidReceiveResponse(
150 unsigned long, 166 unsigned long,
151 const ResourceResponse& response, 167 const ResourceResponse& response,
152 std::unique_ptr<WebDataConsumerHandle> handle) { 168 std::unique_ptr<WebDataConsumerHandle> handle) {
153 DCHECK(!handle); 169 DCHECK(!handle);
154 if (response.HttpStatusCode() != 200) { 170 if (response.HttpStatusCode() != 200) {
155 Failed(HttpStatusCodeToErrorCode(response.HttpStatusCode())); 171 Failed(HttpStatusCodeToErrorCode(response.HttpStatusCode()));
156 return; 172 return;
157 } 173 }
158 174
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 239
224 unsigned bytes_appended = raw_data_->Append(data, data_length); 240 unsigned bytes_appended = raw_data_->Append(data, data_length);
225 if (!bytes_appended) { 241 if (!bytes_appended) {
226 raw_data_.reset(); 242 raw_data_.reset();
227 bytes_loaded_ = 0; 243 bytes_loaded_ = 0;
228 Failed(FileError::kNotReadableErr); 244 Failed(FileError::kNotReadableErr);
229 return; 245 return;
230 } 246 }
231 bytes_loaded_ += bytes_appended; 247 bytes_loaded_ += bytes_appended;
232 is_raw_data_converted_ = false; 248 is_raw_data_converted_ = false;
249 ReportAdditionalMemoryUsageToV8(bytes_appended);
233 250
234 if (client_) 251 if (client_)
235 client_->DidReceiveData(); 252 client_->DidReceiveData();
236 } 253 }
237 254
238 void FileReaderLoader::DidFinishLoading(unsigned long, double) { 255 void FileReaderLoader::DidFinishLoading(unsigned long, double) {
239 if (read_type_ != kReadByClient && raw_data_) { 256 if (read_type_ != kReadByClient && raw_data_) {
240 raw_data_->ShrinkToFit(); 257 raw_data_->ShrinkToFit();
241 is_raw_data_converted_ = false; 258 is_raw_data_converted_ = false;
242 } 259 }
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 break; 342 break;
326 case kReadAsDataURL: 343 case kReadAsDataURL:
327 // Partial data is not supported when reading as data URL. 344 // Partial data is not supported when reading as data URL.
328 if (finished_loading_) 345 if (finished_loading_)
329 ConvertToDataURL(); 346 ConvertToDataURL();
330 break; 347 break;
331 default: 348 default:
332 NOTREACHED(); 349 NOTREACHED();
333 } 350 }
334 351
352 if (finished_loading_)
dmurph 2017/04/27 21:57:12 To make this more clear, can you have the two Conv
michaeln 2017/04/28 00:54:25 ok, i made it more accurate and thnx for pointing
353 ReportAdditionalMemoryUsageToV8(string_result_.CharactersSizeInBytes());
335 return string_result_; 354 return string_result_;
336 } 355 }
337 356
338 void FileReaderLoader::ConvertToText() { 357 void FileReaderLoader::ConvertToText() {
339 is_raw_data_converted_ = true; 358 is_raw_data_converted_ = true;
340 359
341 if (!bytes_loaded_) { 360 if (!bytes_loaded_) {
342 string_result_ = ""; 361 string_result_ = "";
343 return; 362 return;
344 } 363 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 403
385 string_result_ = builder.ToString(); 404 string_result_ = builder.ToString();
386 } 405 }
387 406
388 void FileReaderLoader::SetEncoding(const String& encoding) { 407 void FileReaderLoader::SetEncoding(const String& encoding) {
389 if (!encoding.IsEmpty()) 408 if (!encoding.IsEmpty())
390 encoding_ = WTF::TextEncoding(encoding); 409 encoding_ = WTF::TextEncoding(encoding);
391 } 410 }
392 411
393 } // namespace blink 412 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fileapi/FileReaderLoader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698