| 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 "headless/lib/browser/headless_browser_impl.h" | 5 #include "headless/lib/browser/headless_browser_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 } | 47 } |
| 48 | 48 |
| 49 } // namespace | 49 } // namespace |
| 50 | 50 |
| 51 HeadlessBrowserImpl::HeadlessBrowserImpl( | 51 HeadlessBrowserImpl::HeadlessBrowserImpl( |
| 52 const base::Callback<void(HeadlessBrowser*)>& on_start_callback, | 52 const base::Callback<void(HeadlessBrowser*)>& on_start_callback, |
| 53 HeadlessBrowser::Options options) | 53 HeadlessBrowser::Options options) |
| 54 : on_start_callback_(on_start_callback), | 54 : on_start_callback_(on_start_callback), |
| 55 options_(std::move(options)), | 55 options_(std::move(options)), |
| 56 browser_main_parts_(nullptr), | 56 browser_main_parts_(nullptr), |
| 57 default_browser_context_(nullptr), |
| 57 weak_ptr_factory_(this) {} | 58 weak_ptr_factory_(this) {} |
| 58 | 59 |
| 59 HeadlessBrowserImpl::~HeadlessBrowserImpl() {} | 60 HeadlessBrowserImpl::~HeadlessBrowserImpl() {} |
| 60 | 61 |
| 61 HeadlessBrowserContext::Builder | 62 HeadlessBrowserContext::Builder |
| 62 HeadlessBrowserImpl::CreateBrowserContextBuilder() { | 63 HeadlessBrowserImpl::CreateBrowserContextBuilder() { |
| 63 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 64 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 64 return HeadlessBrowserContext::Builder(this); | 65 return HeadlessBrowserContext::Builder(this); |
| 65 } | 66 } |
| 66 | 67 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 browser_contexts_[browser_context->Id()] = std::move(browser_context); | 152 browser_contexts_[browser_context->Id()] = std::move(browser_context); |
| 152 | 153 |
| 153 return result; | 154 return result; |
| 154 } | 155 } |
| 155 | 156 |
| 156 void HeadlessBrowserImpl::DestroyBrowserContext( | 157 void HeadlessBrowserImpl::DestroyBrowserContext( |
| 157 HeadlessBrowserContextImpl* browser_context) { | 158 HeadlessBrowserContextImpl* browser_context) { |
| 158 auto it = browser_contexts_.find(browser_context->Id()); | 159 auto it = browser_contexts_.find(browser_context->Id()); |
| 159 DCHECK(it != browser_contexts_.end()); | 160 DCHECK(it != browser_contexts_.end()); |
| 160 browser_contexts_.erase(it); | 161 browser_contexts_.erase(it); |
| 162 if (default_browser_context_ == browser_context) |
| 163 SetDefaultBrowserContext(nullptr); |
| 164 } |
| 165 |
| 166 void HeadlessBrowserImpl::SetDefaultBrowserContext( |
| 167 HeadlessBrowserContext* browser_context) { |
| 168 DCHECK(!browser_context || |
| 169 this == HeadlessBrowserContextImpl::From(browser_context)->browser()); |
| 170 default_browser_context_ = browser_context; |
| 171 } |
| 172 |
| 173 HeadlessBrowserContext* HeadlessBrowserImpl::GetDefaultBrowserContext() { |
| 174 return default_browser_context_; |
| 161 } | 175 } |
| 162 | 176 |
| 163 base::WeakPtr<HeadlessBrowserImpl> HeadlessBrowserImpl::GetWeakPtr() { | 177 base::WeakPtr<HeadlessBrowserImpl> HeadlessBrowserImpl::GetWeakPtr() { |
| 164 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 178 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 165 return weak_ptr_factory_.GetWeakPtr(); | 179 return weak_ptr_factory_.GetWeakPtr(); |
| 166 } | 180 } |
| 167 | 181 |
| 168 aura::WindowTreeHost* HeadlessBrowserImpl::window_tree_host() const { | 182 aura::WindowTreeHost* HeadlessBrowserImpl::window_tree_host() const { |
| 169 return window_tree_host_.get(); | 183 return window_tree_host_.get(); |
| 170 } | 184 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 | 224 |
| 211 // Child processes should not end up here. | 225 // Child processes should not end up here. |
| 212 base::CommandLine command_line(options.argc, options.argv); | 226 base::CommandLine command_line(options.argc, options.argv); |
| 213 DCHECK(!command_line.HasSwitch(switches::kProcessType)); | 227 DCHECK(!command_line.HasSwitch(switches::kProcessType)); |
| 214 #endif | 228 #endif |
| 215 return RunContentMain(std::move(options), | 229 return RunContentMain(std::move(options), |
| 216 std::move(on_browser_start_callback)); | 230 std::move(on_browser_start_callback)); |
| 217 } | 231 } |
| 218 | 232 |
| 219 } // namespace headless | 233 } // namespace headless |
| OLD | NEW |