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

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

Issue 14148006: Add an observer interface for DriveScheduler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review fix/ 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
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 12 matching lines...) Expand all
23 23
24 namespace { 24 namespace {
25 const int kMaxThrottleCount = 5; 25 const int kMaxThrottleCount = 5;
26 } 26 }
27 27
28 const int DriveScheduler::kMaxJobCount[] = { 28 const int DriveScheduler::kMaxJobCount[] = {
29 5, // METADATA_QUEUE 29 5, // METADATA_QUEUE
30 1, // FILE_QUEUE 30 1, // FILE_QUEUE
31 }; 31 };
32 32
33 DriveScheduler::JobInfo::JobInfo(JobType in_job_type)
34 : job_type(in_job_type),
35 job_id(-1),
36 completed_bytes(0),
37 total_bytes(0),
38 state(STATE_NONE) {
39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
40 }
41
42 DriveScheduler::QueueEntry::QueueEntry() 33 DriveScheduler::QueueEntry::QueueEntry()
43 : job_id(-1), 34 : job_id(-1),
44 context(DriveClientContext(USER_INITIATED)) { 35 context(DriveClientContext(USER_INITIATED)) {
45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
46 } 37 }
47 38
48 DriveScheduler::QueueEntry::~QueueEntry() { 39 DriveScheduler::QueueEntry::~QueueEntry() {
49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
50 } 41 }
51 42
52 bool DriveScheduler::QueueEntry::Compare( 43 bool DriveScheduler::QueueEntry::Compare(
53 const DriveScheduler::QueueEntry* left, 44 const DriveScheduler::QueueEntry* left,
54 const DriveScheduler::QueueEntry* right) { 45 const DriveScheduler::QueueEntry* right) {
55 return (left->context.type < right->context.type); 46 return (left->context.type < right->context.type);
56 } 47 }
57 48
58 DriveScheduler::DriveScheduler( 49 DriveScheduler::DriveScheduler(
59 Profile* profile, 50 Profile* profile,
60 google_apis::DriveServiceInterface* drive_service) 51 google_apis::DriveServiceInterface* drive_service)
61 : next_job_id_(0), 52 : throttle_count_(0),
62 throttle_count_(0),
63 disable_throttling_(false), 53 disable_throttling_(false),
64 drive_service_(drive_service), 54 drive_service_(drive_service),
65 uploader_(new google_apis::DriveUploader(drive_service)), 55 uploader_(new google_apis::DriveUploader(drive_service)),
66 profile_(profile), 56 profile_(profile),
67 initialized_(false), 57 initialized_(false),
68 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { 58 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
70 for (int i = 0; i < NUM_QUEUES; ++i) { 60 for (int i = 0; i < NUM_QUEUES; ++i) {
71 jobs_running_[i] = 0; 61 jobs_running_[i] = 0;
72 } 62 }
(...skipping 22 matching lines...) Expand all
95 85
96 // Initialize() may be called more than once for the lifetime when the 86 // Initialize() may be called more than once for the lifetime when the
97 // file system is remounted. 87 // file system is remounted.
98 if (initialized_) 88 if (initialized_)
99 return; 89 return;
100 90
101 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); 91 net::NetworkChangeNotifier::AddConnectionTypeObserver(this);
102 initialized_ = true; 92 initialized_ = true;
103 } 93 }
104 94
95 std::vector<JobInfo> DriveScheduler::GetJobInfoList() {
96 std::vector<JobInfo> job_info_list;
97 for (JobIDMap::iterator iter(&job_map_); !iter.IsAtEnd(); iter.Advance())
98 job_info_list.push_back(*iter.GetCurrentValue());
99 return job_info_list;
100 }
101
102 void DriveScheduler::AddObserver(JobListObserver* observer) {
103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
104 observer_list_.AddObserver(observer);
105 }
106
107 void DriveScheduler::RemoveObserver(JobListObserver* observer) {
108 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
109 observer_list_.RemoveObserver(observer);
110 }
111
105 void DriveScheduler::GetAccountMetadata( 112 void DriveScheduler::GetAccountMetadata(
106 const google_apis::GetAccountMetadataCallback& callback) { 113 const google_apis::GetAccountMetadataCallback& callback) {
107 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 114 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
108 DCHECK(!callback.is_null()); 115 DCHECK(!callback.is_null());
109 116
110 scoped_ptr<QueueEntry> new_job(new QueueEntry); 117 scoped_ptr<QueueEntry> new_job(new QueueEntry);
111 new_job->get_account_metadata_callback = callback; 118 new_job->get_account_metadata_callback = callback;
112 119
113 StartNewJob(new_job.Pass(), TYPE_GET_ACCOUNT_METADATA); 120 StartNewJob(new_job.Pass(), TYPE_GET_ACCOUNT_METADATA);
114 } 121 }
(...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 897
891 case TYPE_DOWNLOAD_FILE: 898 case TYPE_DOWNLOAD_FILE:
892 case TYPE_UPLOAD_NEW_FILE: 899 case TYPE_UPLOAD_NEW_FILE:
893 case TYPE_UPLOAD_EXISTING_FILE: 900 case TYPE_UPLOAD_EXISTING_FILE:
894 return FILE_QUEUE; 901 return FILE_QUEUE;
895 } 902 }
896 NOTREACHED(); 903 NOTREACHED();
897 return FILE_QUEUE; 904 return FILE_QUEUE;
898 } 905 }
899 906
907 void DriveScheduler::NotifyJobAdded(const JobInfo& job_info) {
908 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
909 FOR_EACH_OBSERVER(JobListObserver, observer_list_, OnJobAdded(job_info));
910 }
911
912 void DriveScheduler::NotifyJobDone(const JobInfo& job_info) {
913 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
914 FOR_EACH_OBSERVER(JobListObserver, observer_list_, OnJobDone(job_info));
915 }
916
917 void DriveScheduler::NotifyJobUpdated(const JobInfo& job_info) {
918 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
919 FOR_EACH_OBSERVER(JobListObserver, observer_list_, OnJobUpdated(job_info));
920 }
921
900 } // namespace drive 922 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698