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

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

Issue 14118006: Change owner of DriveScheduler from DriveFileSystem to DriveSystemService. (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
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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 } 47 }
48 48
49 DriveScheduler::DriveScheduler( 49 DriveScheduler::DriveScheduler(
50 Profile* profile, 50 Profile* profile,
51 google_apis::DriveServiceInterface* drive_service) 51 google_apis::DriveServiceInterface* drive_service)
52 : throttle_count_(0), 52 : throttle_count_(0),
53 disable_throttling_(false), 53 disable_throttling_(false),
54 drive_service_(drive_service), 54 drive_service_(drive_service),
55 uploader_(new google_apis::DriveUploader(drive_service)), 55 uploader_(new google_apis::DriveUploader(drive_service)),
56 profile_(profile), 56 profile_(profile),
57 initialized_(false),
58 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { 57 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
60 for (int i = 0; i < NUM_QUEUES; ++i) { 59 for (int i = 0; i < NUM_QUEUES; ++i) {
61 jobs_running_[i] = 0; 60 jobs_running_[i] = 0;
62 } 61 }
62
63 net::NetworkChangeNotifier::AddConnectionTypeObserver(this);
63 } 64 }
64 65
65 DriveScheduler::~DriveScheduler() { 66 DriveScheduler::~DriveScheduler() {
66 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
67 DCHECK(initialized_);
68 68
69 size_t num_pending_jobs = 0; 69 size_t num_pending_jobs = 0;
70 size_t num_running_jobs = 0; 70 size_t num_running_jobs = 0;
71 for (int i = 0; i < NUM_QUEUES; ++i) { 71 for (int i = 0; i < NUM_QUEUES; ++i) {
72 num_pending_jobs += queue_[i].size(); 72 num_pending_jobs += queue_[i].size();
73 num_running_jobs += jobs_running_[i]; 73 num_running_jobs += jobs_running_[i];
74 } 74 }
75 DCHECK_EQ(num_pending_jobs + num_running_jobs, job_map_.size()); 75 DCHECK_EQ(num_pending_jobs + num_running_jobs, job_map_.size());
76 76
77 for (int i = 0; i < NUM_QUEUES; ++i) { 77 for (int i = 0; i < NUM_QUEUES; ++i) {
78 STLDeleteElements(&queue_[i]); 78 STLDeleteElements(&queue_[i]);
79 } 79 }
80 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); 80 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this);
81 } 81 }
82 82
83 void DriveScheduler::Initialize() {
84 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
85
86 // Initialize() may be called more than once for the lifetime when the
87 // file system is remounted.
88 if (initialized_)
89 return;
90
91 net::NetworkChangeNotifier::AddConnectionTypeObserver(this);
92 initialized_ = true;
93 }
94
95 std::vector<JobInfo> DriveScheduler::GetJobInfoList() { 83 std::vector<JobInfo> DriveScheduler::GetJobInfoList() {
96 std::vector<JobInfo> job_info_list; 84 std::vector<JobInfo> job_info_list;
97 for (JobIDMap::iterator iter(&job_map_); !iter.IsAtEnd(); iter.Advance()) 85 for (JobIDMap::iterator iter(&job_map_); !iter.IsAtEnd(); iter.Advance())
98 job_info_list.push_back(*iter.GetCurrentValue()); 86 job_info_list.push_back(*iter.GetCurrentValue());
99 return job_info_list; 87 return job_info_list;
100 } 88 }
101 89
102 void DriveScheduler::AddObserver(JobListObserver* observer) { 90 void DriveScheduler::AddObserver(JobListObserver* observer) {
103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 91 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
104 observer_list_.AddObserver(observer); 92 observer_list_.AddObserver(observer);
(...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after
913 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 901 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
914 FOR_EACH_OBSERVER(JobListObserver, observer_list_, OnJobDone(job_info)); 902 FOR_EACH_OBSERVER(JobListObserver, observer_list_, OnJobDone(job_info));
915 } 903 }
916 904
917 void DriveScheduler::NotifyJobUpdated(const JobInfo& job_info) { 905 void DriveScheduler::NotifyJobUpdated(const JobInfo& job_info) {
918 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 906 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
919 FOR_EACH_OBSERVER(JobListObserver, observer_list_, OnJobUpdated(job_info)); 907 FOR_EACH_OBSERVER(JobListObserver, observer_list_, OnJobUpdated(job_info));
920 } 908 }
921 909
922 } // namespace drive 910 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/drive_scheduler.h ('k') | chrome/browser/chromeos/drive/drive_scheduler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698