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

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

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

Powered by Google App Engine
This is Rietveld 408576698