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

Side by Side Diff: third_party/WebKit/Source/core/html/canvas/CanvasAsyncBlobCreator.cpp

Issue 2069533002: Have CanvasAsyncBlobCreator's delayed task keep a weak |this| also. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 | « no previous file | 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 // 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 "core/html/canvas/CanvasAsyncBlobCreator.h" 5 #include "core/html/canvas/CanvasAsyncBlobCreator.h"
6 6
7 #include "core/fileapi/Blob.h" 7 #include "core/fileapi/Blob.h"
8 #include "platform/ThreadSafeFunctional.h" 8 #include "platform/ThreadSafeFunctional.h"
9 #include "platform/graphics/ImageBuffer.h" 9 #include "platform/graphics/ImageBuffer.h"
10 #include "platform/image-encoders/JPEGImageEncoder.h" 10 #include "platform/image-encoders/JPEGImageEncoder.h"
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 } else if (m_mimeType == MimeTypeJpeg) { 111 } else if (m_mimeType == MimeTypeJpeg) {
112 this->scheduleInitiateJpegEncoding(quality); 112 this->scheduleInitiateJpegEncoding(quality);
113 } else { 113 } else {
114 // Progressive encoding is only applicable to png and jpeg image for mat, 114 // Progressive encoding is only applicable to png and jpeg image for mat,
115 // and thus idle tasks scheduling can only be applied to these image formats. 115 // and thus idle tasks scheduling can only be applied to these image formats.
116 // TODO(xlai): Progressive encoding on webp image formats (crbug.com /571399) 116 // TODO(xlai): Progressive encoding on webp image formats (crbug.com /571399)
117 ASSERT_NOT_REACHED(); 117 ASSERT_NOT_REACHED();
118 } 118 }
119 // We post the below task to check if the above idle task isn't late. 119 // We post the below task to check if the above idle task isn't late.
120 // There's no risk of concurrency as both tasks are on main thread. 120 // There's no risk of concurrency as both tasks are on main thread.
121 this->postDelayedTaskToMainThread(BLINK_FROM_HERE, bind(&CanvasAsyncBlob Creator::idleTaskStartTimeoutEvent, this, quality), IdleTaskStartTimeoutDelay); 121 this->postDelayedTaskToMainThread(BLINK_FROM_HERE, bind(&CanvasAsyncBlob Creator::idleTaskStartTimeoutEvent, WeakPersistentThisPointer<CanvasAsyncBlobCre ator>(this), quality), IdleTaskStartTimeoutDelay);
122 } else if (m_mimeType == MimeTypeWebp) { 122 } else if (m_mimeType == MimeTypeWebp) {
123 BackgroundTaskRunner::TaskSize taskSize = (m_size.height() * m_size.widt h() >= LongTaskImageSizeThreshold) ? BackgroundTaskRunner::TaskSizeLongRunningTa sk : BackgroundTaskRunner::TaskSizeShortRunningTask; 123 BackgroundTaskRunner::TaskSize taskSize = (m_size.height() * m_size.widt h() >= LongTaskImageSizeThreshold) ? BackgroundTaskRunner::TaskSizeLongRunningTa sk : BackgroundTaskRunner::TaskSizeShortRunningTask;
124 BackgroundTaskRunner::postOnBackgroundThread(BLINK_FROM_HERE, threadSafe Bind(&CanvasAsyncBlobCreator::encodeImageOnEncoderThread, wrapCrossThreadPersist ent(this), quality), taskSize); 124 BackgroundTaskRunner::postOnBackgroundThread(BLINK_FROM_HERE, threadSafe Bind(&CanvasAsyncBlobCreator::encodeImageOnEncoderThread, wrapCrossThreadPersist ent(this), quality), taskSize);
125 } 125 }
126 } 126 }
127 127
128 void CanvasAsyncBlobCreator::scheduleInitiateJpegEncoding(const double& quality) 128 void CanvasAsyncBlobCreator::scheduleInitiateJpegEncoding(const double& quality)
129 { 129 {
130 Platform::current()->mainThread()->scheduler()->postIdleTask(BLINK_FROM_HERE , bind<double>(&CanvasAsyncBlobCreator::initiateJpegEncoding, WeakPersistentThis Pointer<CanvasAsyncBlobCreator>(this), quality)); 130 Platform::current()->mainThread()->scheduler()->postIdleTask(BLINK_FROM_HERE , bind<double>(&CanvasAsyncBlobCreator::initiateJpegEncoding, WeakPersistentThis Pointer<CanvasAsyncBlobCreator>(this), quality));
131 } 131 }
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 } 353 }
354 } 354 }
355 355
356 void CanvasAsyncBlobCreator::postDelayedTaskToMainThread(const WebTraceLocation& location, std::unique_ptr<SameThreadClosure> task, double delayMs) 356 void CanvasAsyncBlobCreator::postDelayedTaskToMainThread(const WebTraceLocation& location, std::unique_ptr<SameThreadClosure> task, double delayMs)
357 { 357 {
358 DCHECK(isMainThread()); 358 DCHECK(isMainThread());
359 Platform::current()->mainThread()->getWebTaskRunner()->postDelayedTask(locat ion, std::move(task), delayMs); 359 Platform::current()->mainThread()->getWebTaskRunner()->postDelayedTask(locat ion, std::move(task), delayMs);
360 } 360 }
361 361
362 } // namespace blink 362 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698