Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: chrome/browser/page_cycler/page_cycler.h

Issue 9667009: CommandLine Page Cycler (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Replaced now-private BrowserList::GetLastActive() Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_PAGE_CYCLER_PAGE_CYCLER_H_
6 #define CHROME_BROWSER_PAGE_CYCLER_PAGE_CYCLER_H_
7 #pragma once
8
9 #include "base/file_path.h"
10 #include "base/memory/ref_counted.h"
11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_list.h"
13 #include "content/public/browser/navigation_controller.h"
14 #include "content/public/browser/web_contents_observer.h"
15
16 namespace content {
17 class RenderViewHost;
18 } // namespace content
19
20 namespace base {
21 class TimeTicks;
22 } // namespace base
23
24 // Performance test to track the resources used and speed with which chromium
25 // fully loads a given set of URLs. This class is created on the UI thread and
26 // does most of its work there. However, some work happens on background threads
27 // too; those are named with 'OnBackgroundThread'.
28 class PageCycler : public base::RefCountedThreadSafe<PageCycler>,
29 public BrowserList::Observer,
30 public content::WebContentsObserver {
31 public:
32 PageCycler(Browser* browser, FilePath urls_file);
33
34 // Begin running the page cycler.
35 void Run(const int& total_iterations);
36
37 // content::WebContentsObserver
38 virtual void DidFinishLoad(int64 frame_id,
39 const GURL& validated_url,
40 bool is_main_frame) OVERRIDE;
41 virtual void DidFailProvisionalLoad(
42 int64 frame_id,
43 bool is_main_frame,
44 const GURL& validated_url,
45 int error_code,
46 const string16& error_description,
47 content::RenderViewHost* render_view_host) OVERRIDE;
48
49 // This method should never be necessary while running PageCycler; this is
50 // for testing purposes only.
51 const std::vector<GURL>* urls_for_test() { return &urls_; }
52
53 void set_stats_file(const FilePath& stats_file) { stats_file_ = stats_file; }
54 void set_errors_file(const FilePath& errors_file) {
55 errors_file_ = errors_file;
56 }
57
58
59 protected:
60 virtual ~PageCycler();
61
62 private:
63 friend class base::RefCountedThreadSafe<PageCycler>;
64 friend class MockPageCycler;
65
66 // Check to see if a load callback is valid; i.e. the load should be from the
67 // main frame, the url should not be a chrome error url, and |url_index|
68 // should not be 0.
69 bool IsLoadCallbackValid(const GURL& validated_url,
70 bool is_main_frame);
71
72 // Read in the urls from |urls_file_| and store them in |urls_|.
73 void ReadURLsOnBackgroundThread();
74
75 // Perform any initial setup neccessary, and begin visiting the pages.
76 void BeginCycle();
77
78 // If |url_index_| points to a valid position in |urls_|, load the url,
79 // capturing any statistics information. Otherwise, call WriteResults.
80 void LoadNextURL();
81
82 // Complete statistics gathering for the finished visit, and try to load the
83 // next url.
84 void LoadSucceeded();
85
86 // Inidicate that the load failed with an error; try to load the next url.
87 void LoadFailed(const GURL& url, const string16& error_description);
88
89 // Finalize the output strings.
90 void PrepareResultsOnBackgroundThread();
91
92 // Write the data stored within output to the file indicated by |stats_file_|,
93 // if |stats_file_| is not empty. Write any errors to |errors_file_|.
94 void WriteResultsOnBackgroundThread(std::string output);
95
96 // Perform any necessary cleanup and exit |browser_|.
97 void Finish();
98
99 // Called when the Browser to which |browser_| points is closed; exits
100 // PageCycler.
101 void Abort();
102
103 // BrowserList::Observer
104 virtual void OnBrowserAdded(Browser* browser) OVERRIDE;
105 virtual void OnBrowserRemoved(Browser* browser) OVERRIDE;
106
107 // The Browser context in which the page cycler is running.
108 Browser* browser_;
109
110 // The path to the file containing the list of urls to visit.
111 FilePath urls_file_;
112
113 // The path to the file to which we write any errors encountered.
114 FilePath errors_file_;
115
116 // The path to the file to which we write the statistics (optional, may be
117 // an empty path).
118 FilePath stats_file_;
119
120 // The list of urls to visit.
121 std::vector<GURL> urls_;
122
123 // The current index into the |urls_| vector.
124 size_t url_index_;
125
126 // The number of total iterations to be run.
127 int total_iterations_;
128
129 // The number of the current iteration.
130 int current_iteration_;
131
132 // The generated string of urls which we have visited; this is built one url
133 // at a time as we iterate through the |urls_| vector. This is primarily
134 // included for interfacing with the previous page_cycler's output style.
135 std::string urls_string_;
136
137 // The generated string of the times taken to visit each url. As with
138 // |urls_string_|, this is built as we visit each url, and is primarily to
139 // produce output similar to the previous page_cycler's.
140 std::string timings_string_;
141
142 // The time at which we begin the process of loading the next url; this is
143 // used to calculate the time taken for each url load.
144 base::TimeTicks initial_time_;
145
146 // Indicates the abort status of the page cycler; true means aborted.
147 bool aborted_;
148
149 string16 error_;
150
151 DISALLOW_COPY_AND_ASSIGN(PageCycler);
152 };
153
154 #endif // CHROME_BROWSER_PAGE_CYCLER_PAGE_CYCLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698