Switch to using scoped_ptr with UserData

https://codereview.chromium.org/2815913005
This commit is contained in:
Aleksei Kuzmin 2017-08-07 23:30:03 +03:00 committed by Cheng Zhao
parent fe952d5c65
commit 971002a197
2 changed files with 5 additions and 4 deletions

View file

@ -180,12 +180,12 @@ void CommonWebContentsDelegate::SetOwnerWindow(NativeWindow* owner_window) {
void CommonWebContentsDelegate::SetOwnerWindow( void CommonWebContentsDelegate::SetOwnerWindow(
content::WebContents* web_contents, NativeWindow* owner_window) { content::WebContents* web_contents, NativeWindow* owner_window) {
owner_window_ = owner_window ? owner_window->GetWeakPtr() : nullptr; owner_window_ = owner_window ? owner_window->GetWeakPtr() : nullptr;
NativeWindowRelay* relay = new NativeWindowRelay(owner_window_); auto relay = base::MakeUnique<NativeWindowRelay>(owner_window_);
if (owner_window) { if (owner_window) {
web_contents->SetUserData(relay->key, relay); web_contents->SetUserData(relay->key, std::move(relay));
} else { } else {
web_contents->RemoveUserData(relay->key); web_contents->RemoveUserData(relay->key);
delete relay; relay.reset();
} }
} }

View file

@ -13,6 +13,7 @@
#include "atom/common/native_mate_converters/value_converter.h" #include "atom/common/native_mate_converters/value_converter.h"
#include "atom/common/options_switches.h" #include "atom/common/options_switches.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/memory/ptr_util.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "cc/base/switches.h" #include "cc/base/switches.h"
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
@ -44,7 +45,7 @@ WebContentsPreferences::WebContentsPreferences(
copied.Delete("session"); copied.Delete("session");
mate::ConvertFromV8(isolate, copied.GetHandle(), &web_preferences_); mate::ConvertFromV8(isolate, copied.GetHandle(), &web_preferences_);
web_contents->SetUserData(UserDataKey(), this); web_contents->SetUserData(UserDataKey(), base::WrapUnique(this));
instances_.push_back(this); instances_.push_back(this);
} }