Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1006)

Unified Diff: chrome/browser/extensions/api/tab_capture/offscreen_tab.cc

Issue 2310683002: Remove most ScopedVector usage from c/b/extensions. (Closed)
Patch Set: cleaned up Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/tab_capture/offscreen_tab.cc
diff --git a/chrome/browser/extensions/api/tab_capture/offscreen_tab.cc b/chrome/browser/extensions/api/tab_capture/offscreen_tab.cc
index d7e26772b4f17f67bb2c13209f3559be533ac4f9..67b963d01e67aae69018f9dbde1616248441bfac 100644
--- a/chrome/browser/extensions/api/tab_capture/offscreen_tab.cc
+++ b/chrome/browser/extensions/api/tab_capture/offscreen_tab.cc
@@ -8,6 +8,7 @@
#include "base/bind.h"
#include "base/macros.h"
+#include "base/memory/ptr_util.h"
#include "chrome/browser/extensions/api/tab_capture/tab_capture_registry.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/web_contents_sizer.h"
@@ -57,13 +58,21 @@ OffscreenTab* OffscreenTabsOwner::OpenNewTab(
if (tabs_.size() >= kMaxOffscreenTabsPerExtension)
return nullptr; // Maximum number of offscreen tabs reached.
- tabs_.push_back(new OffscreenTab(this));
+ // OffscreenTab cannot be created with MakeUnique<OffscreenTab> since the
+ // constructor is protected. So create it separately, and then move it to
+ // |tabs_| below.
+ std::unique_ptr<OffscreenTab> offscreen_tab(new OffscreenTab(this));
+ tabs_.push_back(std::move(offscreen_tab));
tabs_.back()->Start(start_url, initial_size, optional_presentation_id);
- return tabs_.back();
+ return tabs_.back().get();
}
void OffscreenTabsOwner::DestroyTab(OffscreenTab* tab) {
- const auto it = std::find(tabs_.begin(), tabs_.end(), tab);
+ const auto it =
+ std::find_if(tabs_.begin(), tabs_.end(),
+ [tab](const std::unique_ptr<OffscreenTab>& offscreen_tab) {
+ return offscreen_tab.get() == tab;
+ });
if (it != tabs_.end())
tabs_.erase(it);
asargent_no_longer_on_chrome 2016/09/06 22:12:40 optional: a simpler way to write this method may b
lazyboy 2016/09/06 23:49:38 Done.
}

Powered by Google App Engine
This is Rietveld 408576698