OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "net/disk_cache/simple/simple_index.h" | 5 #include "net/disk_cache/simple/simple_index.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
180 base::StringToInt(tokens.token(), &foreground_delay) && | 180 base::StringToInt(tokens.token(), &foreground_delay) && |
181 tokens.GetNext() && | 181 tokens.GetNext() && |
182 base::StringToInt(tokens.token(), &background_delay)) { | 182 base::StringToInt(tokens.token(), &background_delay)) { |
183 foreground_flush_delay_ = foreground_delay; | 183 foreground_flush_delay_ = foreground_delay; |
184 background_flush_delay_ = background_delay; | 184 background_flush_delay_ = background_delay; |
185 } | 185 } |
186 } | 186 } |
187 | 187 |
188 #if defined(OS_ANDROID) | 188 #if defined(OS_ANDROID) |
189 if (base::android::IsVMInitialized()) { | 189 if (base::android::IsVMInitialized()) { |
190 activity_status_listener_.reset(new base::android::ActivityStatus::Listener( | 190 app_status_listener_.reset(new base::android::ApplicationStatusListener( |
191 base::Bind(&SimpleIndex::OnActivityStateChange, AsWeakPtr()))); | 191 base::Bind(&SimpleIndex::OnApplicationStateChange, AsWeakPtr()))); |
192 } | 192 } |
193 #endif | 193 #endif |
194 | 194 |
195 SimpleIndexLoadResult* load_result = new SimpleIndexLoadResult(); | 195 SimpleIndexLoadResult* load_result = new SimpleIndexLoadResult(); |
196 scoped_ptr<SimpleIndexLoadResult> load_result_scoped(load_result); | 196 scoped_ptr<SimpleIndexLoadResult> load_result_scoped(load_result); |
197 base::Closure reply = base::Bind( | 197 base::Closure reply = base::Bind( |
198 &SimpleIndex::MergeInitializingSet, | 198 &SimpleIndex::MergeInitializingSet, |
199 AsWeakPtr(), | 199 AsWeakPtr(), |
200 base::Passed(&load_result_scoped)); | 200 base::Passed(&load_result_scoped)); |
201 index_file_->LoadIndexEntries(cache_mtime, reply, load_result); | 201 index_file_->LoadIndexEntries(cache_mtime, reply, load_result); |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
448 to_run_when_initialized_.size(), 0, 100, 20); | 448 to_run_when_initialized_.size(), 0, 100, 20); |
449 // Run all callbacks waiting for the index to come up. | 449 // Run all callbacks waiting for the index to come up. |
450 for (CallbackList::iterator it = to_run_when_initialized_.begin(), | 450 for (CallbackList::iterator it = to_run_when_initialized_.begin(), |
451 end = to_run_when_initialized_.end(); it != end; ++it) { | 451 end = to_run_when_initialized_.end(); it != end; ++it) { |
452 io_thread_->PostTask(FROM_HERE, base::Bind((*it), net::OK)); | 452 io_thread_->PostTask(FROM_HERE, base::Bind((*it), net::OK)); |
453 } | 453 } |
454 to_run_when_initialized_.clear(); | 454 to_run_when_initialized_.clear(); |
455 } | 455 } |
456 | 456 |
457 #if defined(OS_ANDROID) | 457 #if defined(OS_ANDROID) |
458 void SimpleIndex::OnActivityStateChange( | 458 void SimpleIndex::OnApplicationStateChange( |
459 base::android::ActivityState state) { | 459 base::android::ApplicationState state) { |
460 DCHECK(io_thread_checker_.CalledOnValidThread()); | 460 DCHECK(io_thread_checker_.CalledOnValidThread()); |
461 // For more info about android activities, see: | 461 // For more info about android activities, see: |
462 // developer.android.com/training/basics/activity-lifecycle/pausing.html | 462 // developer.android.com/training/basics/activity-lifecycle/pausing.html |
463 // These values are defined in the file ActivityStatus.java | 463 if (state == base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES) { |
pasko
2014/02/24 14:43:31
app_on_background_ should be set to false when HAS
| |
464 if (state == base::android::ACTIVITY_STATE_RESUMED) { | |
465 app_on_background_ = false; | 464 app_on_background_ = false; |
466 } else if (state == base::android::ACTIVITY_STATE_STOPPED) { | 465 } else if (state == |
466 base::android::APPLICATION_STATE_HAS_STOPPED_ACTIVITIES) { | |
467 app_on_background_ = true; | 467 app_on_background_ = true; |
468 WriteToDisk(); | 468 WriteToDisk(); |
469 } | 469 } |
470 } | 470 } |
471 #endif | 471 #endif |
472 | 472 |
473 void SimpleIndex::WriteToDisk() { | 473 void SimpleIndex::WriteToDisk() { |
474 DCHECK(io_thread_checker_.CalledOnValidThread()); | 474 DCHECK(io_thread_checker_.CalledOnValidThread()); |
475 if (!initialized_) | 475 if (!initialized_) |
476 return; | 476 return; |
(...skipping 12 matching lines...) Expand all Loading... | |
489 start - last_write_to_disk_); | 489 start - last_write_to_disk_); |
490 } | 490 } |
491 } | 491 } |
492 last_write_to_disk_ = start; | 492 last_write_to_disk_ = start; |
493 | 493 |
494 index_file_->WriteToDisk(entries_set_, cache_size_, | 494 index_file_->WriteToDisk(entries_set_, cache_size_, |
495 start, app_on_background_); | 495 start, app_on_background_); |
496 } | 496 } |
497 | 497 |
498 } // namespace disk_cache | 498 } // namespace disk_cache |
OLD | NEW |