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

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: Split DriveJobListInterface. 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
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(DriveJobListObserver* observer) {
103 observer_list_.AddObserver(observer);
104 }
105
106 void DriveScheduler::RemoveObserver(DriveJobListObserver* observer) {
107 observer_list_.RemoveObserver(observer);
108 }
109
111 void DriveScheduler::GetAccountMetadata( 110 void DriveScheduler::GetAccountMetadata(
112 const google_apis::GetAccountMetadataCallback& callback) { 111 const google_apis::GetAccountMetadataCallback& callback) {
113 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 112 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
114 DCHECK(!callback.is_null()); 113 DCHECK(!callback.is_null());
115 114
116 scoped_ptr<QueueEntry> new_job(new QueueEntry); 115 scoped_ptr<QueueEntry> new_job(new QueueEntry);
117 new_job->get_account_metadata_callback = callback; 116 new_job->get_account_metadata_callback = callback;
118 117
119 StartNewJob(new_job.Pass(), TYPE_GET_ACCOUNT_METADATA); 118 StartNewJob(new_job.Pass(), TYPE_GET_ACCOUNT_METADATA);
120 } 119 }
(...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 895
897 case TYPE_DOWNLOAD_FILE: 896 case TYPE_DOWNLOAD_FILE:
898 case TYPE_UPLOAD_NEW_FILE: 897 case TYPE_UPLOAD_NEW_FILE:
899 case TYPE_UPLOAD_EXISTING_FILE: 898 case TYPE_UPLOAD_EXISTING_FILE:
900 return FILE_QUEUE; 899 return FILE_QUEUE;
901 } 900 }
902 NOTREACHED(); 901 NOTREACHED();
903 return FILE_QUEUE; 902 return FILE_QUEUE;
904 } 903 }
905 904
905 void DriveScheduler::NotifyJobAdded(const JobInfo& job_info) {
906 FOR_EACH_OBSERVER(DriveJobListObserver, observer_list_,
907 OnJobAdded(job_info));
908 }
909
910 void DriveScheduler::NotifyJobDone(const JobInfo& job_info) {
911 FOR_EACH_OBSERVER(DriveJobListObserver, observer_list_,
912 OnJobDone(job_info));
913 }
914
915 void DriveScheduler::NotifyJobUpdated(const JobInfo& job_info) {
916 FOR_EACH_OBSERVER(DriveJobListObserver, observer_list_,
917 OnJobUpdated(job_info));
satorux1 2013/04/17 00:11:29 These are not used in this patch. Intentional?
kinaba 2013/04/17 00:51:42 Intentional (especially for NotifyJobUpdated, not
918 }
919
906 } // namespace drive 920 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698