Commit 0411baea authored by Avi Drissman's avatar Avi Drissman Committed by Commit Bot

Remove linked_ptr from chrome/test/.

BUG=556939

Change-Id: I769c70035bc61aaf43e6e5c3494df8e725e5bde0
Reviewed-on: https://chromium-review.googlesource.com/c/1356885Reviewed-by: default avatarJohn Chen <johnchen@chromium.org>
Commit-Queue: Avi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#613006}
parent 5c213c4f
......@@ -27,8 +27,8 @@ const BrowserInfo* ChromeImpl::GetBrowserInfo() const {
}
bool ChromeImpl::HasCrashedWebView() {
for (auto it = web_views_.begin(); it != web_views_.end(); ++it) {
if ((*it)->WasCrashed())
for (const auto& view : web_views_) {
if (view->WasCrashed())
return true;
}
return false;
......@@ -59,10 +59,8 @@ Status ChromeImpl::GetWebViewIds(std::list<std::string>* web_view_ids,
return status;
UpdateWebViews(views_info, w3c_compliant);
std::list<std::string> web_view_ids_tmp;
for (WebViewList::const_iterator web_view_iter = web_views_.begin();
web_view_iter != web_views_.end(); ++web_view_iter) {
web_view_ids_tmp.push_back((*web_view_iter)->GetId());
}
for (const auto& view : web_views_)
web_view_ids_tmp.push_back(view->GetId());
web_view_ids->swap(web_view_ids_tmp);
return Status(kOk);
}
......@@ -87,9 +85,8 @@ void ChromeImpl::UpdateWebViews(const WebViewsInfo& views_info,
if (devtools_http_client_->IsBrowserWindow(view) &&
!view.IsInactiveBackgroundPage()) {
bool found = false;
for (WebViewList::const_iterator web_view_iter = web_views_.begin();
web_view_iter != web_views_.end(); ++web_view_iter) {
if ((*web_view_iter)->GetId() == view.id) {
for (const auto& web_view : web_views_) {
if (web_view->GetId() == view.id) {
found = true;
break;
}
......@@ -101,19 +98,19 @@ void ChromeImpl::UpdateWebViews(const WebViewsInfo& views_info,
client->AddListener(listener.get());
// OnConnected will fire when DevToolsClient connects later.
CHECK(!page_load_strategy_.empty());
web_views_.push_back(make_linked_ptr(new WebViewImpl(
web_views_.push_back(std::make_unique<WebViewImpl>(
view.id, w3c_compliant, devtools_http_client_->browser_info(),
std::move(client), devtools_http_client_->device_metrics(),
page_load_strategy_)));
page_load_strategy_));
}
}
}
}
Status ChromeImpl::GetWebViewById(const std::string& id, WebView** web_view) {
for (auto it = web_views_.begin(); it != web_views_.end(); ++it) {
if ((*it)->GetId() == id) {
*web_view = (*it).get();
for (const auto& view : web_views_) {
if (view->GetId() == id) {
*web_view = view.get();
return Status(kOk);
}
}
......
......@@ -11,7 +11,6 @@
#include <vector>
#include "base/compiler_specific.h"
#include "base/memory/linked_ptr.h"
#include "base/values.h"
#include "chrome/test/chromedriver/chrome/chrome.h"
......@@ -85,12 +84,10 @@ class ChromeImpl : public Chrome {
std::unique_ptr<DevToolsClient> devtools_websocket_client_;
private:
typedef std::list<linked_ptr<WebViewImpl> > WebViewList;
void UpdateWebViews(const WebViewsInfo& views_info, bool w3c_compliant);
// Web views in this list are in the same order as they are opened.
WebViewList web_views_;
std::list<std::unique_ptr<WebViewImpl>> web_views_;
std::vector<std::unique_ptr<DevToolsEventListener>> devtools_event_listeners_;
std::string page_load_strategy_;
};
......
......@@ -334,8 +334,8 @@ Status DevToolsClientImpl::SendCommandInternal(
}
if (expect_response) {
linked_ptr<ResponseInfo> response_info =
make_linked_ptr(new ResponseInfo(method));
scoped_refptr<ResponseInfo> response_info =
base::MakeRefCounted<ResponseInfo>(method);
if (timeout)
response_info->command_timeout = *timeout;
response_info_map_[command_id] = response_info;
......@@ -472,7 +472,7 @@ Status DevToolsClientImpl::ProcessEvent(const internal::InspectorEvent& event) {
base::DictionaryValue enable_params;
enable_params.SetString("purpose", "detect if alert blocked any cmds");
Status enable_status = SendCommand("Inspector.enable", enable_params);
for (ResponseInfoMap::const_iterator iter = response_info_map_.begin();
for (auto iter = response_info_map_.begin();
iter != response_info_map_.end(); ++iter) {
if (iter->first > max_id)
continue;
......@@ -526,7 +526,7 @@ Status DevToolsClientImpl::ProcessCommandResponse(
if (iter == response_info_map_.end())
return Status(kUnknownError, "unexpected command response");
linked_ptr<ResponseInfo> response_info = response_info_map_[response.id];
scoped_refptr<ResponseInfo> response_info = response_info_map_[response.id];
response_info_map_.erase(response.id);
if (response_info->state != kIgnored) {
......
......@@ -13,7 +13,8 @@
#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "base/memory/linked_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_refptr.h"
#include "chrome/test/chromedriver/chrome/devtools_client.h"
#include "chrome/test/chromedriver/net/sync_websocket_factory.h"
#include "chrome/test/chromedriver/net/timeout.h"
......@@ -128,16 +129,19 @@ class DevToolsClientImpl : public DevToolsClient {
// The response has been received.
kReceived
};
struct ResponseInfo {
struct ResponseInfo : public base::RefCounted<ResponseInfo> {
public:
explicit ResponseInfo(const std::string& method);
~ResponseInfo();
ResponseState state;
std::string method;
internal::InspectorCommandResponse response;
Timeout command_timeout;
private:
friend class base::RefCounted<ResponseInfo>;
~ResponseInfo();
};
typedef std::map<int, linked_ptr<ResponseInfo> > ResponseInfoMap;
Status SendCommandInternal(
const std::string& method,
......@@ -172,8 +176,8 @@ class DevToolsClientImpl : public DevToolsClient {
std::list<DevToolsEventListener*> unnotified_event_listeners_;
const internal::InspectorEvent* unnotified_event_;
std::list<DevToolsEventListener*> unnotified_cmd_response_listeners_;
linked_ptr<ResponseInfo> unnotified_cmd_response_info_;
ResponseInfoMap response_info_map_;
scoped_refptr<ResponseInfo> unnotified_cmd_response_info_;
std::map<int, scoped_refptr<ResponseInfo>> response_info_map_;
int next_id_;
int stack_count_;
......
......@@ -14,7 +14,6 @@
#include "base/bind_helpers.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/memory/linked_ptr.h"
#include "base/memory/ptr_util.h"
#include "base/message_loop/message_loop_current.h"
#include "base/run_loop.h"
......@@ -60,8 +59,8 @@ void ExecuteCreateSession(
std::string new_id = session_id;
if (new_id.empty())
new_id = GenerateId();
std::unique_ptr<Session> session(new Session(new_id));
std::unique_ptr<base::Thread> thread(new base::Thread(new_id));
std::unique_ptr<Session> session = std::make_unique<Session>(new_id);
std::unique_ptr<base::Thread> thread = std::make_unique<base::Thread>(new_id);
if (!thread->Start()) {
callback.Run(
Status(kUnknownError, "failed to start a thread for the new session"),
......@@ -72,8 +71,7 @@ void ExecuteCreateSession(
thread->task_runner()->PostTask(
FROM_HERE, base::BindOnce(&SetThreadLocalSession, std::move(session)));
session_thread_map
->insert(std::make_pair(new_id, make_linked_ptr(thread.release())));
session_thread_map->insert(std::make_pair(new_id, std::move(thread)));
init_session_cmd.Run(params, new_id, callback);
}
......@@ -120,9 +118,8 @@ void ExecuteGetSessions(const Command& session_capabilities_command,
base::RunLoop run_loop;
for (SessionThreadMap::const_iterator iter = session_thread_map->begin();
iter != session_thread_map->end();
++iter) {
for (auto iter = session_thread_map->begin();
iter != session_thread_map->end(); ++iter) {
session_capabilities_command.Run(params,
iter->first,
base::Bind(
......@@ -172,9 +169,8 @@ void ExecuteQuitAll(
return;
}
base::RunLoop run_loop;
for (SessionThreadMap::const_iterator iter = session_thread_map->begin();
iter != session_thread_map->end();
++iter) {
for (auto iter = session_thread_map->begin();
iter != session_thread_map->end(); ++iter) {
quit_command.Run(params,
iter->first,
base::Bind(&OnSessionQuit,
......
......@@ -137,8 +137,8 @@ TEST(CommandsTest, GetSessions) {
SessionThreadMap map;
Session session("id");
Session session2("id2");
map[session.id] = make_linked_ptr(new base::Thread("1"));
map[session2.id] = make_linked_ptr(new base::Thread("2"));
map[session.id] = std::make_unique<base::Thread>("1");
map[session2.id] = std::make_unique<base::Thread>("2");
int count = 0;
......@@ -182,8 +182,8 @@ TEST(CommandsTest, QuitAll) {
SessionThreadMap map;
Session session("id");
Session session2("id2");
map[session.id] = make_linked_ptr(new base::Thread("1"));
map[session2.id] = make_linked_ptr(new base::Thread("2"));
map[session.id] = std::make_unique<base::Thread>("1");
map[session2.id] = std::make_unique<base::Thread>("2");
int count = 0;
Command cmd = base::Bind(&ExecuteStubQuit, &count);
......@@ -225,13 +225,13 @@ void OnSimpleCommand(base::RunLoop* run_loop,
TEST(CommandsTest, ExecuteSessionCommand) {
SessionThreadMap map;
linked_ptr<base::Thread> thread(new base::Thread("1"));
auto thread = std::make_unique<base::Thread>("1");
ASSERT_TRUE(thread->Start());
std::string id("id");
thread->task_runner()->PostTask(
FROM_HERE,
base::BindOnce(&internal::CreateSessionOnSessionThreadForTesting, id));
map[id] = thread;
map[id] = std::move(thread);
base::DictionaryValue params;
params.SetInteger("param", 5);
......@@ -319,10 +319,10 @@ void OnNoSuchSessionAndQuit(base::RunLoop* run_loop,
TEST(CommandsTest, ExecuteSessionCommandOnJustDeletedSession) {
SessionThreadMap map;
linked_ptr<base::Thread> thread(new base::Thread("1"));
auto thread = std::make_unique<base::Thread>("1");
ASSERT_TRUE(thread->Start());
std::string id("id");
map[id] = thread;
map[id] = std::move(thread);
base::MessageLoop loop;
base::RunLoop run_loop;
......@@ -713,14 +713,14 @@ void OnSessionCommand(base::RunLoop* run_loop,
TEST(CommandsTest, SuccessNotifyingCommandListeners) {
SessionThreadMap map;
linked_ptr<base::Thread> thread(new base::Thread("1"));
auto thread = std::make_unique<base::Thread>("1");
ASSERT_TRUE(thread->Start());
std::string id("id");
thread->task_runner()->PostTask(
FROM_HERE,
base::BindOnce(&internal::CreateSessionOnSessionThreadForTesting, id));
map[id] = thread;
map[id] = std::move(thread);
base::DictionaryValue params;
auto listener = std::make_unique<MockCommandListener>();
......@@ -804,19 +804,20 @@ void VerifySessionWasDeleted() {
TEST(CommandsTest, ErrorNotifyingCommandListeners) {
SessionThreadMap map;
linked_ptr<base::Thread> thread(new base::Thread("1"));
auto thread = std::make_unique<base::Thread>("1");
base::Thread* thread_ptr = thread.get();
ASSERT_TRUE(thread->Start());
std::string id("id");
thread->task_runner()->PostTask(
FROM_HERE,
base::BindOnce(&internal::CreateSessionOnSessionThreadForTesting, id));
map[id] = thread;
map[id] = std::move(thread);
// In SuccessNotifyingCommandListenersBeforeCommand, we verified BeforeCommand
// was called before (as opposed to after) command execution. We don't need to
// verify this again, so we can just add |listener| with PostTask.
auto listener = std::make_unique<FailingCommandListener>();
thread->task_runner()->PostTask(
thread_ptr->task_runner()->PostTask(
FROM_HERE, base::BindOnce(&AddListenerToSessionIfSessionExists,
std::move(listener)));
......@@ -836,6 +837,6 @@ TEST(CommandsTest, ErrorNotifyingCommandListeners) {
base::Bind(&OnFailBecauseErrorNotifyingListeners, &run_loop));
run_loop.Run();
thread->task_runner()->PostTask(FROM_HERE,
base::BindOnce(&VerifySessionWasDeleted));
thread_ptr->task_runner()->PostTask(FROM_HERE,
base::BindOnce(&VerifySessionWasDeleted));
}
......@@ -6,11 +6,11 @@
#define CHROME_TEST_CHROMEDRIVER_SESSION_THREAD_MAP_H_
#include <map>
#include <memory>
#include <string>
#include "base/memory/linked_ptr.h"
#include "base/threading/thread.h"
typedef std::map<std::string, linked_ptr<base::Thread> > SessionThreadMap;
using SessionThreadMap = std::map<std::string, std::unique_ptr<base::Thread>>;
#endif // CHROME_TEST_CHROMEDRIVER_SESSION_THREAD_MAP_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment