| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/page_cycler/page_cycler.h" | 5 #include "chrome/browser/page_cycler/page_cycler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
| 23 #include "content/public/common/url_constants.h" | 23 #include "content/public/common/url_constants.h" |
| 24 | 24 |
| 25 using content::NavigationController; | 25 using content::NavigationController; |
| 26 using content::OpenURLParams; | 26 using content::OpenURLParams; |
| 27 using content::Referrer; | 27 using content::Referrer; |
| 28 using content::WebContents; | 28 using content::WebContents; |
| 29 | 29 |
| 30 PageCycler::PageCycler(Browser* browser, | 30 PageCycler::PageCycler(Browser* browser, |
| 31 const FilePath& urls_file) | 31 const FilePath& urls_file) |
| 32 : content::WebContentsObserver(browser->GetSelectedWebContents()), | 32 : content::WebContentsObserver(browser->GetActiveWebContents()), |
| 33 browser_(browser), | 33 browser_(browser), |
| 34 urls_file_(urls_file), | 34 urls_file_(urls_file), |
| 35 url_index_(0), | 35 url_index_(0), |
| 36 total_iterations_(0), | 36 total_iterations_(0), |
| 37 current_iteration_(0), | 37 current_iteration_(0), |
| 38 aborted_(false) { | 38 aborted_(false) { |
| 39 BrowserList::AddObserver(this); | 39 BrowserList::AddObserver(this); |
| 40 AddRef(); // Balanced in Finish()/Abort() (only one should be called). | 40 AddRef(); // Balanced in Finish()/Abort() (only one should be called). |
| 41 } | 41 } |
| 42 | 42 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 } | 125 } |
| 126 | 126 |
| 127 void PageCycler::BeginCycle() { | 127 void PageCycler::BeginCycle() { |
| 128 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 128 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 129 | 129 |
| 130 CHECK(browser_); | 130 CHECK(browser_); |
| 131 // Upon launch, Chrome will automatically load the newtab page. This can | 131 // Upon launch, Chrome will automatically load the newtab page. This can |
| 132 // result in the browser being in a state of loading when PageCycler is ready | 132 // result in the browser being in a state of loading when PageCycler is ready |
| 133 // to start. Instead of interrupting the load, we wait for it to finish, and | 133 // to start. Instead of interrupting the load, we wait for it to finish, and |
| 134 // will call LoadNextURL() from DidFinishLoad() or DidFailProvisionalLoad(). | 134 // will call LoadNextURL() from DidFinishLoad() or DidFailProvisionalLoad(). |
| 135 if (browser_->GetSelectedWebContents()->IsLoading()) | 135 if (browser_->GetActiveWebContents()->IsLoading()) |
| 136 return; | 136 return; |
| 137 LoadNextURL(); | 137 LoadNextURL(); |
| 138 } | 138 } |
| 139 | 139 |
| 140 void PageCycler::LoadNextURL() { | 140 void PageCycler::LoadNextURL() { |
| 141 CHECK(browser_); | 141 CHECK(browser_); |
| 142 if (url_index_ >= urls_.size()) { | 142 if (url_index_ >= urls_.size()) { |
| 143 if (current_iteration_ < total_iterations_ - 1) { | 143 if (current_iteration_ < total_iterations_ - 1) { |
| 144 ++current_iteration_; | 144 ++current_iteration_; |
| 145 url_index_ = 0; | 145 url_index_ = 0; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 aborted_ = true; | 254 aborted_ = true; |
| 255 error_.append(ASCIIToUTF16( | 255 error_.append(ASCIIToUTF16( |
| 256 "Browser was closed before the run was completed.")); | 256 "Browser was closed before the run was completed.")); |
| 257 DLOG(WARNING) << | 257 DLOG(WARNING) << |
| 258 "Page Cycler: browser was closed before the run was completed."; | 258 "Page Cycler: browser was closed before the run was completed."; |
| 259 content::BrowserThread::PostBlockingPoolTask( | 259 content::BrowserThread::PostBlockingPoolTask( |
| 260 FROM_HERE, | 260 FROM_HERE, |
| 261 base::Bind(&PageCycler::PrepareResultsOnBackgroundThread, this)); | 261 base::Bind(&PageCycler::PrepareResultsOnBackgroundThread, this)); |
| 262 } | 262 } |
| 263 } | 263 } |
| OLD | NEW |