Make pointers into CookieManager thread-safe.
authorWojciech Wiśniewski <w.wisniewski@samsung.com>
Tue, 20 Jan 2015 13:17:08 +0000 (14:17 +0100)
committerYoungsoo Choi <kenshin.choi@samsung.com>
Tue, 10 Jul 2018 06:57:09 +0000 (06:57 +0000)
CookieManager class was used mostly through WeakPtr pointers.
These pointers are not thread-safe (they should be dereferenced
and destroyed only in the same thread they were created).
Because CookieManager class is used both from UI and IO browser
threads, it was causing assertion fails in debug builds.

This patch changes WeakPtrs to thread-safe version of scoped_refptrs.
Reviewed by: Daniel Waślicki, Piotr Tworek, SeungSeop Park, arno renevier

Change-Id: I54b7500083e1d54f7cbac223a50f7a9cd5eff95b
Signed-off-by: Wojciech Wiśniewski <w.wisniewski@samsung.com>
13 files changed:
tizen_src/ewk/efl_integration/public/ewk_cookie_manager.cc
tizen_src/impl/API/ewk_cookie_manager_private.h
tizen_src/impl/browser_context_efl.cc
tizen_src/impl/browser_context_efl.h
tizen_src/impl/content_browser_client_efl.cc
tizen_src/impl/cookie_manager.cc
tizen_src/impl/cookie_manager.h
tizen_src/impl/eweb_context.h
tizen_src/impl/network_delegate_efl.cc
tizen_src/impl/network_delegate_efl.h
tizen_src/impl/tizen_webview/public/tw_web_context.cc
tizen_src/impl/tizen_webview/public/tw_web_context.h
tizen_src/impl/url_request_context_getter_efl.h

index a3714b5a76479716a01d8ba89442d40d71e22cbe..1276ae53f67e6de8580d3a3a1e9f8c1a90e2f40c 100644 (file)
@@ -20,7 +20,7 @@
     CRITICAL("ewk cookie manager->cookieManager() is NULL.");           \
     return __VA_ARGS__;                                                 \
   }                                                                     \
