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

Side by Side Diff: chrome/browser/android/thumbnail/thumbnail_cache.cc

Issue 2531673002: Use TaskScheduler instead of WorkerPool in thumbnail_cache.cc. (Closed)
Patch Set: CONTINUE_ON_SHUTDOWN Created 4 years 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/browser/android/thumbnail/thumbnail_cache.h" 5 #include "chrome/browser/android/thumbnail/thumbnail_cache.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/android/application_status_listener.h" 11 #include "base/android/application_status_listener.h"
12 #include "base/android/path_utils.h" 12 #include "base/android/path_utils.h"
13 #include "base/big_endian.h" 13 #include "base/big_endian.h"
14 #include "base/files/file.h" 14 #include "base/files/file.h"
15 #include "base/files/file_enumerator.h" 15 #include "base/files/file_enumerator.h"
16 #include "base/files/file_path.h" 16 #include "base/files/file_path.h"
17 #include "base/files/file_util.h" 17 #include "base/files/file_util.h"
18 #include "base/stl_util.h" 18 #include "base/stl_util.h"
19 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
20 #include "base/threading/worker_pool.h" 20 #include "base/task_scheduler/post_task.h"
21 #include "base/time/time.h" 21 #include "base/time/time.h"
22 #include "build/build_config.h" 22 #include "build/build_config.h"
23 #include "content/public/browser/browser_thread.h" 23 #include "content/public/browser/browser_thread.h"
24 #include "third_party/android_opengl/etc1/etc1.h" 24 #include "third_party/android_opengl/etc1/etc1.h"
25 #include "third_party/skia/include/core/SkBitmap.h" 25 #include "third_party/skia/include/core/SkBitmap.h"
26 #include "third_party/skia/include/core/SkCanvas.h" 26 #include "third_party/skia/include/core/SkCanvas.h"
27 #include "third_party/skia/include/core/SkData.h" 27 #include "third_party/skia/include/core/SkData.h"
28 #include "third_party/skia/include/core/SkMallocPixelRef.h" 28 #include "third_party/skia/include/core/SkMallocPixelRef.h"
29 #include "third_party/skia/include/core/SkPixelRef.h" 29 #include "third_party/skia/include/core/SkPixelRef.h"
30 #include "ui/android/resources/ui_resource_provider.h" 30 #include "ui/android/resources/ui_resource_provider.h"
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 post_compression_task = base::Bind(&ThumbnailCache::PostCompressionTask, 371 post_compression_task = base::Bind(&ThumbnailCache::PostCompressionTask,
372 weak_factory_.GetWeakPtr(), 372 weak_factory_.GetWeakPtr(),
373 tab_id, 373 tab_id,
374 time_stamp, 374 time_stamp,
375 scale); 375 scale);
376 376
377 gfx::Size raw_data_size(bitmap.width(), bitmap.height()); 377 gfx::Size raw_data_size(bitmap.width(), bitmap.height());
378 gfx::Size encoded_size = GetEncodedSize( 378 gfx::Size encoded_size = GetEncodedSize(
379 raw_data_size, ui_resource_provider_->SupportsETC1NonPowerOfTwo()); 379 raw_data_size, ui_resource_provider_->SupportsETC1NonPowerOfTwo());
380 380
381 base::WorkerPool::PostTask(FROM_HERE, 381 base::PostTaskWithTraits(
382 base::Bind(&ThumbnailCache::CompressionTask, 382 FROM_HERE, base::TaskTraits()
383 bitmap, 383 .WithPriority(base::TaskPriority::BACKGROUND)
384 encoded_size, 384 .WithShutdownBehavior(
385 post_compression_task), 385 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN),
386 true); 386 base::Bind(&ThumbnailCache::CompressionTask, bitmap, encoded_size,
387 post_compression_task));
387 } 388 }
388 389
389 void ThumbnailCache::ReadNextThumbnail() { 390 void ThumbnailCache::ReadNextThumbnail() {
390 if (read_queue_.empty() || read_in_progress_) 391 if (read_queue_.empty() || read_in_progress_)
391 return; 392 return;
392 393
393 TabId tab_id = read_queue_.front(); 394 TabId tab_id = read_queue_.front();
394 read_in_progress_ = true; 395 read_in_progress_ = true;
395 396
396 base::Callback<void(sk_sp<SkPixelRef>, float, const gfx::Size&)> 397 base::Callback<void(sk_sp<SkPixelRef>, float, const gfx::Size&)>
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
768 769
769 if (!valid_contents) { 770 if (!valid_contents) {
770 content_size.SetSize(0, 0); 771 content_size.SetSize(0, 0);
771 scale = 0.f; 772 scale = 0.f;
772 compressed_data.reset(); 773 compressed_data.reset();
773 base::DeleteFile(file_path, false); 774 base::DeleteFile(file_path, false);
774 } 775 }
775 } 776 }
776 777
777 if (decompress) { 778 if (decompress) {
778 base::WorkerPool::PostTask( 779 base::PostTaskWithTraits(
779 FROM_HERE, 780 FROM_HERE,
781 base::TaskTraits().WithPriority(base::TaskPriority::BACKGROUND),
780 base::Bind(post_read_task, std::move(compressed_data), scale, 782 base::Bind(post_read_task, std::move(compressed_data), scale,
781 content_size), 783 content_size));
782 true);
783 } else { 784 } else {
784 content::BrowserThread::PostTask( 785 content::BrowserThread::PostTask(
785 content::BrowserThread::UI, 786 content::BrowserThread::UI,
786 FROM_HERE, 787 FROM_HERE,
787 base::Bind(post_read_task, std::move(compressed_data), scale, 788 base::Bind(post_read_task, std::move(compressed_data), scale,
788 content_size)); 789 content_size));
789 } 790 }
790 } 791 }
791 792
792 void ThumbnailCache::PostReadTask(TabId tab_id, 793 void ThumbnailCache::PostReadTask(TabId tab_id,
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
933 return std::make_pair(dst_bitmap, new_scale * scale); 934 return std::make_pair(dst_bitmap, new_scale * scale);
934 } 935 }
935 936
936 void ThumbnailCache::OnMemoryPressure( 937 void ThumbnailCache::OnMemoryPressure(
937 base::MemoryPressureListener::MemoryPressureLevel level) { 938 base::MemoryPressureListener::MemoryPressureLevel level) {
938 if (level == base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { 939 if (level == base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) {
939 cache_.Clear(); 940 cache_.Clear();
940 approximation_cache_.Clear(); 941 approximation_cache_.Clear();
941 } 942 }
942 } 943 }
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