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/browser_process_impl.h" | 5 #include "chrome/browser/browser_process_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
michaeln
2015/05/15 03:14:33
I don't buy that almost all areas have uncommitted
| |
8 #include <map> | 8 #include <map> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/atomic_ref_count.h" | 11 #include "base/atomic_ref_count.h" |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/debug/alias.h" | 15 #include "base/debug/alias.h" |
16 #include "base/debug/leak_annotations.h" | 16 #include "base/debug/leak_annotations.h" |
17 #include "base/files/file_path.h" | 17 #include "base/files/file_path.h" |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
405 // This is done to ensure that the data has been persisted to disk before | 405 // This is done to ensure that the data has been persisted to disk before |
406 // continuing. | 406 // continuing. |
407 class RundownTaskCounter : | 407 class RundownTaskCounter : |
408 public base::RefCountedThreadSafe<RundownTaskCounter> { | 408 public base::RefCountedThreadSafe<RundownTaskCounter> { |
409 public: | 409 public: |
410 RundownTaskCounter(); | 410 RundownTaskCounter(); |
411 | 411 |
412 // Posts a rundown task to |task_runner|, can be invoked an arbitrary number | 412 // Posts a rundown task to |task_runner|, can be invoked an arbitrary number |
413 // of times before calling TimedWait. | 413 // of times before calling TimedWait. |
414 void Post(base::SequencedTaskRunner* task_runner); | 414 void Post(base::SequencedTaskRunner* task_runner); |
415 void PostMany( | |
416 const std::vector<scoped_refptr<base::SequencedTaskRunner>> &runners); | |
415 | 417 |
416 // Waits until the count is zero or |max_time| has passed. | 418 // Waits until the count is zero or |max_time| has passed. |
417 // This can only be called once per instance. | 419 // This can only be called once per instance. |
418 bool TimedWait(const base::TimeDelta& max_time); | 420 bool TimedWait(const base::TimeDelta& max_time); |
419 | 421 |
420 private: | 422 private: |
421 friend class base::RefCountedThreadSafe<RundownTaskCounter>; | 423 friend class base::RefCountedThreadSafe<RundownTaskCounter>; |
422 ~RundownTaskCounter() {} | 424 ~RundownTaskCounter() {} |
423 | 425 |
424 // Decrements the counter and releases the waitable event on transition to | 426 // Decrements the counter and releases the waitable event on transition to |
425 // zero. | 427 // zero. |
426 void Decrement(); | 428 void Decrement(); |
427 | 429 |
428 // The count starts at one to defer the possibility of one->zero transitions | 430 // The count starts at one to defer the possibility of one->zero transitions |
429 // until TimedWait is called. | 431 // until TimedWait is called. |
430 base::AtomicRefCount count_; | 432 base::AtomicRefCount count_; |
431 base::WaitableEvent waitable_event_; | 433 base::WaitableEvent waitable_event_; |
432 | 434 |
433 DISALLOW_COPY_AND_ASSIGN(RundownTaskCounter); | 435 DISALLOW_COPY_AND_ASSIGN(RundownTaskCounter); |
434 }; | 436 }; |
435 | 437 |
436 RundownTaskCounter::RundownTaskCounter() | 438 RundownTaskCounter::RundownTaskCounter() |
437 : count_(1), waitable_event_(true, false) { | 439 : count_(1), waitable_event_(true, false) { |
438 } | 440 } |
439 | 441 |
442 void RundownTaskCounter::PostMany( | |
443 const std::vector<scoped_refptr<base::SequencedTaskRunner>> &runners) { | |
444 for (const auto& runner : runners) | |
445 Post(runner.get()); | |
446 } | |
447 | |
440 void RundownTaskCounter::Post(base::SequencedTaskRunner* task_runner) { | 448 void RundownTaskCounter::Post(base::SequencedTaskRunner* task_runner) { |
441 // As the count starts off at one, it should never get to zero unless | 449 // As the count starts off at one, it should never get to zero unless |
442 // TimedWait has been called. | 450 // TimedWait has been called. |
443 DCHECK(!base::AtomicRefCountIsZero(&count_)); | 451 DCHECK(!base::AtomicRefCountIsZero(&count_)); |
444 | 452 |
445 base::AtomicRefCountInc(&count_); | 453 base::AtomicRefCountInc(&count_); |
446 | 454 |
447 // The task must be non-nestable to guarantee that it runs after all tasks | 455 // The task must be non-nestable to guarantee that it runs after all tasks |
448 // currently scheduled on |task_runner| have completed. | 456 // currently scheduled on |task_runner| have completed. |
449 task_runner->PostNonNestableTask(FROM_HERE, | 457 task_runner->PostNonNestableTask(FROM_HERE, |
450 base::Bind(&RundownTaskCounter::Decrement, this)); | 458 base::Bind(&RundownTaskCounter::Decrement, this)); |
451 } | 459 } |
452 | 460 |
453 void RundownTaskCounter::Decrement() { | 461 void RundownTaskCounter::Decrement() { |
454 if (!base::AtomicRefCountDec(&count_)) | 462 if (!base::AtomicRefCountDec(&count_)) |
455 waitable_event_.Signal(); | 463 waitable_event_.Signal(); |
456 } | 464 } |
457 | 465 |
458 bool RundownTaskCounter::TimedWait(const base::TimeDelta& max_time) { | 466 bool RundownTaskCounter::TimedWait(const base::TimeDelta& max_time) { |
459 // Decrement the excess count from the constructor. | 467 // Decrement the excess count from the constructor. |
460 Decrement(); | 468 Decrement(); |
461 | 469 |
462 return waitable_event_.TimedWait(max_time); | 470 return waitable_event_.TimedWait(max_time); |
463 } | 471 } |
464 | 472 |
473 void FlushStoragePartition( | |
474 RundownTaskCounter* rundown_counter, | |
475 content::StoragePartition* partition) { | |
476 partition->Flush(); | |
477 //rundown_counter->PostMany(partition->GetFlushTaskRunners()); | |
478 } | |
479 | |
465 } // namespace | 480 } // namespace |
466 | 481 |
467 void BrowserProcessImpl::EndSession() { | 482 void BrowserProcessImpl::EndSession() { |
468 // Mark all the profiles as clean. | 483 // Mark all the profiles as clean. |
469 ProfileManager* pm = profile_manager(); | 484 ProfileManager* pm = profile_manager(); |
470 std::vector<Profile*> profiles(pm->GetLoadedProfiles()); | 485 std::vector<Profile*> profiles(pm->GetLoadedProfiles()); |
471 scoped_refptr<RundownTaskCounter> rundown_counter(new RundownTaskCounter()); | 486 scoped_refptr<RundownTaskCounter> rundown_counter(new RundownTaskCounter()); |
472 for (size_t i = 0; i < profiles.size(); ++i) { | 487 for (size_t i = 0; i < profiles.size(); ++i) { |
473 Profile* profile = profiles[i]; | 488 Profile* profile = profiles[i]; |
474 profile->SetExitType(Profile::EXIT_SESSION_ENDED); | 489 profile->SetExitType(Profile::EXIT_SESSION_ENDED); |
475 if (profile->GetPrefs()) { | 490 if (profile->GetPrefs()) { |
476 profile->GetPrefs()->CommitPendingWrite(); | 491 profile->GetPrefs()->CommitPendingWrite(); |
477 rundown_counter->Post(profile->GetIOTaskRunner().get()); | 492 rundown_counter->Post(profile->GetIOTaskRunner().get()); |
478 } | 493 } |
494 content::BrowserContext::ForEachStoragePartition( | |
495 profile, base::Bind(FlushStoragePartition, rundown_counter)); | |
hashimoto
2015/05/14 04:46:09
I'm not sure if this will work as expected.
Curren
| |
479 } | 496 } |
480 | 497 |
481 // Tell the metrics service it was cleanly shutdown. | 498 // Tell the metrics service it was cleanly shutdown. |
482 metrics::MetricsService* metrics = g_browser_process->metrics_service(); | 499 metrics::MetricsService* metrics = g_browser_process->metrics_service(); |
483 if (metrics && local_state()) { | 500 if (metrics && local_state()) { |
484 metrics->RecordStartOfSessionEnd(); | 501 metrics->RecordStartOfSessionEnd(); |
485 #if !defined(OS_CHROMEOS) | 502 #if !defined(OS_CHROMEOS) |
486 // MetricsService lazily writes to prefs, force it to write now. | 503 // MetricsService lazily writes to prefs, force it to write now. |
487 // On ChromeOS, chrome gets killed when hangs, so no need to | 504 // On ChromeOS, chrome gets killed when hangs, so no need to |
488 // commit metrics::prefs::kStabilitySessionEndCompleted change immediately. | 505 // commit metrics::prefs::kStabilitySessionEndCompleted change immediately. |
(...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1229 } | 1246 } |
1230 | 1247 |
1231 void BrowserProcessImpl::OnAutoupdateTimer() { | 1248 void BrowserProcessImpl::OnAutoupdateTimer() { |
1232 if (CanAutorestartForUpdate()) { | 1249 if (CanAutorestartForUpdate()) { |
1233 DLOG(WARNING) << "Detected update. Restarting browser."; | 1250 DLOG(WARNING) << "Detected update. Restarting browser."; |
1234 RestartBackgroundInstance(); | 1251 RestartBackgroundInstance(); |
1235 } | 1252 } |
1236 } | 1253 } |
1237 | 1254 |
1238 #endif // (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) | 1255 #endif // (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) |
OLD | NEW |