Fix ewk shutdown procedure
authorKamil Klimek <k.klimek@partner.samsung.com>
Fri, 13 Jun 2014 22:54:10 +0000 (15:54 -0700)
committerYoungsoo Choi <kenshin.choi@samsung.com>
Tue, 10 Jul 2018 06:57:09 +0000 (06:57 +0000)
1. Releasing all blink related resources so all local caches are written
to the hard drive
2. Releasing web pages
3. Releasing all EWK API related structures and resources

Issue: CBWEBVIEW-525
Change-Id: Ie453682a1a302f463726b836c205ebdb2783fe31

Conflicts:

impl/browser_context_efl.cc

tizen_src/impl/browser_context_efl.cc
tizen_src/impl/browser_context_efl.h
tizen_src/impl/browser_main_parts_efl.cc
tizen_src/impl/chromium-efl.gyp
tizen_src/impl/eweb_context.cc
tizen_src/impl/eweb_context.h
tizen_src/impl/ewk_global_data.cc [new file with mode: 0644]
tizen_src/impl/ewk_global_data.h [new file with mode: 0644]
tizen_src/impl/message_pump_for_ui_efl.cc

index bd8d7d3..9bc51f4 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "browser_context_efl.h"
 
+#include "base/bind.h"
 #include "base/file_util.h"
 #include "base/path_service.h"
 #include "components/visitedlink/browser/visitedlink_master.h"
@@ -34,6 +35,13 @@ BrowserContextEfl::ResourceContextEfl::ResourceContextEfl(BrowserContextEfl *ctx
       browser_context_(ctx) {
 }
 
+BrowserContextEfl::~BrowserContextEfl() {
+  if (resource_context_) {
+    DCHECK(BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, resource_context_));
+    resource_context_ = NULL;
+  }
+}
+
 BrowserContextEfl::ResourceContextEfl::~ResourceContextEfl() {
 }
 
@@ -61,7 +69,8 @@ void BrowserContextEfl::ResourceContextEfl::set_url_request_context_getter(
 }
 
 BrowserContextEfl::BrowserContextEfl(EWebContext* web_context)
-  : web_context_(web_context),
+  : resource_context_(NULL),
+    web_context_(web_context),
 #if defined(ENABLE_NOTIFICATIONS)
     notification_controllerefl_(new NotificationControllerEfl()),
 #endif
