Add lock for WebViewRendererState

This commit is contained in:
Cheng Zhao 2015-02-04 12:50:24 -08:00
parent f1bca5dd0f
commit c1f3d22910
2 changed files with 6 additions and 0 deletions

View file

@ -20,21 +20,25 @@ WebViewRendererState::~WebViewRendererState() {
} }
bool WebViewRendererState::IsGuest(int render_process_id) { bool WebViewRendererState::IsGuest(int render_process_id) {
base::AutoLock auto_lock(lock_);
return webview_info_map_.find(render_process_id) != return webview_info_map_.find(render_process_id) !=
webview_info_map_.end(); webview_info_map_.end();
} }
void WebViewRendererState::AddGuest(int guest_process_id, void WebViewRendererState::AddGuest(int guest_process_id,
const WebViewInfo& webview_info) { const WebViewInfo& webview_info) {
base::AutoLock auto_lock(lock_);
webview_info_map_[guest_process_id] = webview_info; webview_info_map_[guest_process_id] = webview_info;
} }
void WebViewRendererState::RemoveGuest(int guest_process_id) { void WebViewRendererState::RemoveGuest(int guest_process_id) {
base::AutoLock auto_lock(lock_);
webview_info_map_.erase(guest_process_id); webview_info_map_.erase(guest_process_id);
} }
bool WebViewRendererState::GetInfo(int guest_process_id, bool WebViewRendererState::GetInfo(int guest_process_id,
WebViewInfo* webview_info) { WebViewInfo* webview_info) {
base::AutoLock auto_lock(lock_);
WebViewInfoMap::iterator iter = webview_info_map_.find(guest_process_id); WebViewInfoMap::iterator iter = webview_info_map_.find(guest_process_id);
if (iter != webview_info_map_.end()) { if (iter != webview_info_map_.end()) {
*webview_info = iter->second; *webview_info = iter->second;

View file

@ -11,6 +11,7 @@
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/memory/singleton.h" #include "base/memory/singleton.h"
#include "base/synchronization/lock.h"
namespace content { namespace content {
class WebContents; class WebContents;
@ -56,6 +57,7 @@ class WebViewRendererState {
void RemoveGuest(int render_process_id); void RemoveGuest(int render_process_id);
WebViewInfoMap webview_info_map_; WebViewInfoMap webview_info_map_;
base::Lock lock_;
DISALLOW_COPY_AND_ASSIGN(WebViewRendererState); DISALLOW_COPY_AND_ASSIGN(WebViewRendererState);
}; };