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

Side by Side Diff: net/disk_cache/simple/simple_index.cc

Issue 159173002: Refactor ActivityStatus to not store current activity (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed Comments Created 6 years, 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
bulach 2014/02/13 11:17:48 trigger happy! :)
David Trainor- moved to gerrit 2014/02/14 19:13:36 DELETE DELETE DELETE OMNOMNOM
2 // Use of this source code is governed by a BSD-style license that can be 1 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 2 // found in the LICENSE file.
4 3
5 #include "net/disk_cache/simple/simple_index.h" 4 #include "net/disk_cache/simple/simple_index.h"
6 5
7 #include <algorithm> 6 #include <algorithm>
8 #include <limits> 7 #include <limits>
9 #include <string> 8 #include <string>
10 #include <utility> 9 #include <utility>
11 10
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 tokens.GetNext() && 180 tokens.GetNext() &&
182 base::StringToInt(tokens.token(), &background_delay)) { 181 base::StringToInt(tokens.token(), &background_delay)) {
183 foreground_flush_delay_ = foreground_delay; 182 foreground_flush_delay_ = foreground_delay;
184 background_flush_delay_ = background_delay; 183 background_flush_delay_ = background_delay;
185 } 184 }
186 } 185 }
187 186
188 #if defined(OS_ANDROID) 187 #if defined(OS_ANDROID)
189 if (base::android::IsVMInitialized()) { 188 if (base::android::IsVMInitialized()) {
190 activity_status_listener_.reset(new base::android::ActivityStatus::Listener( 189 activity_status_listener_.reset(new base::android::ActivityStatus::Listener(
191 base::Bind(&SimpleIndex::OnActivityStateChange, AsWeakPtr()))); 190 base::Bind(&SimpleIndex::OnApplicationStateChange, AsWeakPtr())));
192 } 191 }
193 #endif 192 #endif
194 193
195 SimpleIndexLoadResult* load_result = new SimpleIndexLoadResult(); 194 SimpleIndexLoadResult* load_result = new SimpleIndexLoadResult();
196 scoped_ptr<SimpleIndexLoadResult> load_result_scoped(load_result); 195 scoped_ptr<SimpleIndexLoadResult> load_result_scoped(load_result);
197 base::Closure reply = base::Bind( 196 base::Closure reply = base::Bind(
198 &SimpleIndex::MergeInitializingSet, 197 &SimpleIndex::MergeInitializingSet,
199 AsWeakPtr(), 198 AsWeakPtr(),
200 base::Passed(&load_result_scoped)); 199 base::Passed(&load_result_scoped));
201 index_file_->LoadIndexEntries(cache_mtime, reply, load_result); 200 index_file_->LoadIndexEntries(cache_mtime, reply, load_result);
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 to_run_when_initialized_.size(), 0, 100, 20); 447 to_run_when_initialized_.size(), 0, 100, 20);
449 // Run all callbacks waiting for the index to come up. 448 // Run all callbacks waiting for the index to come up.
450 for (CallbackList::iterator it = to_run_when_initialized_.begin(), 449 for (CallbackList::iterator it = to_run_when_initialized_.begin(),
451 end = to_run_when_initialized_.end(); it != end; ++it) { 450 end = to_run_when_initialized_.end(); it != end; ++it) {
452 io_thread_->PostTask(FROM_HERE, base::Bind((*it), net::OK)); 451 io_thread_->PostTask(FROM_HERE, base::Bind((*it), net::OK));
453 } 452 }
454 to_run_when_initialized_.clear(); 453 to_run_when_initialized_.clear();
455 } 454 }
456 455
457 #if defined(OS_ANDROID) 456 #if defined(OS_ANDROID)
458 void SimpleIndex::OnActivityStateChange( 457 void SimpleIndex::OnApplicationStateChange(
459 base::android::ActivityState state) { 458 base::android::ApplicationState state) {
460 DCHECK(io_thread_checker_.CalledOnValidThread()); 459 DCHECK(io_thread_checker_.CalledOnValidThread());
461 // For more info about android activities, see: 460 // For more info about android activities, see:
462 // developer.android.com/training/basics/activity-lifecycle/pausing.html 461 // developer.android.com/training/basics/activity-lifecycle/pausing.html
463 // These values are defined in the file ActivityStatus.java 462 if (state == base::android::APPLICATION_STATE_RUNNING) {
464 if (state == base::android::ACTIVITY_STATE_RESUMED) {
465 app_on_background_ = false; 463 app_on_background_ = false;
466 } else if (state == base::android::ACTIVITY_STATE_STOPPED) { 464 } else if (state == base::android::APPLICATION_STATE_STOPPED) {
467 app_on_background_ = true; 465 app_on_background_ = true;
468 WriteToDisk(); 466 WriteToDisk();
469 } 467 }
470 } 468 }
471 #endif 469 #endif
472 470
473 void SimpleIndex::WriteToDisk() { 471 void SimpleIndex::WriteToDisk() {
474 DCHECK(io_thread_checker_.CalledOnValidThread()); 472 DCHECK(io_thread_checker_.CalledOnValidThread());
475 if (!initialized_) 473 if (!initialized_)
476 return; 474 return;
(...skipping 12 matching lines...) Expand all
489 start - last_write_to_disk_); 487 start - last_write_to_disk_);
490 } 488 }
491 } 489 }
492 last_write_to_disk_ = start; 490 last_write_to_disk_ = start;
493 491
494 index_file_->WriteToDisk(entries_set_, cache_size_, 492 index_file_->WriteToDisk(entries_set_, cache_size_,
495 start, app_on_background_); 493 start, app_on_background_);
496 } 494 }
497 495
498 } // namespace disk_cache 496 } // namespace disk_cache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698