[fuchsia] Add ImportantFileWriterCleaner to WebEngine

Bug: 1151334
Change-Id: Ide606473bb8abb4a2d2e4c3cccfe62f522db3c94
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2566507
Reviewed-by: David Dorwin <ddorwin@chromium.org>
Reviewed-by: Wez <wez@chromium.org>
Commit-Queue: Sharon Yang <yangsharon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#832821}
diff --git a/fuchsia/engine/browser/web_engine_browser_main_parts.cc b/fuchsia/engine/browser/web_engine_browser_main_parts.cc
index 87474d2..5f7a8405 100644
--- a/fuchsia/engine/browser/web_engine_browser_main_parts.cc
+++ b/fuchsia/engine/browser/web_engine_browser_main_parts.cc
@@ -9,6 +9,7 @@
 
 #include "base/callback_helpers.h"
 #include "base/command_line.h"
+#include "base/files/important_file_writer_cleaner.h"
 #include "base/fuchsia/fuchsia_logging.h"
 #include "base/logging.h"
 #include "base/threading/thread_task_runner_handle.h"
@@ -60,6 +61,10 @@
   display::Screen::SetScreenInstance(nullptr);
 }
 
+void WebEngineBrowserMainParts::PostEarlyInitialization() {
+  base::ImportantFileWriterCleaner::GetInstance().Initialize();
+}
+
 void WebEngineBrowserMainParts::PreMainMessageLoopRun() {
   DCHECK(!screen_);
 
@@ -129,6 +134,9 @@
     delete parameters_.ui_task;
     run_message_loop_ = false;
   }
+
+  // Make sure temporary files associated with this process are cleaned up.
+  base::ImportantFileWriterCleaner::GetInstance().Start();
 }
 
 void WebEngineBrowserMainParts::PreDefaultMainMessageLoopRun(
@@ -153,4 +161,6 @@
   context_binding_.reset();
   browser_context_.reset();
   screen_.reset();
+
+  base::ImportantFileWriterCleaner::GetInstance().Stop();
 }
diff --git a/fuchsia/engine/browser/web_engine_browser_main_parts.h b/fuchsia/engine/browser/web_engine_browser_main_parts.h
index 58101e0..23d932e 100644
--- a/fuchsia/engine/browser/web_engine_browser_main_parts.h
+++ b/fuchsia/engine/browser/web_engine_browser_main_parts.h
@@ -47,6 +47,7 @@
   }
 
   // content::BrowserMainParts overrides.
+  void PostEarlyInitialization() override;
   void PreMainMessageLoopRun() override;
   void PreDefaultMainMessageLoopRun(base::OnceClosure quit_closure) override;
   bool MainMessageLoopRun(int* result_code) override;