OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/nacl/browser/nacl_browser.h" | 5 #include "components/nacl/browser/nacl_browser.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/files/file_proxy.h" | 9 #include "base/files/file_proxy.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 } else { | 265 } else { |
266 LOG(ERROR) << "Failed to open NaCl IRT file \"" | 266 LOG(ERROR) << "Failed to open NaCl IRT file \"" |
267 << irt_filepath_.LossyDisplayName() | 267 << irt_filepath_.LossyDisplayName() |
268 << "\": " << error_code; | 268 << "\": " << error_code; |
269 MarkAsFailed(); | 269 MarkAsFailed(); |
270 } | 270 } |
271 irt_state_ = NaClResourceReady; | 271 irt_state_ = NaClResourceReady; |
272 CheckWaiting(); | 272 CheckWaiting(); |
273 } | 273 } |
274 | 274 |
275 void NaClBrowser::SetProcessGdbDebugStubPort(int process_id, int port) { | 275 void NaClBrowser::FireGdbDebugStubPortOpened(int port) { |
276 gdb_debug_stub_port_map_[process_id] = port; | 276 content::BrowserThread::PostTask( |
277 if (port != kGdbDebugStubPortUnknown && | 277 content::BrowserThread::IO, |
278 !debug_stub_port_listener_.is_null()) { | 278 FROM_HERE, |
279 content::BrowserThread::PostTask( | 279 base::Bind(debug_stub_port_listener_, port)); |
280 content::BrowserThread::IO, | 280 } |
281 FROM_HERE, | 281 |
282 base::Bind(debug_stub_port_listener_, port)); | 282 bool NaClBrowser::HasGdbDebugStubPortListener() { |
283 } | 283 return !debug_stub_port_listener_.is_null(); |
284 } | 284 } |
285 | 285 |
286 void NaClBrowser::SetGdbDebugStubPortListener( | 286 void NaClBrowser::SetGdbDebugStubPortListener( |
287 base::Callback<void(int)> listener) { | 287 base::Callback<void(int)> listener) { |
288 debug_stub_port_listener_ = listener; | 288 debug_stub_port_listener_ = listener; |
289 } | 289 } |
290 | 290 |
291 void NaClBrowser::ClearGdbDebugStubPortListener() { | 291 void NaClBrowser::ClearGdbDebugStubPortListener() { |
292 debug_stub_port_listener_.Reset(); | 292 debug_stub_port_listener_.Reset(); |
293 } | 293 } |
294 | 294 |
295 int NaClBrowser::GetProcessGdbDebugStubPort(int process_id) { | |
296 GdbDebugStubPortMap::iterator i = gdb_debug_stub_port_map_.find(process_id); | |
297 if (i != gdb_debug_stub_port_map_.end()) { | |
298 return i->second; | |
299 } | |
300 return kGdbDebugStubPortUnused; | |
301 } | |
302 | |
303 void NaClBrowser::InitValidationCacheFilePath() { | 295 void NaClBrowser::InitValidationCacheFilePath() { |
304 // Determine where the validation cache resides in the file system. It | 296 // Determine where the validation cache resides in the file system. It |
305 // exists in Chrome's cache directory and is not tied to any specific | 297 // exists in Chrome's cache directory and is not tied to any specific |
306 // profile. | 298 // profile. |
307 // Start by finding the user data directory. | 299 // Start by finding the user data directory. |
308 base::FilePath user_data_dir; | 300 base::FilePath user_data_dir; |
309 if (!browser_delegate_->GetUserDirectory(&user_data_dir)) { | 301 if (!browser_delegate_->GetUserDirectory(&user_data_dir)) { |
310 RunWithoutValidationCache(); | 302 RunWithoutValidationCache(); |
311 return; | 303 return; |
312 } | 304 } |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 // The task is sequenced so that multiple writes happen in order. | 527 // The task is sequenced so that multiple writes happen in order. |
536 content::BrowserThread::PostBlockingPoolSequencedTask( | 528 content::BrowserThread::PostBlockingPoolSequencedTask( |
537 kValidationCacheSequenceName, | 529 kValidationCacheSequenceName, |
538 FROM_HERE, | 530 FROM_HERE, |
539 base::Bind(WriteCache, validation_cache_file_path_, | 531 base::Bind(WriteCache, validation_cache_file_path_, |
540 base::Owned(pickle))); | 532 base::Owned(pickle))); |
541 } | 533 } |
542 validation_cache_is_modified_ = false; | 534 validation_cache_is_modified_ = false; |
543 } | 535 } |
544 | 536 |
545 void NaClBrowser::OnProcessEnd(int process_id) { | |
546 gdb_debug_stub_port_map_.erase(process_id); | |
547 } | |
548 | |
549 void NaClBrowser::OnProcessCrashed() { | 537 void NaClBrowser::OnProcessCrashed() { |
550 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 538 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
551 if (crash_times_.size() == kMaxCrashesPerInterval) { | 539 if (crash_times_.size() == kMaxCrashesPerInterval) { |
552 crash_times_.pop_front(); | 540 crash_times_.pop_front(); |
553 } | 541 } |
554 base::Time time = base::Time::Now(); | 542 base::Time time = base::Time::Now(); |
555 crash_times_.push_back(time); | 543 crash_times_.push_back(time); |
556 } | 544 } |
557 | 545 |
558 bool NaClBrowser::IsThrottled() { | 546 bool NaClBrowser::IsThrottled() { |
559 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 547 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
560 if (crash_times_.size() != kMaxCrashesPerInterval) { | 548 if (crash_times_.size() != kMaxCrashesPerInterval) { |
561 return false; | 549 return false; |
562 } | 550 } |
563 base::TimeDelta delta = base::Time::Now() - crash_times_.front(); | 551 base::TimeDelta delta = base::Time::Now() - crash_times_.front(); |
564 return delta.InSeconds() <= kCrashesIntervalInSeconds; | 552 return delta.InSeconds() <= kCrashesIntervalInSeconds; |
565 } | 553 } |
566 | 554 |
567 } // namespace nacl | 555 } // namespace nacl |
OLD | NEW |