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>
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,
~Ewk_Cookie_Manager() { }
- base::WeakPtr<CookieManager> cookieManager() const {
- return cookie_manager_->GetWeakPtr();
+ scoped_refptr<CookieManager> cookieManager() const {
+ return cookie_manager_;
}
private:
: cookie_manager_(new CookieManager(request_context_getter)) {
}
- scoped_ptr<CookieManager> cookie_manager_;
+ scoped_refptr<CookieManager> cookie_manager_;
};
#endif // ewk_cookie_manager_private_h
getter_ = getter;
}
-base::WeakPtr<CookieManager>
+scoped_refptr<CookieManager>
BrowserContextEfl::ResourceContextEfl::GetCookieManager() const {
return getter_->cookieManager();
}
#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"
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;
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,
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,
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)
{
}
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
base::Bind(&CookieManager::DeleteCookiesOnIOThread,
- GetWeakPtr(),
+ scoped_refptr<CookieManager>(this),
url,
cookie_name));
}
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));
BrowserThread::PostTask(BrowserThread::IO,
FROM_HERE,
base::Bind(&CookieManager::FetchCookiesOnIOThread,
- GetWeakPtr()));
+ scoped_refptr<CookieManager>(this)));
}
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());
}
if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
base::Bind(&CookieManager::OnFetchComplete,
- GetWeakPtr(),
+ scoped_refptr<CookieManager>(this),
cookies));
return;
}
cookie_monster->GetCookiesWithOptionsAsync(host,
options,
base::Bind(&CookieManager::GetCookieValueCompleted,
- GetWeakPtr(),
+ scoped_refptr<CookieManager>(this),
completion,
result));
} else {
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));
completion.Wait();
return cookie_value;
}
-
-base::WeakPtr<CookieManager> CookieManager::GetWeakPtr() {
- return weak_ptr_factory_.GetWeakPtr();
-}
#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"
struct _Ewk_Error;
-class CookieManager {
+class CookieManager : public base::RefCountedThreadSafe<CookieManager> {
public:
typedef void (*AsyncPolicyGetCb)(tizen_webview::Cookie_Accept_Policy,
void *);
//This is synchronous call
std::string GetCookiesForURL(const std::string& url);
- base::WeakPtr<CookieManager> GetWeakPtr();
-
private:
struct EwkGetHostCallback;
std::queue< EwkGetHostCallback* > host_callback_queue_;
DISALLOW_COPY_AND_ASSIGN(CookieManager);
-
- base::WeakPtrFactory<CookieManager> weak_ptr_factory_;
};
#endif //cookie_manager_h
#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"
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
namespace net {
NetworkDelegateEfl::NetworkDelegateEfl(
- base::WeakPtr<CookieManager> cookie_manager)
+ scoped_refptr<CookieManager> cookie_manager)
: cookie_manager_(cookie_manager) {
}
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);
}
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);
}
class NetworkDelegateEfl : public NetworkDelegate {
public:
- NetworkDelegateEfl(base::WeakPtr<CookieManager> cookie_manager);
+ NetworkDelegateEfl(scoped_refptr<CookieManager> cookie_manager);
private:
// NetworkDelegate implementation.
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
return impl->ewkCookieManager();
}
-base::WeakPtr<CookieManager> WebContext::cookieManager() const {
+scoped_refptr<CookieManager> WebContext::cookieManager() const {
return impl->cookieManager();
}
#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"
// 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,
#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"
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();
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_;