Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/api/tab_capture/offscreen_tab.h" | 5 #include "chrome/browser/extensions/api/tab_capture/offscreen_tab.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ptr_util.h" | |
| 11 #include "chrome/browser/extensions/api/tab_capture/tab_capture_registry.h" | 12 #include "chrome/browser/extensions/api/tab_capture/tab_capture_registry.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/ui/web_contents_sizer.h" | 14 #include "chrome/browser/ui/web_contents_sizer.h" |
| 14 #include "content/public/browser/render_widget_host_view.h" | 15 #include "content/public/browser/render_widget_host_view.h" |
| 15 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 16 #include "extensions/browser/extension_host.h" | 17 #include "extensions/browser/extension_host.h" |
| 17 #include "extensions/browser/process_manager.h" | 18 #include "extensions/browser/process_manager.h" |
| 18 | 19 |
| 19 using content::WebContents; | 20 using content::WebContents; |
| 20 | 21 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 50 return FromWebContents(extension_web_contents); | 51 return FromWebContents(extension_web_contents); |
| 51 } | 52 } |
| 52 | 53 |
| 53 OffscreenTab* OffscreenTabsOwner::OpenNewTab( | 54 OffscreenTab* OffscreenTabsOwner::OpenNewTab( |
| 54 const GURL& start_url, | 55 const GURL& start_url, |
| 55 const gfx::Size& initial_size, | 56 const gfx::Size& initial_size, |
| 56 const std::string& optional_presentation_id) { | 57 const std::string& optional_presentation_id) { |
| 57 if (tabs_.size() >= kMaxOffscreenTabsPerExtension) | 58 if (tabs_.size() >= kMaxOffscreenTabsPerExtension) |
| 58 return nullptr; // Maximum number of offscreen tabs reached. | 59 return nullptr; // Maximum number of offscreen tabs reached. |
| 59 | 60 |
| 60 tabs_.push_back(new OffscreenTab(this)); | 61 // OffscreenTab cannot be created with MakeUnique<OffscreenTab> since the |
| 62 // constructor is protected. So create it separately, and then move it to | |
| 63 // |tabs_| below. | |
| 64 std::unique_ptr<OffscreenTab> offscreen_tab(new OffscreenTab(this)); | |
| 65 tabs_.push_back(std::move(offscreen_tab)); | |
| 61 tabs_.back()->Start(start_url, initial_size, optional_presentation_id); | 66 tabs_.back()->Start(start_url, initial_size, optional_presentation_id); |
| 62 return tabs_.back(); | 67 return tabs_.back().get(); |
| 63 } | 68 } |
| 64 | 69 |
| 65 void OffscreenTabsOwner::DestroyTab(OffscreenTab* tab) { | 70 void OffscreenTabsOwner::DestroyTab(OffscreenTab* tab) { |
| 66 const auto it = std::find(tabs_.begin(), tabs_.end(), tab); | 71 const auto it = |
| 72 std::find_if(tabs_.begin(), tabs_.end(), | |
| 73 [tab](const std::unique_ptr<OffscreenTab>& offscreen_tab) { | |
| 74 return offscreen_tab.get() == tab; | |
| 75 }); | |
| 67 if (it != tabs_.end()) | 76 if (it != tabs_.end()) |
| 68 tabs_.erase(it); | 77 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.
| |
| 69 } | 78 } |
| 70 | 79 |
| 71 OffscreenTab::OffscreenTab(OffscreenTabsOwner* owner) | 80 OffscreenTab::OffscreenTab(OffscreenTabsOwner* owner) |
| 72 : owner_(owner), | 81 : owner_(owner), |
| 73 profile_(Profile::FromBrowserContext( | 82 profile_(Profile::FromBrowserContext( |
| 74 owner->extension_web_contents()->GetBrowserContext()) | 83 owner->extension_web_contents()->GetBrowserContext()) |
| 75 ->CreateOffTheRecordProfile()), | 84 ->CreateOffTheRecordProfile()), |
| 76 capture_poll_timer_(false, false), | 85 capture_poll_timer_(false, false), |
| 77 content_capture_was_detected_(false) { | 86 content_capture_was_detected_(false) { |
| 78 DCHECK(profile_); | 87 DCHECK(profile_); |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 352 | 361 |
| 353 // Schedule the timer to check again in a second. | 362 // Schedule the timer to check again in a second. |
| 354 capture_poll_timer_.Start( | 363 capture_poll_timer_.Start( |
| 355 FROM_HERE, | 364 FROM_HERE, |
| 356 base::TimeDelta::FromSeconds(kPollIntervalInSeconds), | 365 base::TimeDelta::FromSeconds(kPollIntervalInSeconds), |
| 357 base::Bind(&OffscreenTab::DieIfContentCaptureEnded, | 366 base::Bind(&OffscreenTab::DieIfContentCaptureEnded, |
| 358 base::Unretained(this))); | 367 base::Unretained(this))); |
| 359 } | 368 } |
| 360 | 369 |
| 361 } // namespace extensions | 370 } // namespace extensions |
| OLD | NEW |