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

Side by Side Diff: chrome/browser/chromeos/drive/drive_scheduler.cc

Issue 14367010: Fire event notification from DriveScheduler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 7 years, 8 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
« no previous file with comments | « no previous file | chrome/browser/chromeos/drive/drive_scheduler_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/chromeos/drive/drive_scheduler.h" 5 #include "chrome/browser/chromeos/drive/drive_scheduler.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 8
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 StartNewJob(new_job.Pass(), TYPE_UPLOAD_EXISTING_FILE); 359 StartNewJob(new_job.Pass(), TYPE_UPLOAD_EXISTING_FILE);
360 } 360 }
361 361
362 void DriveScheduler::StartNewJob(scoped_ptr<QueueEntry> job, JobType type) { 362 void DriveScheduler::StartNewJob(scoped_ptr<QueueEntry> job, JobType type) {
363 // job_info is owned by job_map_ and released when it is removed in OnJobDone. 363 // job_info is owned by job_map_ and released when it is removed in OnJobDone.
364 JobInfo* job_info = new JobInfo(type); 364 JobInfo* job_info = new JobInfo(type);
365 job->job_id = job_info->job_id = job_map_.Add(job_info); 365 job->job_id = job_info->job_id = job_map_.Add(job_info);
366 job_info->file_path = job->drive_file_path; 366 job_info->file_path = job->drive_file_path;
367 367
368 QueueJob(job.Pass()); 368 QueueJob(job.Pass());
369 NotifyJobAdded(*job_info);
369 StartJobLoop(GetJobQueueType(type)); 370 StartJobLoop(GetJobQueueType(type));
370 } 371 }
371 372
372 void DriveScheduler::QueueJob(scoped_ptr<QueueEntry> job) { 373 void DriveScheduler::QueueJob(scoped_ptr<QueueEntry> job) {
373 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 374 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
374 375
375 JobInfo* job_info = job_map_.Lookup(job->job_id); 376 JobInfo* job_info = job_map_.Lookup(job->job_id);
376 DCHECK(job_info); 377 DCHECK(job_info);
377 378
378 QueueType queue_type = GetJobQueueType(job_info->job_type); 379 QueueType queue_type = GetJobQueueType(job_info->job_type);
(...skipping 25 matching lines...) Expand all
404 // Increment the number of jobs. 405 // Increment the number of jobs.
405 ++jobs_running_[queue_type]; 406 ++jobs_running_[queue_type];
406 407
407 // Should copy before calling queue_.pop_front(). 408 // Should copy before calling queue_.pop_front().
408 scoped_ptr<QueueEntry> queue_entry(queue_[queue_type].front()); 409 scoped_ptr<QueueEntry> queue_entry(queue_[queue_type].front());
409 queue_[queue_type].pop_front(); 410 queue_[queue_type].pop_front();
410 411
411 JobInfo* job_info = job_map_.Lookup(queue_entry->job_id); 412 JobInfo* job_info = job_map_.Lookup(queue_entry->job_id);
412 DCHECK(job_info); 413 DCHECK(job_info);
413 job_info->state = STATE_RUNNING; 414 job_info->state = STATE_RUNNING;
415 NotifyJobUpdated(*job_info);
414 416
415 // The some arguments are evaluated after bind, so we copy the pointer to the 417 // The some arguments are evaluated after bind, so we copy the pointer to the
416 // QueueEntry 418 // QueueEntry
417 QueueEntry* entry = queue_entry.get(); 419 QueueEntry* entry = queue_entry.get();
418 420
419 switch (job_info->job_type) { 421 switch (job_info->job_type) {
420 case TYPE_GET_ABOUT_RESOURCE: { 422 case TYPE_GET_ABOUT_RESOURCE: {
421 drive_service_->GetAboutResource( 423 drive_service_->GetAboutResource(
422 base::Bind(&DriveScheduler::OnGetAboutResourceJobDone, 424 base::Bind(&DriveScheduler::OnGetAboutResourceJobDone,
423 weak_ptr_factory_.GetWeakPtr(), 425 weak_ptr_factory_.GetWeakPtr(),
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 JobInfo* job_info = job_map_.Lookup(queue_entry->job_id); 689 JobInfo* job_info = job_map_.Lookup(queue_entry->job_id);
688 DCHECK(job_info); 690 DCHECK(job_info);
689 QueueType queue_type = GetJobQueueType(job_info->job_type); 691 QueueType queue_type = GetJobQueueType(job_info->job_type);
690 692
691 // Decrement the number of jobs for this queue. 693 // Decrement the number of jobs for this queue.
692 --jobs_running_[queue_type]; 694 --jobs_running_[queue_type];
693 695
694 // Retry, depending on the error. 696 // Retry, depending on the error.
695 if (error == DRIVE_FILE_ERROR_THROTTLED) { 697 if (error == DRIVE_FILE_ERROR_THROTTLED) {
696 job_info->state = STATE_RETRY; 698 job_info->state = STATE_RETRY;
699 NotifyJobUpdated(*job_info);
697 700
698 // Requeue the job. 701 // Requeue the job.
699 QueueJob(queue_entry.Pass()); 702 QueueJob(queue_entry.Pass());
700 703
701 ThrottleAndContinueJobLoop(queue_type); 704 ThrottleAndContinueJobLoop(queue_type);
702 705
703 return scoped_ptr<DriveScheduler::QueueEntry>(); 706 return scoped_ptr<DriveScheduler::QueueEntry>();
704 } else { 707 } else {
708 NotifyJobDone(*job_info, error);
705 // The job has finished, no retry will happen in the scheduler. Now we can 709 // The job has finished, no retry will happen in the scheduler. Now we can
706 // remove the job info from the map. This is the only place of the removal. 710 // remove the job info from the map. This is the only place of the removal.
707 job_map_.Remove(queue_entry->job_id); 711 job_map_.Remove(queue_entry->job_id);
708 712
709 ResetThrottleAndContinueJobLoop(queue_type); 713 ResetThrottleAndContinueJobLoop(queue_type);
710 714
711 // Send the entry back. 715 // Send the entry back.
712 return queue_entry.Pass(); 716 return queue_entry.Pass();
713 } 717 }
714 } 718 }
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 queue_entry->upload_completion_callback.Run( 860 queue_entry->upload_completion_callback.Run(
857 error, drive_path, file_path, resource_entry.Pass()); 861 error, drive_path, file_path, resource_entry.Pass());
858 } 862 }
859 863
860 void DriveScheduler::UpdateProgress(JobID job_id, int64 progress, int64 total) { 864 void DriveScheduler::UpdateProgress(JobID job_id, int64 progress, int64 total) {
861 JobInfo* job_info = job_map_.Lookup(job_id); 865 JobInfo* job_info = job_map_.Lookup(job_id);
862 DCHECK(job_info); 866 DCHECK(job_info);
863 867
864 job_info->num_completed_bytes = progress; 868 job_info->num_completed_bytes = progress;
865 job_info->num_total_bytes = total; 869 job_info->num_total_bytes = total;
870 NotifyJobUpdated(*job_info);
866 } 871 }
867 872
868 void DriveScheduler::OnConnectionTypeChanged( 873 void DriveScheduler::OnConnectionTypeChanged(
869 net::NetworkChangeNotifier::ConnectionType type) { 874 net::NetworkChangeNotifier::ConnectionType type) {
870 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 875 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
871 876
872 // Resume the job loop if the network is back online. Note that we don't 877 // Resume the job loop if the network is back online. Note that we don't
873 // need to check the type of the network as it will be checked in 878 // need to check the type of the network as it will be checked in
874 // ShouldStopJobLoop() as soon as the loop is resumed. 879 // ShouldStopJobLoop() as soon as the loop is resumed.
875 if (!net::NetworkChangeNotifier::IsOffline()) { 880 if (!net::NetworkChangeNotifier::IsOffline()) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
918 FOR_EACH_OBSERVER(JobListObserver, observer_list_, 923 FOR_EACH_OBSERVER(JobListObserver, observer_list_,
919 OnJobDone(job_info, error)); 924 OnJobDone(job_info, error));
920 } 925 }
921 926
922 void DriveScheduler::NotifyJobUpdated(const JobInfo& job_info) { 927 void DriveScheduler::NotifyJobUpdated(const JobInfo& job_info) {
923 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 928 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
924 FOR_EACH_OBSERVER(JobListObserver, observer_list_, OnJobUpdated(job_info)); 929 FOR_EACH_OBSERVER(JobListObserver, observer_list_, OnJobUpdated(job_info));
925 } 930 }
926 931
927 } // namespace drive 932 } // namespace drive
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/drive/drive_scheduler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698