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

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

Issue 10491010: Reland r140188: CommandLine Page Cycler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/page_cycler/page_cycler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_|; virtual since tests may
97 // need to override this function.
98 virtual void Finish();
99
100 // Called when the Browser to which |browser_| points is closed; exits
101 // PageCycler.
102 void Abort();
103
104 // BrowserList::Observer
105 virtual void OnBrowserAdded(Browser* browser) OVERRIDE;
106 virtual void OnBrowserRemoved(Browser* browser) OVERRIDE;
107
108 // The Browser context in which the page cycler is running.
109 Browser* browser_;
110
111 // The path to the file containing the list of urls to visit.
112 FilePath urls_file_;
113
114 // The path to the file to which we write any errors encountered.
115 FilePath errors_file_;
116
117 // The path to the file to which we write the statistics (optional, may be
118 // an empty path).
119 FilePath stats_file_;
120
121 // The list of urls to visit.
122 std::vector<GURL> urls_;
123
124 // The current index into the |urls_| vector.
125 size_t url_index_;
126
127 // The number of total iterations to be run.
128 int total_iterations_;
129
130 // The number of the current iteration.
131 int current_iteration_;
132
133 // The generated string of urls which we have visited; this is built one url
134 // at a time as we iterate through the |urls_| vector. This is primarily
135 // included for interfacing with the previous page_cycler's output style.
136 std::string urls_string_;
137
138 // The generated string of the times taken to visit each url. As with
139 // |urls_string_|, this is built as we visit each url, and is primarily to
140 // produce output similar to the previous page_cycler's.
141 std::string timings_string_;
142
143 // The time at which we begin the process of loading the next url; this is
144 // used to calculate the time taken for each url load.
145 base::TimeTicks initial_time_;
146
147 // Indicates the abort status of the page cycler; true means aborted.
148 bool aborted_;
149
150 string16 error_;
151
152 DISALLOW_COPY_AND_ASSIGN(PageCycler);
153 };
154
155 #endif // CHROME_BROWSER_PAGE_CYCLER_PAGE_CYCLER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/page_cycler/page_cycler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698