@@ -89,9 +98,9 @@ void BrowserContextEfl::CancelProtectedMediaIdentifierPermissionRequests(
 
 ResourceContext* BrowserContextEfl::GetResourceContext() {
   if (!resource_context_)
-    resource_context_.reset(new ResourceContextEfl(this));
+    resource_context_ = new ResourceContextEfl(this);
 
-  return resource_context_.get();
+  return resource_context_;
 }
 
 base::FilePath BrowserContextEfl::GetPath() const {
index f1b22cb..2d53a4c 100644 (file)
@@ -44,6 +44,7 @@ class BrowserContextEfl
     public visitedlink::VisitedLinkDelegate {
  public:
   BrowserContextEfl(EWebContext*);
+  ~BrowserContextEfl();
 
   virtual bool IsOffTheRecord() const OVERRIDE { return false; }
   virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE;
@@ -137,7 +138,7 @@ class BrowserContextEfl
   static void ReadCertificateAndAdd(base::FilePath* file_path);
 
   scoped_ptr<visitedlink::VisitedLinkMaster> visitedlink_master_;
-  scoped_ptr<ResourceContextEfl> resource_context_;
+  ResourceContextEfl* resource_context_;
   scoped_refptr<URLRequestContextGetterEfl> request_context_getter_;
   EWebContext* web_context_;
 #if defined(ENABLE_NOTIFICATIONS)
index b352a63..cffe801 100644 (file)
@@ -10,7 +10,8 @@
 
 namespace content {
 
-BrowserMainPartsEfl::BrowserMainPartsEfl() {
+BrowserMainPartsEfl::BrowserMainPartsEfl()
+  : devtools_delegate_(NULL) {
 }
 
 BrowserMainPartsEfl::~BrowserMainPartsEfl() {
index cf150d6..607c789 100755 (executable)
       'eweb_view.cc',
       'eweb_view.h',
       'eweb_view_callbacks.h',
+      'ewk_global_data.h',
+      'ewk_global_data.cc',
       'file_chooser_controller_efl.cc',
       'file_chooser_controller_efl.h',
       'memory_purger.cc',
index e8ee430..12c75a5 100644 (file)
 
 #include "eweb_context.h"
 
-#include "base/command_line.h"
-#include "base/files/file_path.h"
-#include "base/path_service.h"
-#include "base/logging.h"
-#include "base/threading/thread_restrictions.h"
+#include "base/synchronization/waitable_event.h"
 #include "content/common/plugin_list.h"
-#include "content/public/app/content_main_runner.h"
-#include "content/public/common/main_function_params.h"
-#include "content/public/browser/browser_main_runner.h"
+#include "content/public/browser/browser_context.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/storage_partition.h"
 #include "content/public/browser/render_process_host.h"
-#include "content/public/common/content_client.h"
-#include "content/common/plugin_list.h"
-#include "content/public/app/content_main_runner.h"
-#include "content/public/common/main_function_params.h"
-#include "content/public/browser/browser_main_runner.h"
-#include "content/public/browser/utility_process_host.h"
-#include "content/utility/in_process_utility_thread.h"
-#include "content/renderer/in_process_renderer_thread.h"
-#include "content/gpu/in_process_gpu_thread.h"
-#include "content/browser/gpu/gpu_process_host.h"
-#include "content/public/common/content_switches.h"
-#include "common/render_messages_efl.h"
-#include "browser/renderer_host/browsing_data_remover_efl.h"
-#include "browser/vibration/vibration_provider_client.h"
-#include "content_main_delegate_efl.h"
-#include "message_pump_for_ui_efl.h"
-#include "API/ewk_security_origin_private.h"
-#include "web_contents_delegate_efl.h"
-#include "screen_efl.h"
-#include "memory_purger.h"
-#include "cookie_manager.h"
-#include "command_line_efl.h"
 #include "net/http/http_cache.h"
-#include "net/proxy/proxy_config.h"
 #include "net/proxy/proxy_config_service_fixed.h"
 #include "net/proxy/proxy_service.h"
-#include "net/url_request/url_request_context_getter.h"
-#include "ui/base/resource/resource_bundle.h"
 #include "webkit/browser/appcache/appcache_service.h"
 #include "webkit/browser/database/database_quota_client.h"
 #include "webkit/browser/fileapi/file_system_quota_client.h"
 #include "webkit/browser/quota/quota_manager.h"
-#include "webkit/common/quota/quota_types.h"
 
-#include <Ecore.h>
+#include "browser_context_efl.h"
+#include "ewk_global_data.h"
+#include "memory_purger.h"
+#include "API/ewk_security_origin_private.h"
+#include "browser/renderer_host/browsing_data_remover_efl.h"
+#include "browser/vibration/vibration_provider_client.h"
+#include "common/render_messages_efl.h"
+
+using content::BrowserThread;
+using content::BrowserContext;
+using content::BrowserContextEfl;
 
-using namespace base;
-using namespace content;
 using std::string;
 using std::pair;
 using std::map;
 
 namespace {
 
-MessagePump* MessagePumpFactory() {
-  return new MessagePumpForUIEfl;
-}
-
 void SetProxyConfigCallbackOnIOThread(base::WaitableEvent* done,
                             net::URLRequestContextGetter* url_request_context_getter,
                             const net::ProxyConfig& proxy_config) {
@@ -189,18 +163,7 @@ void EwkDidStartDownloadCallback::TriggerCallback(const string& url) {
     (*callback_)(url.c_str(),user_data_);
 }
 
-struct EWebContext::GlobalData {
-  GlobalData()
-    : content_main_runner_(ContentMainRunner::Create())
-    , browser_main_runner_(BrowserMainRunner::Create()) {
-  }
-
-  ContentMainRunner* content_main_runner_;
-  BrowserMainRunner* browser_main_runner_;
-};
-
 EWebContext* EWebContext::default_context_ = NULL;
-EWebContext::GlobalData* EWebContext::global_data_ = NULL;
 
 EWebContext* ToEWebContext(Ewk_Context* context) {
   EWebContext* web_context = ewk_object_cast<EWebContext*>(context);
@@ -248,7 +211,7 @@ void EWebContext::Delete(EWebContext*const context) {
 
 EWebContext::EWebContext()
   : m_pixmap(0) {
-  EnsureGlobalData();
+  EwkGlobalData::Ensure();
 
   browser_context_.reset(new BrowserContextEfl(this));
   // Notification Service gets init in BrowserMainRunner init,
@@ -262,47 +225,6 @@ EWebContext::~EWebContext() {
     default_context_= NULL;
 }
 
-// static
-void EWebContext::EnsureGlobalData() {
-  if (global_data_)
-    return;
-
-  global_data_ = new GlobalData;
-
-  bool message_pump_overridden = base::MessageLoop::InitMessagePumpForUIFactory(&MessagePumpFactory);
-  DCHECK(message_pump_overridden);
-
-  InstallScreenInstance();
-
-  global_data_->content_main_runner_->Initialize(CommandLineEfl::GetArgc(),
-      CommandLineEfl::GetArgv(), new ContentMainDelegateEfl());
-  global_data_->browser_main_runner_->Initialize(CommandLineEfl::GetDefaultPortParams());
-
-  base::ThreadRestrictions::SetIOAllowed(true);
-
-  base::FilePath pak_dir;
-  base::FilePath pak_file;
-  PathService::Get(base::DIR_MODULE, &pak_dir);
-  pak_file = pak_dir.Append(FILE_PATH_LITERAL("content_shell.pak"));
-  ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file);
-
-  if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) {
-    UtilityProcessHost::RegisterUtilityMainThreadFactory(
-        CreateInProcessUtilityThread);
-    RenderProcessHost::RegisterRendererMainThreadFactory(
-        CreateInProcessRendererThread);
-    GpuProcessHost::RegisterGpuMainThreadFactory(
-        CreateInProcessGpuThread);
-  }
-
-#ifndef NDEBUG
-  logging::LoggingSettings settings;
-  settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
-  logging::InitLogging(settings);
-  logging::SetLogItems(true, true, true, true);
-#endif
-}
-
 void EWebContext::ClearNetworkCache() {
   BrowsingDataRemoverEfl* remover = BrowsingDataRemoverEfl::CreateForUnboundedRange(browser_context_.get());
   remover->ClearNetworkCache();
index 83d7ea5..03800dc 100644 (file)
 #ifndef EWEB_CONTEXT_H
 #define EWEB_CONTEXT_H
 
-#include "base/command_line.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/run_loop.h"
-#include "content/public/app/content_main_runner.h"
-#include "content/public/browser/browser_main_runner.h"
-#include "content/public/browser/browser_context.h"
-#include "browser/renderer_host/web_cache_manager_efl.h"
 #include "eweb_object.h"
 #include "API/ewk_cookie_manager_private.h"
+#include "browser/renderer_host/web_cache_manager_efl.h"
 #include "public/ewk_context.h"
-#include "public/ewk_ipc_message.h"
-#include "ui/gfx/rect.h"
-
-#include <Evas.h>
 
 typedef std::map<std::string, std::string> HTTPCustomHeadersEflMap;
 
+class CookieManager;
+struct Ewk_IPC_Wrt_Message_Data;
+
 namespace content {
 class BrowserContextEfl;
 }
@@ -111,14 +104,9 @@ class EWebContext : public EWebObject {
   int Pixmap() const { return m_pixmap; }
 
  private:
-  struct GlobalData;
-
   virtual ~EWebContext();
 
-  static void EnsureGlobalData();
-
   static EWebContext* default_context_;
-  static GlobalData* global_data_;
   scoped_ptr<WebCacheManagerEfl> web_cache_manager_;
   scoped_ptr<content::BrowserContextEfl> browser_context_;
   HTTPCustomHeadersEflMap http_custom_headers_;
@@ -126,9 +114,6 @@ class EWebContext : public EWebObject {
   std::string proxy_uri_;
   scoped_ptr<EwkDidStartDownloadCallback> start_download_callback_;
   int m_pixmap;
-
-  static int argc_;
-  static const char** argv_;
 };
 
 EWebContext* ToEWebContext(Ewk_Context* context);
diff --git a/tizen_src/impl/ewk_global_data.cc b/tizen_src/impl/ewk_global_data.cc
new file mode 100644 (file)
index 0000000..c54d7e2
--- /dev/null
@@ -0,0 +1,99 @@
+#include "ewk_global_data.h"
+
+#include "base/logging.h"
+#include "base/path_service.h"
+#include "base/message_loop/message_loop.h"
+#include "content/browser/gpu/gpu_process_host.h"
+#include "content/gpu/in_process_gpu_thread.h"
+#include "content/public/app/content_main_runner.h"
+#include "content/public/browser/browser_main_runner.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/render_process_host.h"
+#include "content/public/browser/utility_process_host.h"
+#include "content/public/common/content_switches.h"
+#include "content/renderer/in_process_renderer_thread.h"
+#include "content/utility/in_process_utility_thread.h"
+#include "ui/base/resource/resource_bundle.h"
+
+#include "command_line_efl.h"
+#include "content_main_delegate_efl.h"
+#include "message_pump_for_ui_efl.h"
+#include "screen_efl.h"
+
+using base::MessageLoop;
+using content::BrowserMainRunner;
+using content::BrowserThread;
+using content::ContentMainDelegateEfl;
+using content::ContentMainRunner;
+using content::GpuProcessHost;
+using content::RenderProcessHost;
+using content::UtilityProcessHost;
+
+EwkGlobalData* EwkGlobalData::instance_ = NULL;
+
+namespace {
+
+base::MessagePump* MessagePumpFactory() {
+  return new base::MessagePumpForUIEfl;
+}
+
+} // namespace
+
+EwkGlobalData::EwkGlobalData()
+  : content_main_runner_(ContentMainRunner::Create())
+  , browser_main_runner_(BrowserMainRunner::Create()) {
+}
+
+EwkGlobalData::~EwkGlobalData() {
+    DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+    // We need to pretend that message loop was stopped so chromium unwinds correctly
+    MessageLoop *loop = MessageLoop::current();
+    loop->QuitNow();
+    // browser_main_runner must be deleted first as it depends on content_main_runner
+    delete browser_main_runner_;
+    delete content_main_runner_;
+}
+
+EwkGlobalData* EwkGlobalData::GetInstance() {
+  return instance_;
+}
+
+void EwkGlobalData::Ensure() {
+  if (instance_)
+    return;
+
+  instance_ = new EwkGlobalData();
+
+  bool message_pump_overridden = base::MessageLoop::InitMessagePumpForUIFactory(&MessagePumpFactory);
+  DCHECK(message_pump_overridden);
+
+  content::InstallScreenInstance();
+
+  instance_->content_main_runner_->Initialize(CommandLineEfl::GetArgc(),
+      CommandLineEfl::GetArgv(), new ContentMainDelegateEfl());
+  instance_->browser_main_runner_->Initialize(CommandLineEfl::GetDefaultPortParams());
+
+  base::ThreadRestrictions::SetIOAllowed(true);
+
+  base::FilePath pak_dir;
+  base::FilePath pak_file;
+  PathService::Get(base::DIR_EXE, &pak_dir);
+  pak_file = pak_dir.Append(FILE_PATH_LITERAL("content_shell.pak"));
+  ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file);
+
+  if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) {
+    UtilityProcessHost::RegisterUtilityMainThreadFactory(
+        content::CreateInProcessUtilityThread);
+    RenderProcessHost::RegisterRendererMainThreadFactory(
+        content::CreateInProcessRendererThread);
+    GpuProcessHost::RegisterGpuMainThreadFactory(
+        content::CreateInProcessGpuThread);
+  }
+
+#ifndef NDEBUG
+  logging::LoggingSettings settings;
+  settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
+  logging::InitLogging(settings);
+  logging::SetLogItems(true, true, true, true);
+#endif
+}
diff --git a/tizen_src/impl/ewk_global_data.h b/tizen_src/impl/ewk_global_data.h
new file mode 100644 (file)
index 0000000..7201ee0
--- /dev/null
@@ -0,0 +1,27 @@
+#ifndef EWK_GLOBAL_DATA_H_
+#define EWK_GLOBAL_DATA_H_
+
+namespace content {
+  class BrowserMainRunner;
+  class ContentMainRunner;
+}
+
+class EwkGlobalData
+{
+public:
+  ~EwkGlobalData();
+
+  static EwkGlobalData* GetInstance();
+  static void Ensure();
+
+private:
+  EwkGlobalData();
+
+private:
+  static EwkGlobalData* instance_;
+
+  content::ContentMainRunner* content_main_runner_;
+  content::BrowserMainRunner* browser_main_runner_;
+};
+
+#endif // EWK_GLOBAL_DATA_H_
index e8f3ddd..5b73197 100644 (file)
@@ -42,9 +42,6 @@ MessagePumpForUIEfl::MessagePumpForUIEfl()
 }
 
 MessagePumpForUIEfl::~MessagePumpForUIEfl() {
-  DCHECK(run_loop_->running());
-  run_loop_->AfterRun();
-  delete run_loop_;
 }
 
 // FIXME: need to be implemented for tests.
@@ -54,7 +51,13 @@ void MessagePumpForUIEfl::Run(base::MessagePump::Delegate* delegate) {
 
 // FIXME: need to be implemented for tests.
 void MessagePumpForUIEfl::Quit() {
-  NOTREACHED();
+  // RunLoop must be destroyed before chromium cleanup
+  ecore_pipe_del(pipe_);
+  DCHECK(run_loop_->running());
+  run_loop_->AfterRun();
+  delete run_loop_;
+  run_loop_ = NULL;
+  pipe_ = NULL;
 }
 
 void MessagePumpForUIEfl::ScheduleWork() {