OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/browser/frame_host/navigation_entry_screenshot_manager.h" | 5 #include "content/browser/frame_host/navigation_entry_screenshot_manager.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/threading/worker_pool.h" | 9 #include "base/task_scheduler/post_task.h" |
10 #include "content/browser/frame_host/navigation_controller_impl.h" | 10 #include "content/browser/frame_host/navigation_controller_impl.h" |
11 #include "content/browser/frame_host/navigation_entry_impl.h" | 11 #include "content/browser/frame_host/navigation_entry_impl.h" |
12 #include "content/browser/renderer_host/render_view_host_impl.h" | 12 #include "content/browser/renderer_host/render_view_host_impl.h" |
13 #include "content/public/browser/overscroll_configuration.h" | 13 #include "content/public/browser/overscroll_configuration.h" |
14 #include "content/public/browser/render_widget_host.h" | 14 #include "content/public/browser/render_widget_host.h" |
15 #include "content/public/browser/render_widget_host_view.h" | 15 #include "content/public/browser/render_widget_host_view.h" |
16 #include "content/public/common/content_switches.h" | 16 #include "content/public/common/content_switches.h" |
17 #include "ui/gfx/codec/png_codec.h" | 17 #include "ui/gfx/codec/png_codec.h" |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 // Minimum delay between taking screenshots. | 21 // Minimum delay between taking screenshots. |
22 const int kMinScreenshotIntervalMS = 1000; | 22 const int kMinScreenshotIntervalMS = 1000; |
23 | 23 |
24 } | 24 } |
25 | 25 |
26 namespace content { | 26 namespace content { |
27 | 27 |
28 // Encodes the A8 SkBitmap to grayscale PNG in a worker thread. | 28 // Encodes the A8 SkBitmap to grayscale PNG in a worker thread. |
29 class ScreenshotData : public base::RefCountedThreadSafe<ScreenshotData> { | 29 class ScreenshotData : public base::RefCountedThreadSafe<ScreenshotData> { |
30 public: | 30 public: |
31 ScreenshotData() { | 31 ScreenshotData() { |
32 } | 32 } |
33 | 33 |
34 void EncodeScreenshot(const SkBitmap& bitmap, base::Closure callback) { | 34 void EncodeScreenshot(const SkBitmap& bitmap, base::Closure callback) { |
35 if (!base::WorkerPool::PostTaskAndReply(FROM_HERE, | 35 base::PostTaskWithTraitsAndReply( |
36 base::Bind(&ScreenshotData::EncodeOnWorker, | 36 FROM_HERE, base::TaskTraits().WithShutdownBehavior( |
37 this, | 37 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN), |
38 bitmap), | 38 base::Bind(&ScreenshotData::EncodeOnWorker, this, bitmap), callback); |
39 callback, | |
40 true)) { | |
alexmos
2017/01/03 19:19:06
Is there's an equivalent to task_is_slow in TaskSc
fdoray
2017/01/04 00:27:09
|task_is_slow| is ignored by WorkerPool and develo
alexmos
2017/01/04 01:00:08
At least on Windows, it seems to be used to add WT
fdoray
2017/01/04 02:13:15
Our experiments show that this flag is ignored on
| |
41 callback.Run(); | |
42 } | |
43 } | 39 } |
44 | 40 |
45 scoped_refptr<base::RefCountedBytes> data() const { return data_; } | 41 scoped_refptr<base::RefCountedBytes> data() const { return data_; } |
46 | 42 |
47 private: | 43 private: |
48 friend class base::RefCountedThreadSafe<ScreenshotData>; | 44 friend class base::RefCountedThreadSafe<ScreenshotData>; |
49 virtual ~ScreenshotData() { | 45 virtual ~ScreenshotData() { |
50 } | 46 } |
51 | 47 |
52 void EncodeOnWorker(const SkBitmap& bitmap) { | 48 void EncodeOnWorker(const SkBitmap& bitmap) { |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
247 NavigationEntryImpl* entry = owner_->GetEntryAtIndex(forward); | 243 NavigationEntryImpl* entry = owner_->GetEntryAtIndex(forward); |
248 if (ClearScreenshot(entry)) | 244 if (ClearScreenshot(entry)) |
249 --screenshot_count; | 245 --screenshot_count; |
250 ++forward; | 246 ++forward; |
251 } | 247 } |
252 CHECK_GE(screenshot_count, 0); | 248 CHECK_GE(screenshot_count, 0); |
253 CHECK_LE(screenshot_count, kMaxScreenshots); | 249 CHECK_LE(screenshot_count, kMaxScreenshots); |
254 } | 250 } |
255 | 251 |
256 } // namespace content | 252 } // namespace content |
OLD | NEW |