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/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 Loading... |
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 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 | 85 |
95 // 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 |
96 // file system is remounted. | 87 // file system is remounted. |
97 if (initialized_) | 88 if (initialized_) |
98 return; | 89 return; |
99 | 90 |
100 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); | 91 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); |
101 initialized_ = true; | 92 initialized_ = true; |
102 } | 93 } |
103 | 94 |
104 std::vector<DriveScheduler::JobInfo> DriveScheduler::GetJobInfoList() { | 95 std::vector<JobInfo> DriveScheduler::GetJobInfoList() { |
105 std::vector<JobInfo> job_info_list; | 96 std::vector<JobInfo> job_info_list; |
106 for (JobIDMap::iterator iter(&job_map_); !iter.IsAtEnd(); iter.Advance()) | 97 for (JobIDMap::iterator iter(&job_map_); !iter.IsAtEnd(); iter.Advance()) |
107 job_info_list.push_back(*iter.GetCurrentValue()); | 98 job_info_list.push_back(*iter.GetCurrentValue()); |
108 return job_info_list; | 99 return job_info_list; |
109 } | 100 } |
110 | 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 |
111 void DriveScheduler::GetAccountMetadata( | 112 void DriveScheduler::GetAccountMetadata( |
112 const google_apis::GetAccountMetadataCallback& callback) { | 113 const google_apis::GetAccountMetadataCallback& callback) { |
113 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 114 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
114 DCHECK(!callback.is_null()); | 115 DCHECK(!callback.is_null()); |
115 | 116 |
116 scoped_ptr<QueueEntry> new_job(new QueueEntry); | 117 scoped_ptr<QueueEntry> new_job(new QueueEntry); |
117 new_job->get_account_metadata_callback = callback; | 118 new_job->get_account_metadata_callback = callback; |
118 | 119 |
119 StartNewJob(new_job.Pass(), TYPE_GET_ACCOUNT_METADATA); | 120 StartNewJob(new_job.Pass(), TYPE_GET_ACCOUNT_METADATA); |
120 } | 121 } |
(...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
896 | 897 |
897 case TYPE_DOWNLOAD_FILE: | 898 case TYPE_DOWNLOAD_FILE: |
898 case TYPE_UPLOAD_NEW_FILE: | 899 case TYPE_UPLOAD_NEW_FILE: |
899 case TYPE_UPLOAD_EXISTING_FILE: | 900 case TYPE_UPLOAD_EXISTING_FILE: |
900 return FILE_QUEUE; | 901 return FILE_QUEUE; |
901 } | 902 } |
902 NOTREACHED(); | 903 NOTREACHED(); |
903 return FILE_QUEUE; | 904 return FILE_QUEUE; |
904 } | 905 } |
905 | 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 |
906 } // namespace drive | 922 } // namespace drive |
OLD | NEW |