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/after_startup_task_utils.h" | 5 #include "chrome/browser/after_startup_task_utils.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
| 13 #include "base/process/process_info.h" | 13 #include "base/process/process_info.h" |
| 14 #include "base/rand_util.h" | 14 #include "base/rand_util.h" |
| 15 #include "base/synchronization/cancellation_flag.h" | 15 #include "base/synchronization/cancellation_flag.h" |
| 16 #include "base/task_runner.h" | 16 #include "base/task_runner.h" |
| 17 #include "base/tracked_objects.h" | 17 #include "base/tracked_objects.h" |
| 18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 19 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
| 20 #include "chrome/browser/ui/browser_iterator.h" | 20 #include "chrome/browser/ui/browser_list.h" |
| 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 22 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| 23 #include "content/public/browser/render_frame_host.h" | 23 #include "content/public/browser/render_frame_host.h" |
| 24 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
| 25 #include "content/public/browser/web_contents_observer.h" | 25 #include "content/public/browser/web_contents_observer.h" |
| 26 | 26 |
| 27 using content::BrowserThread; | 27 using content::BrowserThread; |
| 28 using content::WebContents; | 28 using content::WebContents; |
| 29 using content::WebContentsObserver; | 29 using content::WebContentsObserver; |
| 30 using StartupCompleteFlag = base::CancellationFlag; | 30 using StartupCompleteFlag = base::CancellationFlag; |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 155 DISALLOW_COPY_AND_ASSIGN(StartupObserver); | 155 DISALLOW_COPY_AND_ASSIGN(StartupObserver); |
| 156 }; | 156 }; |
| 157 | 157 |
| 158 void StartupObserver::Start() { | 158 void StartupObserver::Start() { |
| 159 // Signal completion quickly when there is no first page to load. | 159 // Signal completion quickly when there is no first page to load. |
| 160 const int kShortDelaySecs = 3; | 160 const int kShortDelaySecs = 3; |
| 161 base::TimeDelta delay = base::TimeDelta::FromSeconds(kShortDelaySecs); | 161 base::TimeDelta delay = base::TimeDelta::FromSeconds(kShortDelaySecs); |
| 162 | 162 |
| 163 #if !defined(OS_ANDROID) | 163 #if !defined(OS_ANDROID) |
| 164 WebContents* contents = nullptr; | 164 WebContents* contents = nullptr; |
| 165 for (chrome::BrowserIterator iter; !iter.done(); iter.Next()) { | 165 for (auto& browser : *BrowserList::GetInstance()) { |
|
sky
2016/01/28 03:04:05
Does this work? BrowserList::GerInstance() returns
scottmg
2016/01/28 03:09:23
It's a BrowserList& here. The * is needed in a ran
| |
| 166 contents = (*iter)->tab_strip_model()->GetActiveWebContents(); | 166 contents = browser->tab_strip_model()->GetActiveWebContents(); |
| 167 if (contents && contents->GetMainFrame() && | 167 if (contents && contents->GetMainFrame() && |
| 168 contents->GetMainFrame()->GetVisibilityState() == | 168 contents->GetMainFrame()->GetVisibilityState() == |
| 169 blink::WebPageVisibilityStateVisible) { | 169 blink::WebPageVisibilityStateVisible) { |
| 170 break; | 170 break; |
| 171 } | 171 } |
| 172 } | 172 } |
| 173 | 173 |
| 174 if (contents) { | 174 if (contents) { |
| 175 // Give the page time to finish loading. | 175 // Give the page time to finish loading. |
| 176 const int kLongerDelayMins = 3; | 176 const int kLongerDelayMins = 3; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 223 return ::IsBrowserStartupComplete(); | 223 return ::IsBrowserStartupComplete(); |
| 224 } | 224 } |
| 225 | 225 |
| 226 void AfterStartupTaskUtils::UnsafeResetForTesting() { | 226 void AfterStartupTaskUtils::UnsafeResetForTesting() { |
| 227 DCHECK(g_after_startup_tasks.Get().empty()); | 227 DCHECK(g_after_startup_tasks.Get().empty()); |
| 228 if (!IsBrowserStartupComplete()) | 228 if (!IsBrowserStartupComplete()) |
| 229 return; | 229 return; |
| 230 g_startup_complete_flag.Get().UnsafeResetForTesting(); | 230 g_startup_complete_flag.Get().UnsafeResetForTesting(); |
| 231 DCHECK(!IsBrowserStartupComplete()); | 231 DCHECK(!IsBrowserStartupComplete()); |
| 232 } | 232 } |
| OLD | NEW |