OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stdint.h> | 5 #include <stdint.h> |
6 #include <memory> | 6 #include <memory> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
12 #include "base/files/scoped_temp_dir.h" | 12 #include "base/files/scoped_temp_dir.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "base/test/histogram_tester.h" | 16 #include "base/test/histogram_tester.h" |
17 #include "base/threading/thread_restrictions.h" | 17 #include "base/threading/thread_restrictions.h" |
18 #include "content/browser/download/download_task_runner.h" | |
18 #include "content/browser/renderer_host/render_process_host_impl.h" | 19 #include "content/browser/renderer_host/render_process_host_impl.h" |
19 #include "content/common/frame_messages.h" | 20 #include "content/common/frame_messages.h" |
20 #include "content/public/browser/mhtml_extra_parts.h" | 21 #include "content/public/browser/mhtml_extra_parts.h" |
21 #include "content/public/browser/render_frame_host.h" | 22 #include "content/public/browser/render_frame_host.h" |
22 #include "content/public/browser/render_process_host.h" | 23 #include "content/public/browser/render_process_host.h" |
23 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
24 #include "content/public/common/mhtml_generation_params.h" | 25 #include "content/public/common/mhtml_generation_params.h" |
25 #include "content/public/test/browser_test_utils.h" | 26 #include "content/public/test/browser_test_utils.h" |
26 #include "content/public/test/content_browser_test.h" | 27 #include "content/public/test/content_browser_test.h" |
27 #include "content/public/test/content_browser_test_utils.h" | 28 #include "content/public/test/content_browser_test_utils.h" |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
269 render_process_host_(render_process_host) {} | 270 render_process_host_(render_process_host) {} |
270 | 271 |
271 protected: | 272 protected: |
272 ~GenerateMHTMLAndExitRendererMessageFilter() override {} | 273 ~GenerateMHTMLAndExitRendererMessageFilter() override {} |
273 | 274 |
274 private: | 275 private: |
275 bool OnMessageReceived(const IPC::Message& message) override { | 276 bool OnMessageReceived(const IPC::Message& message) override { |
276 if (message.type() == FrameHostMsg_SerializeAsMHTMLResponse::ID) { | 277 if (message.type() == FrameHostMsg_SerializeAsMHTMLResponse::ID) { |
277 // After |return false| below, this IPC message will be handled by the | 278 // After |return false| below, this IPC message will be handled by the |
278 // product code as illustrated below. (1), (2), (3) depict points in time | 279 // product code as illustrated below. (1), (2), (3) depict points in time |
279 // when product code runs on UI and FILE threads. (X), (Y), (Z) depict | 280 // when product code runs on UI thread and download sequence. (X), (Y), |
280 // when we want test-injected tasks to run - for the repro, (Z) has to | 281 // (Z) depict when we want test-injected tasks to run - for the repro, (Z) |
281 // happen between (1) and (3). (Y?) and (Z?) depict when test tasks can | 282 // has to happen between (1) and (3). (Y?) and (Z?) depict when test |
282 // theoretically happen and ruin the repro. | 283 // tasks can theoretically happen and ruin the repro. |
283 // | 284 // |
284 // IO thread UI thread FILE thread | 285 // IO thread UI thread download sequence |
285 // --------- --------- ----------- | 286 // --------- --------- ----------- |
286 // | | | | 287 // | | | |
287 // WE ARE HERE | | | 288 // WE ARE HERE | | |
288 // | | | | 289 // | | | |
289 // after |return false| | | | 290 // after |return false| | | |
290 // +--------------->+ | | 291 // +--------------->+ | |
291 // | | | | 292 // | | | |
292 // | (X) | | 293 // | (X) | |
293 // | | | | 294 // | | | |
294 // | | (Y?) | 295 // | | (Y?) |
(...skipping 17 matching lines...) Expand all Loading... | |
312 // | +<--------------------+ | 313 // | +<--------------------+ |
313 // | | | | 314 // | | | |
314 // (3) | MHTMLGenerationManager | | 315 // (3) | MHTMLGenerationManager | |
315 // | ::OnFileClosed | | 316 // | ::OnFileClosed | |
316 // | | | | 317 // | | | |
317 // | 318 // |
318 // We hope that (Z) happens between (1) and (3) by doing the following: | 319 // We hope that (Z) happens between (1) and (3) by doing the following: |
319 // - From here post TaskX to UI thread. (X) is guaranteed to happen | 320 // - From here post TaskX to UI thread. (X) is guaranteed to happen |
320 // before timepoint (1) (because posting of (1) happens after | 321 // before timepoint (1) (because posting of (1) happens after |
321 // |return false| / before we post TaskX below). | 322 // |return false| / before we post TaskX below). |
322 // - From (X) post TaskY to FILE thread. Because this posting is done | 323 // - From (X) post TaskY to downlod sequence. Because this posting is |
Avi (use Gerrit)
2017/07/21 17:30:08
typo: download
Sigurður Ásgeirsson
2017/07/21 17:38:20
Done.
| |
323 // before (1), we can guarantee that (Y) will happen before (2). | 324 // done before (1), we can guarantee that (Y) will happen before (2). |
324 // - From (Y) post TaskZ to UI thread. Because this posting is done | 325 // - From (Y) post TaskZ to UI thread. Because this posting is done |
325 // before (2), we can guarantee that (Z) will happen before (3). | 326 // before (2), we can guarantee that (Z) will happen before (3). |
326 // - We cannot really guarantee that (Y) and (Z) happen *after* (1) - i.e. | 327 // - We cannot really guarantee that (Y) and (Z) happen *after* (1) - i.e. |
327 // execution at (Y?) and (Z?) instead is possible. In practice, | 328 // execution at (Y?) and (Z?) instead is possible. In practice, |
328 // bouncing off of UI and FILE thread does mean (Z) happens after (1). | 329 // bouncing off of UI and download sequence does mean (Z) happens |
330 // after (1). | |
329 BrowserThread::PostTask( | 331 BrowserThread::PostTask( |
330 BrowserThread::UI, FROM_HERE, base::Bind( | 332 BrowserThread::UI, FROM_HERE, base::Bind( |
331 &GenerateMHTMLAndExitRendererMessageFilter::TaskX, | 333 &GenerateMHTMLAndExitRendererMessageFilter::TaskX, |
332 base::Unretained(this))); | 334 base::Unretained(this))); |
333 } | 335 } |
334 | 336 |
335 return false; | 337 return false; |
336 }; | 338 }; |
337 | 339 |
338 void TaskX() { | 340 void TaskX() { |
339 BrowserThread::PostTask( | 341 GetDownloadTaskRunner()->PostTask( |
340 BrowserThread::FILE, FROM_HERE, base::Bind( | 342 FROM_HERE, base::Bind(&GenerateMHTMLAndExitRendererMessageFilter::TaskY, |
341 &GenerateMHTMLAndExitRendererMessageFilter::TaskY, | 343 base::Unretained(this))); |
342 base::Unretained(this))); | |
343 } | 344 } |
344 | 345 |
345 void TaskY() { | 346 void TaskY() { |
346 BrowserThread::PostTask( | 347 BrowserThread::PostTask( |
347 BrowserThread::UI, FROM_HERE, base::Bind( | 348 BrowserThread::UI, FROM_HERE, base::Bind( |
348 &GenerateMHTMLAndExitRendererMessageFilter::TaskZ, | 349 &GenerateMHTMLAndExitRendererMessageFilter::TaskZ, |
349 base::Unretained(this))); | 350 base::Unretained(this))); |
350 } | 351 } |
351 | 352 |
352 void TaskZ() { | 353 void TaskZ() { |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
724 base::ThreadRestrictions::ScopedAllowIO allow_io_for_content_verification; | 725 base::ThreadRestrictions::ScopedAllowIO allow_io_for_content_verification; |
725 ASSERT_TRUE(base::ReadFileToString(path, &mhtml)); | 726 ASSERT_TRUE(base::ReadFileToString(path, &mhtml)); |
726 } | 727 } |
727 | 728 |
728 // Make sure that both extra data parts made it into the mhtml. | 729 // Make sure that both extra data parts made it into the mhtml. |
729 EXPECT_THAT(mhtml, HasSubstr(kFakeSignalData1)); | 730 EXPECT_THAT(mhtml, HasSubstr(kFakeSignalData1)); |
730 EXPECT_THAT(mhtml, HasSubstr(kFakeSignalData2)); | 731 EXPECT_THAT(mhtml, HasSubstr(kFakeSignalData2)); |
731 } | 732 } |
732 | 733 |
733 } // namespace content | 734 } // namespace content |
OLD | NEW |