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/extensions/api/record/record_api.h" | 5 #include "chrome/browser/extensions/api/record/record_api.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 RunPageCyclerFunction::~RunPageCyclerFunction() {} | 46 RunPageCyclerFunction::~RunPageCyclerFunction() {} |
47 | 47 |
48 bool RunPageCyclerFunction::RunImpl() { | 48 bool RunPageCyclerFunction::RunImpl() { |
49 if (!ParseJSParameters()) | 49 if (!ParseJSParameters()) |
50 return false; | 50 return false; |
51 | 51 |
52 // If we've had any errors reportable to the JS caller so far (in | 52 // If we've had any errors reportable to the JS caller so far (in |
53 // parameter parsing) then return a list of such errors, else perform | 53 // parameter parsing) then return a list of such errors, else perform |
54 // RunTestBrowser on the BlockingPool. | 54 // RunTestBrowser on the BlockingPool. |
55 if (!errors_.empty()) { | 55 if (!errors_.empty()) { |
56 results_ = record::CaptureURLs::Results::Create(errors_); | 56 results_ = record::CaptureURLs::Results::Create(errors_, "FIX_ME"); |
57 SendResponse(true); | 57 SendResponse(true); |
58 } else { | 58 } else { |
59 content::BrowserThread::PostBlockingPoolTask(FROM_HERE, | 59 content::BrowserThread::PostBlockingPoolTask(FROM_HERE, |
60 base::Bind(&RunPageCyclerFunction::RunTestBrowser, this)); | 60 base::Bind(&RunPageCyclerFunction::RunTestBrowser, this)); |
61 process_strategy_->PumpBlockingPool(); // Test purposes only. | 61 process_strategy_->PumpBlockingPool(); // Test purposes only. |
62 } | 62 } |
63 | 63 |
64 return true; | 64 return true; |
65 } | 65 } |
66 | 66 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
160 CaptureURLsFunction::CaptureURLsFunction(ProcessStrategy* strategy) | 160 CaptureURLsFunction::CaptureURLsFunction(ProcessStrategy* strategy) |
161 : RunPageCyclerFunction(strategy) {} | 161 : RunPageCyclerFunction(strategy) {} |
162 | 162 |
163 // Fetch data for possible optional switch for an extension to load. | 163 // Fetch data for possible optional switch for an extension to load. |
164 bool CaptureURLsFunction::ParseJSParameters() { | 164 bool CaptureURLsFunction::ParseJSParameters() { |
165 scoped_ptr<record::CaptureURLs::Params> params( | 165 scoped_ptr<record::CaptureURLs::Params> params( |
166 record::CaptureURLs::Params::Create(*args_)); | 166 record::CaptureURLs::Params::Create(*args_)); |
167 EXTENSION_FUNCTION_VALIDATE(params.get()); | 167 EXTENSION_FUNCTION_VALIDATE(params.get()); |
168 | 168 |
169 url_contents_ = JoinString(params->urls, '\n'); | 169 url_contents_ = JoinString(params->urls, '\n'); |
170 user_data_dir_ = FilePath::FromUTF8Unsafe(params->cache_directory_path); | 170 // FIX: Can't just use captureName -- gotta stick it in a temp dir |
Jeffrey Yasskin
2012/08/09 19:27:04
I believe it's more common to use TODO(yourname) i
clintstaley
2012/08/10 00:33:13
Done.
| |
171 user_data_dir_ = FilePath::FromUTF8Unsafe(params->capture_name); | |
Jeffrey Yasskin
2012/08/09 19:27:04
What happens if the user's filesystem doesn't use
clintstaley
2012/08/10 00:33:13
Good point. I think we probably just need to be s
| |
171 | 172 |
172 return true; | 173 return true; |
173 } | 174 } |
174 | 175 |
175 // CaptureURLsFunction adds "record-mode" to sub-browser call, and returns | 176 // CaptureURLsFunction adds "record-mode" to sub-browser call, and returns |
176 // just the (possibly empty) error list. | 177 // just the (possibly empty) error list. |
177 void CaptureURLsFunction::AddSwitches(CommandLine* line) { | 178 void CaptureURLsFunction::AddSwitches(CommandLine* line) { |
178 if (!line->HasSwitch(switches::kRecordMode)) | 179 if (!line->HasSwitch(switches::kRecordMode)) |
179 line->AppendSwitch(switches::kRecordMode); | 180 line->AppendSwitch(switches::kRecordMode); |
180 } | 181 } |
181 | 182 |
182 void CaptureURLsFunction::Finish() { | 183 void CaptureURLsFunction::Finish() { |
183 results_ = record::CaptureURLs::Results::Create(errors_); | 184 results_ = record::CaptureURLs::Results::Create(errors_, |
185 user_data_dir_.AsUTF8Unsafe()); | |
184 SendResponse(true); | 186 SendResponse(true); |
185 } | 187 } |
186 | 188 |
187 | |
188 // ReplayURLsFunction ------------------------------------------------ | 189 // ReplayURLsFunction ------------------------------------------------ |
189 | 190 |
190 ReplayURLsFunction::ReplayURLsFunction() | 191 ReplayURLsFunction::ReplayURLsFunction() |
191 : RunPageCyclerFunction(new ProductionProcessStrategy()), | 192 : RunPageCyclerFunction(new ProductionProcessStrategy()), |
192 run_time_ms_(0) { | 193 run_time_ms_(0) { |
193 } | 194 } |
194 | 195 |
195 ReplayURLsFunction::ReplayURLsFunction(ProcessStrategy* strategy) | 196 ReplayURLsFunction::ReplayURLsFunction(ProcessStrategy* strategy) |
196 : RunPageCyclerFunction(strategy), run_time_ms_(0) { | 197 : RunPageCyclerFunction(strategy), run_time_ms_(0) { |
197 } | 198 } |
198 | 199 |
199 ReplayURLsFunction::~ReplayURLsFunction() {} | 200 ReplayURLsFunction::~ReplayURLsFunction() {} |
200 | 201 |
201 // Fetch data for possible optional switches for a repeat count and an | 202 // Fetch data for possible optional switches for a repeat count and an |
202 // extension to load. | 203 // extension to load. |
203 bool ReplayURLsFunction::ParseJSParameters() { | 204 bool ReplayURLsFunction::ParseJSParameters() { |
204 scoped_ptr<record::ReplayURLs::Params> params( | 205 scoped_ptr<record::ReplayURLs::Params> params( |
205 record::ReplayURLs::Params::Create(*args_)); | 206 record::ReplayURLs::Params::Create(*args_)); |
206 EXTENSION_FUNCTION_VALIDATE(params.get()); | 207 EXTENSION_FUNCTION_VALIDATE(params.get()); |
207 | 208 |
208 url_contents_ = JoinString(params->urls, '\n'); | 209 |
209 user_data_dir_ = FilePath::FromUTF8Unsafe(params->capture_directory_path); | 210 // FIX: Must build full temp dir from capture_name |
211 user_data_dir_ = FilePath::FromUTF8Unsafe(params->capture_name); | |
212 | |
213 // FIX: Get this from user data dir ultimately | |
214 url_contents_ = "http://www.google.com\nhttp://www.amazon.com\n"; | |
215 | |
210 repeat_count_ = params->repeat_count; | 216 repeat_count_ = params->repeat_count; |
211 | 217 |
212 if (params->details.get()) { | 218 if (params->details.get()) { |
213 if (params->details->extension_path.get()) | 219 if (params->details->extension_path.get()) |
214 extension_path_ = | 220 extension_path_ = |
215 FilePath::FromUTF8Unsafe(*params->details->extension_path); | 221 FilePath::FromUTF8Unsafe(*params->details->extension_path); |
216 } | 222 } |
217 | 223 |
218 return true; | 224 return true; |
219 } | 225 } |
(...skipping 14 matching lines...) Expand all Loading... | |
234 } | 240 } |
235 | 241 |
236 // Read stats file, and get run time. | 242 // Read stats file, and get run time. |
237 void ReplayURLsFunction::ReadReplyFiles() { | 243 void ReplayURLsFunction::ReadReplyFiles() { |
238 file_util::ReadFileToString(stats_file_path_, &stats_); | 244 file_util::ReadFileToString(stats_file_path_, &stats_); |
239 | 245 |
240 run_time_ms_ = (base::Time::NowFromSystemTime() - timer_).InMilliseconds(); | 246 run_time_ms_ = (base::Time::NowFromSystemTime() - timer_).InMilliseconds(); |
241 } | 247 } |
242 | 248 |
243 void ReplayURLsFunction::Finish() { | 249 void ReplayURLsFunction::Finish() { |
244 record::ReplayURLsResult result; | 250 results_ = record::ReplayURLs::Results::Create(run_time_ms_, stats_, errors_); |
245 | |
246 result.run_time = run_time_ms_; | |
247 result.stats = stats_; | |
248 result.errors = errors_; | |
249 | |
250 results_ = record::ReplayURLs::Results::Create(result); | |
251 SendResponse(true); | 251 SendResponse(true); |
252 } | 252 } |
253 | 253 |
254 } // namespace extensions | 254 } // namespace extensions |
OLD | NEW |