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" |
11 #include "base/process_util.h" | 11 #include "base/process_util.h" |
12 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
13 #include "base/string_split.h" | 13 #include "base/string_split.h" |
14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
15 #include "chrome/app/chrome_command_ids.h" | 15 #include "chrome/app/chrome_command_ids.h" |
16 #include "chrome/browser/ui/browser_commands.h" | 16 #include "chrome/browser/ui/browser_commands.h" |
| 17 #include "chrome/browser/ui/browser_tabstrip.h" |
17 #include "chrome/common/chrome_notification_types.h" | 18 #include "chrome/common/chrome_notification_types.h" |
18 #include "chrome/test/base/chrome_process_util.h" | 19 #include "chrome/test/base/chrome_process_util.h" |
19 #include "chrome/test/perf/perf_test.h" | 20 #include "chrome/test/perf/perf_test.h" |
20 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
21 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
22 #include "content/public/browser/render_view_host.h" | 23 #include "content/public/browser/render_view_host.h" |
23 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
24 #include "content/public/common/url_constants.h" | 25 #include "content/public/common/url_constants.h" |
25 | 26 |
26 using content::NavigationController; | 27 using content::NavigationController; |
27 using content::OpenURLParams; | 28 using content::OpenURLParams; |
28 using content::Referrer; | 29 using content::Referrer; |
29 using content::WebContents; | 30 using content::WebContents; |
30 | 31 |
31 PageCycler::PageCycler(Browser* browser, | 32 PageCycler::PageCycler(Browser* browser, |
32 const FilePath& urls_file) | 33 const FilePath& urls_file) |
33 : content::WebContentsObserver(browser->GetActiveWebContents()), | 34 : content::WebContentsObserver(chrome::GetActiveWebContents(browser)), |
34 browser_(browser), | 35 browser_(browser), |
35 urls_file_(urls_file), | 36 urls_file_(urls_file), |
36 url_index_(0), | 37 url_index_(0), |
37 aborted_(false) { | 38 aborted_(false) { |
38 BrowserList::AddObserver(this); | 39 BrowserList::AddObserver(this); |
39 AddRef(); // Balanced in Finish()/Abort() (only one should be called). | 40 AddRef(); // Balanced in Finish()/Abort() (only one should be called). |
40 } | 41 } |
41 | 42 |
42 PageCycler::~PageCycler() { | 43 PageCycler::~PageCycler() { |
43 } | 44 } |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 } | 124 } |
124 | 125 |
125 void PageCycler::BeginCycle() { | 126 void PageCycler::BeginCycle() { |
126 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 127 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
127 | 128 |
128 CHECK(browser_); | 129 CHECK(browser_); |
129 // Upon launch, Chrome will automatically load the newtab page. This can | 130 // Upon launch, Chrome will automatically load the newtab page. This can |
130 // result in the browser being in a state of loading when PageCycler is ready | 131 // result in the browser being in a state of loading when PageCycler is ready |
131 // to start. Instead of interrupting the load, we wait for it to finish, and | 132 // to start. Instead of interrupting the load, we wait for it to finish, and |
132 // will call LoadNextURL() from DidFinishLoad() or DidFailProvisionalLoad(). | 133 // will call LoadNextURL() from DidFinishLoad() or DidFailProvisionalLoad(). |
133 if (browser_->GetActiveWebContents()->IsLoading()) | 134 if (chrome::GetActiveWebContents(browser_)->IsLoading()) |
134 return; | 135 return; |
135 LoadNextURL(); | 136 LoadNextURL(); |
136 } | 137 } |
137 | 138 |
138 void PageCycler::LoadNextURL() { | 139 void PageCycler::LoadNextURL() { |
139 CHECK(browser_); | 140 CHECK(browser_); |
140 if (url_index_ >= urls_.size()) { | 141 if (url_index_ >= urls_.size()) { |
141 content::BrowserThread::PostBlockingPoolTask( | 142 content::BrowserThread::PostBlockingPoolTask( |
142 FROM_HERE, | 143 FROM_HERE, |
143 base::Bind(&PageCycler::PrepareResultsOnBackgroundThread, this)); | 144 base::Bind(&PageCycler::PrepareResultsOnBackgroundThread, this)); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 aborted_ = true; | 253 aborted_ = true; |
253 error_.append(ASCIIToUTF16( | 254 error_.append(ASCIIToUTF16( |
254 "Browser was closed before the run was completed.")); | 255 "Browser was closed before the run was completed.")); |
255 DLOG(WARNING) << | 256 DLOG(WARNING) << |
256 "Page Cycler: browser was closed before the run was completed."; | 257 "Page Cycler: browser was closed before the run was completed."; |
257 content::BrowserThread::PostBlockingPoolTask( | 258 content::BrowserThread::PostBlockingPoolTask( |
258 FROM_HERE, | 259 FROM_HERE, |
259 base::Bind(&PageCycler::PrepareResultsOnBackgroundThread, this)); | 260 base::Bind(&PageCycler::PrepareResultsOnBackgroundThread, this)); |
260 } | 261 } |
261 } | 262 } |
OLD | NEW |