Chromium Code Reviews| 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.
|
| } |