Skip to content

Commit

Permalink
Remove linked_ptr usage in //base.
Browse files Browse the repository at this point in the history
And clean up some code that didn't IWYU.

BUG=556939

Review URL: https://codereview.chromium.org/1641563002

Cr-Commit-Position: refs/heads/master@{#372977}
  • Loading branch information
zetafunction authored and Commit bot committed Feb 2, 2016
1 parent 2b31885 commit 2588941
Show file tree
Hide file tree
Showing 20 changed files with 106 additions and 121 deletions.
2 changes: 1 addition & 1 deletion base/supports_user_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ SupportsUserData::Data* SupportsUserData::GetUserData(const void* key) const {

void SupportsUserData::SetUserData(const void* key, Data* data) {
DCHECK(thread_checker_.CalledOnValidThread());
user_data_[key] = linked_ptr<Data>(data);
user_data_[key] = make_scoped_ptr(data);
}

void SupportsUserData::RemoveUserData(const void* key) {
Expand Down
4 changes: 2 additions & 2 deletions base/supports_user_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

#include "base/base_export.h"
#include "base/macros.h"
#include "base/memory/linked_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/threading/thread_checker.h"

namespace base {
Expand Down Expand Up @@ -47,7 +47,7 @@ class BASE_EXPORT SupportsUserData {
virtual ~SupportsUserData();

private:
typedef std::map<const void*, linked_ptr<Data> > DataMap;
using DataMap = std::map<const void*, scoped_ptr<Data>>;

// Externally-defined data accessible by key.
DataMap user_data_;
Expand Down
9 changes: 4 additions & 5 deletions base/threading/sequenced_worker_pool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/linked_ptr.h"
#include "base/memory/scoped_ptr.h"
#include "base/stl_util.h"
#include "base/strings/stringprintf.h"
#include "base/synchronization/condition_variable.h"
Expand Down Expand Up @@ -448,7 +448,7 @@ class SequencedWorkerPool::Inner {
// Owning pointers to all threads we've created so far, indexed by
// ID. Since we lazily create threads, this may be less than
// max_threads_ and will be initially empty.
typedef std::map<PlatformThreadId, linked_ptr<Worker> > ThreadMap;
using ThreadMap = std::map<PlatformThreadId, scoped_ptr<Worker>>;
ThreadMap threads_;

// Set to true when we're in the process of creating another thread.
Expand Down Expand Up @@ -788,9 +788,8 @@ void SequencedWorkerPool::Inner::ThreadLoop(Worker* this_worker) {
AutoLock lock(lock_);
DCHECK(thread_being_created_);
thread_being_created_ = false;
std::pair<ThreadMap::iterator, bool> result =
threads_.insert(
std::make_pair(this_worker->tid(), make_linked_ptr(this_worker)));
auto result = threads_.insert(
std::make_pair(this_worker->tid(), make_scoped_ptr(this_worker)));
DCHECK(result.second);

while (true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,8 @@ bool ChromeWebViewInternalShowContextMenuFunction::RunAsyncSafe(
webview::ShowContextMenu::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get());

// TODO(lazyboy): Actually implement filtering menu items, we pass NULL for
// now.
guest->ShowContextMenu(params->request_id, NULL);
// TODO(lazyboy): Actually implement filtering menu items.
guest->ShowContextMenu(params->request_id);

SendResponse(true);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ bool ChromeWebViewGuestDelegate::HandleContextMenu(
MenuModelToValue(pending_menu_->menu_model());
args->Set(webview::kContextMenuItems, items.release());
args->SetInteger(webview::kRequestId, request_id);
web_view_guest()->DispatchEventToView(
new GuestViewEvent(webview::kEventContextMenuShow, std::move(args)));
web_view_guest()->DispatchEventToView(make_scoped_ptr(
new GuestViewEvent(webview::kEventContextMenuShow, std::move(args))));
return true;
}

Expand Down Expand Up @@ -99,18 +99,15 @@ scoped_ptr<base::ListValue> ChromeWebViewGuestDelegate::MenuModelToValue(
return items;
}

void ChromeWebViewGuestDelegate::OnShowContextMenu(
int request_id,
const MenuItemVector* items) {
if (!pending_menu_.get())
void ChromeWebViewGuestDelegate::OnShowContextMenu(int request_id) {
if (!pending_menu_)
return;

// Make sure this was the correct request.
if (request_id != pending_context_menu_request_id_)
return;

// TODO(lazyboy): Implement.
DCHECK(!items);

ContextMenuDelegate* menu_delegate =
ContextMenuDelegate::FromWebContents(guest_web_contents());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ChromeWebViewGuestDelegate : public WebViewGuestDelegate {
// WebViewGuestDelegate implementation.
bool HandleContextMenu(const content::ContextMenuParams& params) override;
void OnDidInitialize() override;
void OnShowContextMenu(int request_id, const MenuItemVector* items) override;
void OnShowContextMenu(int request_id) override;
bool ShouldHandleFindRequestsForEmbedder() const override;

WebViewGuest* web_view_guest() const { return web_view_guest_; }
Expand Down
6 changes: 2 additions & 4 deletions chrome/browser/printing/cloud_print/privet_notifications.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,11 @@ void PrivetNotificationsListener::DeviceChanged(
return; // Already saw this device.
}

linked_ptr<DeviceContext> device_context(new DeviceContext);

scoped_ptr<DeviceContext>& device_context = devices_seen_[name];
device_context.reset(new DeviceContext);
device_context->notification_may_be_active = false;
device_context->registered = !description.id.empty();

devices_seen_.insert(make_pair(name, device_context));

if (!device_context->registered) {
device_context->privet_http_resolution =
privet_http_factory_->CreatePrivetHTTP(name);
Expand Down
3 changes: 2 additions & 1 deletion chrome/browser/printing/cloud_print/privet_notifications.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <map>
#include <string>

#include "base/memory/scoped_ptr.h"
#include "chrome/browser/notifications/notification_delegate.h"
#include "chrome/browser/printing/cloud_print/privet_device_lister.h"
#include "chrome/browser/printing/cloud_print/privet_http.h"
Expand Down Expand Up @@ -75,7 +76,7 @@ class PrivetNotificationsListener {
scoped_ptr<PrivetHTTPClient> privet_http;
};

typedef std::map<std::string, linked_ptr<DeviceContext> > DeviceContextMap;
using DeviceContextMap = std::map<std::string, scoped_ptr<DeviceContext>>;

void CreateInfoOperation(scoped_ptr<PrivetHTTPClient> http_client);
void OnPrivetInfoDone(DeviceContext* device,
Expand Down
14 changes: 8 additions & 6 deletions components/guest_view/browser/guest_view_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,8 @@ void GuestViewBase::DispatchOnResizeEvent(const gfx::Size& old_size,
args->SetInteger(kOldHeight, old_size.height());
args->SetInteger(kNewWidth, new_size.width());
args->SetInteger(kNewHeight, new_size.height());
DispatchEventToGuestProxy(new GuestViewEvent(kEventResize, std::move(args)));
DispatchEventToGuestProxy(
make_scoped_ptr(new GuestViewEvent(kEventResize, std::move(args))));
}

gfx::Size GuestViewBase::GetDefaultSize() const {
Expand Down Expand Up @@ -752,14 +753,15 @@ void GuestViewBase::OnZoomChanged(
}
}

void GuestViewBase::DispatchEventToGuestProxy(GuestViewEvent* event) {
void GuestViewBase::DispatchEventToGuestProxy(
scoped_ptr<GuestViewEvent> event) {
event->Dispatch(this, guest_instance_id_);
}

void GuestViewBase::DispatchEventToView(GuestViewEvent* event) {
void GuestViewBase::DispatchEventToView(scoped_ptr<GuestViewEvent> event) {
if (!attached() &&
(!CanRunInDetachedState() || !can_owner_receive_events())) {
pending_events_.push_back(linked_ptr<GuestViewEvent>(event));
pending_events_.push_back(std::move(event));
return;
}

Expand All @@ -770,9 +772,9 @@ void GuestViewBase::SendQueuedEvents() {
if (!attached())
return;
while (!pending_events_.empty()) {
linked_ptr<GuestViewEvent> event_ptr = pending_events_.front();
scoped_ptr<GuestViewEvent> event_ptr = std::move(pending_events_.front());
pending_events_.pop_front();
event_ptr.release()->Dispatch(this, view_instance_id_);
event_ptr->Dispatch(this, view_instance_id_);
}
}

Expand Down
7 changes: 4 additions & 3 deletions components/guest_view/browser/guest_view_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <queue>

#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/values.h"
#include "components/guest_view/common/guest_view_constants.h"
Expand Down Expand Up @@ -112,10 +113,10 @@ class GuestViewBase : public content::BrowserPluginGuestDelegate,
virtual int GetTaskPrefix() const = 0;

// Dispatches an event to the guest proxy.
void DispatchEventToGuestProxy(GuestViewEvent* event);
void DispatchEventToGuestProxy(scoped_ptr<GuestViewEvent> event);

// Dispatches an event to the view.
void DispatchEventToView(GuestViewEvent* event);
void DispatchEventToView(scoped_ptr<GuestViewEvent> event);

// This creates a WebContents and initializes |this| GuestViewBase to use the
// newly created WebContents.
Expand Down Expand Up @@ -431,7 +432,7 @@ class GuestViewBase : public content::BrowserPluginGuestDelegate,

// This is a queue of Events that are destined to be sent to the embedder once
// the guest is attached to a particular embedder.
std::deque<linked_ptr<GuestViewEvent> > pending_events_;
std::deque<scoped_ptr<GuestViewEvent>> pending_events_;

// The opener guest view.
base::WeakPtr<GuestViewBase> opener_;
Expand Down
4 changes: 2 additions & 2 deletions components/guest_view/browser/guest_view_event.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <utility>

#include "base/logging.h"
#include "components/guest_view/browser/guest_view_base.h"
#include "components/guest_view/browser/guest_view_manager.h"

Expand All @@ -19,10 +20,9 @@ GuestViewEvent::~GuestViewEvent() {
}

void GuestViewEvent::Dispatch(GuestViewBase* guest, int instance_id) {
DCHECK(args_) << "Dispatch was probably invoked twice!";
GuestViewManager::FromBrowserContext(guest->browser_context())
->DispatchEvent(name_, std::move(args_), guest, instance_id);

delete this;
}

} // namespace guest_view
3 changes: 1 addition & 2 deletions components/guest_view/browser/guest_view_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ class GuestViewEvent {
~GuestViewEvent();

// This method will dispatch the event to the specified |guest|'s embedder and
// use the provided |instance_id| for routing. After dispatch, this object
// will self-destruct.
// use the provided |instance_id| for routing.
void Dispatch(GuestViewBase* guest, int instance_id);

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ void ExtensionOptionsGuest::DidInitialize(

void ExtensionOptionsGuest::GuestViewDidStopLoading() {
scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
DispatchEventToView(new GuestViewEvent(
extension_options_internal::OnLoad::kEventName, std::move(args)));
DispatchEventToView(make_scoped_ptr(new GuestViewEvent(
extension_options_internal::OnLoad::kEventName, std::move(args))));
}

const char* ExtensionOptionsGuest::GetAPINamespace() const {
Expand All @@ -148,9 +148,9 @@ void ExtensionOptionsGuest::OnPreferredSizeChanged(const gfx::Size& pref_size) {
// Convert the size from physical pixels to logical pixels.
options.width = PhysicalPixelsToLogicalPixels(pref_size.width());
options.height = PhysicalPixelsToLogicalPixels(pref_size.height());
DispatchEventToView(new GuestViewEvent(
DispatchEventToView(make_scoped_ptr(new GuestViewEvent(
extension_options_internal::OnPreferredSizeChanged::kEventName,
options.ToValue()));
options.ToValue())));
}

bool ExtensionOptionsGuest::ShouldHandleFindRequestsForEmbedder() const {
Expand Down Expand Up @@ -180,9 +180,9 @@ WebContents* ExtensionOptionsGuest::OpenURLFromTab(
}

void ExtensionOptionsGuest::CloseContents(WebContents* source) {
DispatchEventToView(
DispatchEventToView(make_scoped_ptr(
new GuestViewEvent(extension_options_internal::OnClose::kEventName,
make_scoped_ptr(new base::DictionaryValue())));
make_scoped_ptr(new base::DictionaryValue()))));
}

bool ExtensionOptionsGuest::HandleContextMenu(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ void ExtensionViewGuest::DidCommitProvisionalLoadForFrame(

scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
args->SetString(guest_view::kUrl, url_.spec());
DispatchEventToView(
new GuestViewEvent(extensionview::kEventLoadCommit, std::move(args)));
DispatchEventToView(make_scoped_ptr(
new GuestViewEvent(extensionview::kEventLoadCommit, std::move(args))));
}

void ExtensionViewGuest::DidNavigateMainFrame(
Expand Down
24 changes: 11 additions & 13 deletions extensions/browser/guest_view/web_view/web_view_find_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ WebViewFindHelper::~WebViewFindHelper() {
}

void WebViewFindHelper::CancelAllFindSessions() {
current_find_session_ = linked_ptr<WebViewFindHelper::FindInfo>();
current_find_session_ = nullptr;
while (!find_info_map_.empty()) {
find_info_map_.begin()->second->SendResponse(true /* canceled */);
find_info_map_.erase(find_info_map_.begin());
}
if (find_update_event_.get())
if (find_update_event_)
DispatchFindUpdateEvent(true /* canceled */, true /* final_update */);
find_update_event_.reset();
}
Expand All @@ -40,8 +40,8 @@ void WebViewFindHelper::DispatchFindUpdateEvent(bool canceled,
args->SetBoolean(webview::kFindCanceled, canceled);
args->SetBoolean(webview::kFindFinalUpdate, final_update);
DCHECK(webview_guest_);
webview_guest_->DispatchEventToView(
new GuestViewEvent(webview::kEventFindReply, std::move(args)));
webview_guest_->DispatchEventToView(make_scoped_ptr(
new GuestViewEvent(webview::kEventFindReply, std::move(args))));
}

void WebViewFindHelper::EndFindSession(int session_request_id, bool canceled) {
Expand Down Expand Up @@ -100,17 +100,16 @@ void WebViewFindHelper::Find(
std::pair<FindInfoMap::iterator, bool> insert_result =
find_info_map_.insert(std::make_pair(
current_find_request_id_,
linked_ptr<
WebViewFindHelper::FindInfo>(new WebViewFindHelper::FindInfo(
current_find_request_id_, search_text, options, find_function))));
make_scoped_refptr(new FindInfo(current_find_request_id_, search_text,
options, find_function))));
// No duplicate insertions.
DCHECK(insert_result.second);

// Find options including the implicit |findNext| field.
blink::WebFindOptions* full_options = insert_result.first->second->options();

// Set |findNext| implicitly.
if (current_find_session_.get()) {
if (current_find_session_) {
const base::string16& current_search_text =
current_find_session_->search_text();
bool current_match_case = current_find_session_->options()->matchCase;
Expand All @@ -122,7 +121,7 @@ void WebViewFindHelper::Find(
}

// Link find requests that are a part of the same find session.
if (full_options->findNext && current_find_session_.get()) {
if (full_options->findNext && current_find_session_) {
DCHECK(current_find_request_id_ != current_find_session_->request_id());
current_find_session_->AddFindNextRequest(
insert_result.first->second->AsWeakPtr());
Expand Down Expand Up @@ -155,7 +154,7 @@ void WebViewFindHelper::FindReply(int request_id,
return;

// This find request must be a part of an existing find session.
DCHECK(current_find_session_.get());
DCHECK(current_find_session_);

WebViewFindHelper::FindInfo* find_info = find_iterator->second.get();

Expand Down Expand Up @@ -260,9 +259,6 @@ WebViewFindHelper::FindInfo::FindInfo(
weak_ptr_factory_(this) {
}

WebViewFindHelper::FindInfo::~FindInfo() {
}

void WebViewFindHelper::FindInfo::AggregateResults(
int number_of_matches,
const gfx::Rect& selection_rect,
Expand All @@ -289,4 +285,6 @@ void WebViewFindHelper::FindInfo::SendResponse(bool canceled) {
find_function_->SendResponse(true);
}

WebViewFindHelper::FindInfo::~FindInfo() {}

} // namespace extensions
Loading

0 comments on commit 2588941

Please sign in to comment.