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

Side by Side Diff: chrome/browser/extensions/api/record/record_api.h

Issue 21854002: Remove experimental.record api completely (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 4 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_EXTENSIONS_API_RECORD_RECORD_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_RECORD_RECORD_API_H_
7
8 #include "base/command_line.h"
9 #include "base/files/file_path.h"
10 #include "base/time/time.h"
11 #include "chrome/browser/extensions/extension_function.h"
12
13 namespace {
14
15 const base::FilePath::CharType kURLErrorsSuffix[] =
16 FILE_PATH_LITERAL(".errors");
17 const char kErrorsKey[] = "errors";
18 const char kStatsKey[] = "stats";
19
20 };
21
22 namespace extensions {
23
24 // ProcessStrategy abstracts the API's starting and waiting on a test
25 // browser instance. This lets us browser-test the API without actually
26 // firing up a sub browser instance.
27 class ProcessStrategy {
28 public:
29 // Needed to void build warnings
30 virtual ~ProcessStrategy();
31
32 // Used only in test version to pump the blocking pool queue,
33 // which doesn't otherwise happen during test.
34 virtual void PumpBlockingPool() {}
35
36 // Start up process with given commandline. Real version does just
37 // that; test version mocks it up, generating errors or good results,
38 // as configured. If there are any problems running the process itself,
39 // as opposed to errors in the cycler URL list, etc, report these via
40 // |errors|
41 virtual void RunProcess(const CommandLine& line,
42 std::vector<std::string> *errors) = 0;
43 };
44
45 // Production (default) version of ProcessStrategy. See ProcessStrategy
46 // comments for more info. This subclass actually starts a sub browser
47 // instance.
48 class ProductionProcessStrategy : public ProcessStrategy {
49 public:
50 virtual void RunProcess(const CommandLine& line,
51 std::vector<std::string> *errors) OVERRIDE;
52 };
53
54 // Both page cycler calls (capture and replay) have a great deal in common,
55 // including the need to build and write a url list file, set the user
56 // data dir, start a sub-instance of Chrome, and parse a resultant error
57 // file. This base class encapslates those common elements.
58 class RunPageCyclerFunction : public AsyncExtensionFunction {
59 public:
60 explicit RunPageCyclerFunction(ProcessStrategy* strategy);
61
62 // Make a CommandLine copy of |original|, removing all switches in
63 // |to_remove|.
64 static CommandLine RemoveSwitches(const CommandLine& original,
65 const std::vector<std::string>& to_remove);
66
67 // Return ProcessStrategy, to allow for test versions.
68 virtual const ProcessStrategy &GetProcessStrategy();
69
70 protected:
71 virtual ~RunPageCyclerFunction();
72
73 // Gather common page cycler parameters and store them, then do blocking
74 // thread invocation of RunTestBrowser.
75 virtual bool RunImpl() OVERRIDE;
76
77 // Parse the JS parameters, and store them as member data.
78 virtual bool ParseJSParameters() = 0;
79
80 // Do a vanilla test browser run, bracketing it immediately before and
81 // after with a call of AddSwitches to add special commandline options
82 // for Capture or Replay, and ReadReplyFiles to do any special post-run
83 // data collection. Gather any error results into |errors_| and then do a
84 // BrowserThread call of Finish to return JS values.
85 virtual void RunTestBrowser();
86 virtual void AddSwitches(CommandLine* command_line) {}
87
88 // The test browser communicates URL errors, performance statistics, and
89 // possibly other data by posting them to text files. ReadReplyFiles
90 // collects these data for return to the JS side caller.
91 virtual void ReadReplyFiles() {}
92
93 // Return the values gathered in RunTestBrowser. No common code here; all
94 // logic is in subclasses.
95 virtual void Finish() {}
96
97 base::FilePath user_data_dir_;
98 std::string url_contents_;
99 int repeat_count_;
100 std::vector<std::string> errors_;
101
102 // Base CommandLine on which to build the test browser CommandLine
103 CommandLine base_command_line_;
104
105 // ProcessStrategy to use for this run.
106 scoped_ptr<ProcessStrategy> process_strategy_;
107 };
108
109 class RecordCaptureURLsFunction : public RunPageCyclerFunction {
110 public:
111 DECLARE_EXTENSION_FUNCTION("experimental.record.captureURLs",
112 EXPERIMENTAL_RECORD_CAPTUREURLS)
113
114 RecordCaptureURLsFunction();
115 explicit RecordCaptureURLsFunction(ProcessStrategy* strategy);
116
117 private:
118 virtual ~RecordCaptureURLsFunction() {}
119
120 // Read the ReplayDetails parameter if it exists.
121 virtual bool ParseJSParameters() OVERRIDE;
122
123 // Add record-mode.
124 virtual void AddSwitches(CommandLine* command_line) OVERRIDE;
125
126 // Return error list.
127 virtual void Finish() OVERRIDE;
128 };
129
130 class RecordReplayURLsFunction : public RunPageCyclerFunction {
131 public:
132 DECLARE_EXTENSION_FUNCTION("experimental.record.replayURLs",
133 EXPERIMENTAL_RECORD_REPLAYURLS)
134
135 RecordReplayURLsFunction();
136 explicit RecordReplayURLsFunction(ProcessStrategy* strategy);
137
138 private:
139 virtual ~RecordReplayURLsFunction();
140
141 // Read the ReplayDetails parameter if it exists.
142 virtual bool ParseJSParameters() OVERRIDE;
143
144 // Add visit-urls-count and load-extension.
145 virtual void AddSwitches(CommandLine* command_line) OVERRIDE;
146
147 // Read stats file.
148 virtual void ReadReplyFiles() OVERRIDE;
149
150 // Return error list, statistical results, and runtime.
151 virtual void Finish() OVERRIDE;
152
153 // These data are additional information added to the sub-browser
154 // commandline or used to repeatedly run the sub-browser.
155 base::FilePath extension_path_;
156 base::FilePath stats_file_path_;
157
158 // This time datum marks the start and end of the sub-browser run.
159 base::Time timer_;
160
161 // These two data are additional information returned to caller.
162 double run_time_ms_;
163 std::string stats_;
164 };
165
166 } // namespace extensions
167
168 #endif // CHROME_BROWSER_EXTENSIONS_API_RECORD_RECORD_API_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698