-  base::WeakPtr<CookieManager> cookie_manager = (manager)->cookieManager()
+  scoped_refptr<CookieManager> cookie_manager = (manager)->cookieManager()
 
 
 void ewk_cookie_manager_persistent_storage_set(Ewk_Cookie_Manager* manager,
index e1c101f8981c98b22726d8cd741670b5d9587bfa..171ab78c7951ee61e769300734bdeda44decfbd8 100644 (file)
@@ -19,8 +19,8 @@ class Ewk_Cookie_Manager {
 
   ~Ewk_Cookie_Manager() { }
 
-  base::WeakPtr<CookieManager> cookieManager() const {
-    return cookie_manager_->GetWeakPtr();
+  scoped_refptr<CookieManager> cookieManager() const {
+    return cookie_manager_;
   }
 
  private:
@@ -28,7 +28,7 @@ class Ewk_Cookie_Manager {
     : cookie_manager_(new CookieManager(request_context_getter)) {
   }
 
-  scoped_ptr<CookieManager> cookie_manager_;
+  scoped_refptr<CookieManager> cookie_manager_;
 };
 
 #endif // ewk_cookie_manager_private_h
index 7b0d2c25fdbbf754448b8565b7121fa615437cc9..594a2c89e3222dfc1fbc543f538d1a71539f9b3e 100644 (file)
@@ -92,7 +92,7 @@ void BrowserContextEfl::ResourceContextEfl::set_url_request_context_getter(
   getter_ = getter;
 }
 
-base::WeakPtr<CookieManager>
+scoped_refptr<CookieManager>
 BrowserContextEfl::ResourceContextEfl::GetCookieManager() const {
   return getter_->cookieManager();
 }
index 844cc8a8e1cb3ae7a7cd1062a70987e9bec15ba3..1a79d9e9399db1ce21df09e5c82bff305916d6c3 100644 (file)
@@ -10,7 +10,6 @@
 #include "url_request_context_getter_efl.h"
 #include "base/files/scoped_temp_dir.h"
 #include "base/memory/scoped_ptr.h"
-#include "base/memory/weak_ptr.h"
 #include "base/synchronization/lock.h"
 #include "browser/download_manager_delegate_efl.h"
 #include "browser/geolocation/geolocation_permission_context_efl.h"
@@ -56,7 +55,7 @@ class BrowserContextEfl
     void set_url_request_context_getter(
         scoped_refptr<URLRequestContextGetterEfl> getter);
 
-    base::WeakPtr<CookieManager> GetCookieManager() const;
+    scoped_refptr<CookieManager> GetCookieManager() const;
 
 #if defined(ENABLE_NOTIFICATIONS)
     scoped_refptr<NotificationControllerEfl> GetNotificationController() const;
index 9ed14bb08509a1b06645188eb7e38d6e1dacc531..07ef152ab708c79c4a6e64e7235094bcbf225453 100755 (executable)
@@ -244,8 +244,8 @@ bool ContentBrowserClientEfl::AllowGetCookie(const GURL& url,
   if (!rc)
     return false;
 
-  base::WeakPtr<CookieManager> cookie_manager = rc->GetCookieManager();
-  if (!cookie_manager)
+  scoped_refptr<CookieManager> cookie_manager = rc->GetCookieManager();
+  if (!cookie_manager.get())
     return false;
 
   return cookie_manager->AllowGetCookie(url,
@@ -268,8 +268,8 @@ bool ContentBrowserClientEfl::AllowSetCookie(const GURL& url,
   if (!rc)
     return false;
 
-  base::WeakPtr<CookieManager> cookie_manager = rc->GetCookieManager();
-  if (!cookie_manager)
+  scoped_refptr<CookieManager> cookie_manager = rc->GetCookieManager();
+  if (!cookie_manager.get())
     return false;
 
   return cookie_manager->AllowSetCookie(url,
index 25b40c4a56676ca79696ff97edf2d969c4c57eeb..b368bb75cd295bc460cdd01fb704680eb7c567ba 100644 (file)
@@ -77,8 +77,7 @@ class CookieManager::EwkGetHostCallback {
 CookieManager::CookieManager(content::URLRequestContextGetterEfl* request_context_getter)
     : is_clearing_(false),
       request_context_getter_(request_context_getter),
-      cookie_policy_(TW_COOKIE_ACCEPT_POLICY_ALWAYS),
-      weak_ptr_factory_(this)
+      cookie_policy_(TW_COOKIE_ACCEPT_POLICY_ALWAYS)
 {
 }
 
@@ -88,7 +87,7 @@ void CookieManager::DeleteCookiesAsync(const std::string& url,
   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
   BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
                                     base::Bind(&CookieManager::DeleteCookiesOnIOThread,
-                                                 GetWeakPtr(),
+                                                 scoped_refptr<CookieManager>(this),
                                                  url,
                                                  cookie_name));
 }
@@ -125,7 +124,7 @@ void CookieManager::SetStoragePath(const std::string& path,
     DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
     BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
                                     base::Bind(&CookieManager::SetStoragePathOnIOThread,
-                                                 GetWeakPtr(),
+                                                 scoped_refptr<CookieManager>(this),
                                                  path,
                                                  persist_session_cookies,
                                                  file_storage_type));
@@ -146,7 +145,7 @@ void CookieManager::GetHostNamesWithCookiesAsync(AsyncHostnamesGetCb callback, v
   BrowserThread::PostTask(BrowserThread::IO,
                           FROM_HERE,
                           base::Bind(&CookieManager::FetchCookiesOnIOThread,
-                                     GetWeakPtr()));
+                                     scoped_refptr<CookieManager>(this)));
 }
 
 void CookieManager::FetchCookiesOnIOThread() {
@@ -160,7 +159,7 @@ void CookieManager::FetchCookiesOnIOThread() {
       cookie_store()->GetCookieMonster();
   if (cookie_monster.get()) {
     cookie_monster->GetAllCookiesAsync(
-        base::Bind(&CookieManager::OnFetchComplete, GetWeakPtr()));
+        base::Bind(&CookieManager::OnFetchComplete, scoped_refptr<CookieManager>(this)));
   } else {
     OnFetchComplete(net::CookieList());
   }
@@ -170,7 +169,7 @@ void CookieManager::OnFetchComplete(const net::CookieList& cookies) {
   if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
     BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
                                     base::Bind(&CookieManager::OnFetchComplete,
-                                                   GetWeakPtr(),
+                                                   scoped_refptr<CookieManager>(this),
                                                    cookies));
     return;
   }
@@ -285,7 +284,7 @@ void CookieManager::GetCookieValueOnIOThread(const GURL& host,
     cookie_monster->GetCookiesWithOptionsAsync(host,
                                                options,
                                                base::Bind(&CookieManager::GetCookieValueCompleted,
-                                                          GetWeakPtr(),
+                                                          scoped_refptr<CookieManager>(this),
                                                           completion,
                                                           result));
   } else {
@@ -308,7 +307,7 @@ std::string CookieManager::GetCookiesForURL(const std::string& url) {
   base::WaitableEvent completion(false, false);
   BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
                                   base::Bind(&CookieManager::GetCookieValueOnIOThread,
-                                                 GetWeakPtr(),
+                                                 scoped_refptr<CookieManager>(this),
                                                  GURL(url),
                                                  &cookie_value,
                                                  &completion));
@@ -319,7 +318,3 @@ std::string CookieManager::GetCookiesForURL(const std::string& url) {
   completion.Wait();
   return cookie_value;
 }
-
-base::WeakPtr<CookieManager> CookieManager::GetWeakPtr() {
-  return weak_ptr_factory_.GetWeakPtr();
-}
index 87ec8616fdb692d85fde4325888d9cc4e56be63d..c13ecaf9200441bdf29a31a77fbccbdf4e20a1bf 100644 (file)
@@ -10,7 +10,7 @@
 
 #include "url_request_context_getter_efl.h"
 #include "base/basictypes.h"
-#include "base/memory/weak_ptr.h"
+#include "base/memory/ref_counted.h"
 #include "base/synchronization/lock.h"
 #include "net/url_request/url_request_context.h"
 #include "net/url_request/url_request_context_getter.h"
@@ -26,7 +26,7 @@ class ResourceContext;
 
 struct _Ewk_Error;
 
-class CookieManager {
+class CookieManager : public base::RefCountedThreadSafe<CookieManager> {
  public:
   typedef void (*AsyncPolicyGetCb)(tizen_webview::Cookie_Accept_Policy,
                                    void *);
@@ -88,8 +88,6 @@ class CookieManager {
   //This is synchronous call
   std::string GetCookiesForURL(const std::string& url);
 
-  base::WeakPtr<CookieManager> GetWeakPtr();
-
  private:
   struct EwkGetHostCallback;
 
@@ -125,8 +123,6 @@ class CookieManager {
   std::queue< EwkGetHostCallback* > host_callback_queue_;
 
   DISALLOW_COPY_AND_ASSIGN(CookieManager);
-
-  base::WeakPtrFactory<CookieManager> weak_ptr_factory_;
 };
 
 #endif //cookie_manager_h
index f3f9ab90b2abfe13cc0f0afa10229e5e7e3d4e07..ed7febd397362ada74630e93d030a6840c5dac3d 100644 (file)
@@ -7,7 +7,6 @@
 
 #include "API/ewk_cookie_manager_private.h"
 #include "base/memory/scoped_ptr.h"
-#include "base/memory/weak_ptr.h"
 #include "browser/renderer_host/web_cache_manager_efl.h"
 #include "tizen_webview/public/tw_cache_model.h"
 #include "tizen_webview/public/tw_callbacks.h"
@@ -70,7 +69,7 @@ class EWebContext {
 
   void NotifyLowMemory();
   Ewk_Cookie_Manager* ewkCookieManager();
-  base::WeakPtr<CookieManager> cookieManager()
+  scoped_refptr<CookieManager> cookieManager()
   { return ewkCookieManager()->cookieManager(); }
   void SetProxyUri(const char* uri);
   const char* GetProxyUri() const
index 79c8dd8ae2101031d8c58e45ec97ab883fde04e1..3b81cce2daf1700630a221ebdad7e211cb4f4e16 100644 (file)
@@ -12,7 +12,7 @@
 namespace net {
 
 NetworkDelegateEfl::NetworkDelegateEfl(
-    base::WeakPtr<CookieManager> cookie_manager)
+    scoped_refptr<CookieManager> cookie_manager)
     : cookie_manager_(cookie_manager) {
 }
 
@@ -26,7 +26,7 @@ NetworkDelegate::AuthRequiredResponse NetworkDelegateEfl::OnAuthRequired(
 
 bool NetworkDelegateEfl::OnCanGetCookies(const URLRequest& request,
                                          const CookieList& cookie_list) {
-  if (!cookie_manager_)
+  if (!cookie_manager_.get())
     return false;
   return cookie_manager_->OnCanGetCookies(request, cookie_list);
 }
@@ -34,7 +34,7 @@ bool NetworkDelegateEfl::OnCanGetCookies(const URLRequest& request,
 bool NetworkDelegateEfl::OnCanSetCookie(const URLRequest& request,
                                         const std::string& cookie_line,
                                         CookieOptions* options) {
-  if (!cookie_manager_)
+  if (!cookie_manager_.get())
     return false;
   return cookie_manager_->OnCanSetCookie(request, cookie_line, options);
 }
index 52b2dc35894af9cdd82206763316453170ad5dc3..e5f1f88e142e8972035763604ac6899f29700bd6 100644 (file)
@@ -15,7 +15,7 @@ namespace net {
 
 class NetworkDelegateEfl : public NetworkDelegate {
  public:
-  NetworkDelegateEfl(base::WeakPtr<CookieManager> cookie_manager);
+  NetworkDelegateEfl(scoped_refptr<CookieManager> cookie_manager);
 
  private:
   // NetworkDelegate implementation.
@@ -33,7 +33,7 @@ class NetworkDelegateEfl : public NetworkDelegate {
                                const base::FilePath& path) const override;
   virtual bool OnCanThrottleRequest(const URLRequest& request) const override;
 
-  base::WeakPtr<CookieManager> cookie_manager_;
+  scoped_refptr<CookieManager> cookie_manager_;
 };
 
 } // namespace net
index 42db6338fd6b45aabdad5c26704870995c02efe6..67fe3cb9150d2aec9dfad286bafcebc60a792c0c 100644 (file)
@@ -77,7 +77,7 @@ Ewk_Cookie_Manager* WebContext::ewkCookieManager() const {
   return impl->ewkCookieManager();
 }
 
-base::WeakPtr<CookieManager> WebContext::cookieManager() const {
+scoped_refptr<CookieManager> WebContext::cookieManager() const {
   return impl->cookieManager();
 }
 
index 46c848ca3335a241a5583ce84effb1df6034856b..039b9c8078a475e14920cde4b7f3f082f422733d 100644 (file)
@@ -9,7 +9,7 @@
 #include <string>
 #include <Evas.h>
 
-#include "base/memory/weak_ptr.h"
+#include "base/memory/ref_counted.h"
 #include "tizen_webview/public/tw_callbacks.h"
 #include "tizen_webview/public/tw_cache_model.h"
 #include "tizen_webview/public/tw_ref_counted.h"
@@ -39,7 +39,7 @@ struct WebContext : public tizen_webview::RefCounted<WebContext> {
   // Get related class
   content::BrowserContextEfl* browser_context() const;
   Ewk_Cookie_Manager* ewkCookieManager() const;
-  base::WeakPtr<CookieManager> cookieManager() const;
+  scoped_refptr<CookieManager> cookieManager() const;
 
   // Set Callbacks
   void SetDidStartDownloadCallback(Context_Did_Start_Download_Callback callback,
index 010d66e9853cb26b781a70f37d457622c67c7b84..42ee2ec75d1e7820f7b6e756b37617cb713094db 100644 (file)
@@ -7,7 +7,6 @@
 #define _URL_REQUEST_CONTEXT_GETTER_EFL_H_
 
 #include "base/memory/scoped_ptr.h"
-#include "base/memory/weak_ptr.h"
 #include "content/public/browser/content_browser_client.h"
 #include "net/url_request/url_request_context_getter.h"
 
@@ -50,7 +49,7 @@ class URLRequestContextGetterEfl : public net::URLRequestContextGetter {
                             bool persist_session_cookies,
                             bool file_storage=true);
 
-  base::WeakPtr<CookieManager> cookieManager() { return cookie_manager_; }
+  scoped_refptr<CookieManager> cookieManager() { return cookie_manager_; }
 
  protected:
   virtual ~URLRequestContextGetterEfl();
@@ -71,7 +70,7 @@ class URLRequestContextGetterEfl : public net::URLRequestContextGetter {
 
   base::FilePath cookie_store_path_;
   scoped_refptr<net::CookieStore> cookie_store_;
-  base::WeakPtr<CookieManager> cookie_manager_;
+  scoped_refptr<CookieManager> cookie_manager_;
 
   scoped_ptr<net::ProxyConfigService> proxy_config_service_;
   scoped_ptr<net::NetworkDelegate> network_delegate_;