| 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/job_scheduler.h" | 5 #include "chrome/browser/chromeos/drive/job_scheduler.h" |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/rand_util.h" | 9 #include "base/rand_util.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 StartJob(new_job); | 268 StartJob(new_job); |
| 269 } | 269 } |
| 270 | 270 |
| 271 void JobScheduler::GetAllResourceList( | 271 void JobScheduler::GetAllResourceList( |
| 272 const google_apis::GetResourceListCallback& callback) { | 272 const google_apis::GetResourceListCallback& callback) { |
| 273 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 273 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 274 DCHECK(!callback.is_null()); | 274 DCHECK(!callback.is_null()); |
| 275 | 275 |
| 276 JobEntry* new_job = CreateNewJob(TYPE_GET_ALL_RESOURCE_LIST); | 276 JobEntry* new_job = CreateNewJob(TYPE_GET_ALL_RESOURCE_LIST); |
| 277 new_job->task = base::Bind( | 277 new_job->task = base::Bind( |
| 278 &DriveServiceInterface::GetAllResourceList, | 278 &DriveServiceInterface::GetAllFileList, |
| 279 base::Unretained(drive_service_), | 279 base::Unretained(drive_service_), |
| 280 base::Bind(&JobScheduler::OnGetResourceListJobDone, | 280 base::Bind(&JobScheduler::OnGetFileListJobDone, |
| 281 weak_ptr_factory_.GetWeakPtr(), | 281 weak_ptr_factory_.GetWeakPtr(), |
| 282 new_job->job_info.job_id, | 282 new_job->job_info.job_id, |
| 283 callback)); | 283 callback)); |
| 284 new_job->abort_callback = CreateErrorRunCallback(callback); | 284 new_job->abort_callback = CreateErrorRunCallback(callback); |
| 285 StartJob(new_job); | 285 StartJob(new_job); |
| 286 } | 286 } |
| 287 | 287 |
| 288 void JobScheduler::GetResourceListInDirectory( | 288 void JobScheduler::GetResourceListInDirectory( |
| 289 const std::string& directory_resource_id, | 289 const std::string& directory_resource_id, |
| 290 const google_apis::GetResourceListCallback& callback) { | 290 const google_apis::GetResourceListCallback& callback) { |
| 291 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 291 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 292 DCHECK(!callback.is_null()); | 292 DCHECK(!callback.is_null()); |
| 293 | 293 |
| 294 JobEntry* new_job = CreateNewJob( | 294 JobEntry* new_job = CreateNewJob( |
| 295 TYPE_GET_RESOURCE_LIST_IN_DIRECTORY); | 295 TYPE_GET_RESOURCE_LIST_IN_DIRECTORY); |
| 296 new_job->task = base::Bind( | 296 new_job->task = base::Bind( |
| 297 &DriveServiceInterface::GetResourceListInDirectory, | 297 &DriveServiceInterface::GetFileListInDirectory, |
| 298 base::Unretained(drive_service_), | 298 base::Unretained(drive_service_), |
| 299 directory_resource_id, | 299 directory_resource_id, |
| 300 base::Bind(&JobScheduler::OnGetResourceListJobDone, | 300 base::Bind(&JobScheduler::OnGetFileListJobDone, |
| 301 weak_ptr_factory_.GetWeakPtr(), | 301 weak_ptr_factory_.GetWeakPtr(), |
| 302 new_job->job_info.job_id, | 302 new_job->job_info.job_id, |
| 303 callback)); | 303 callback)); |
| 304 new_job->abort_callback = CreateErrorRunCallback(callback); | 304 new_job->abort_callback = CreateErrorRunCallback(callback); |
| 305 StartJob(new_job); | 305 StartJob(new_job); |
| 306 } | 306 } |
| 307 | 307 |
| 308 void JobScheduler::Search( | 308 void JobScheduler::Search( |
| 309 const std::string& search_query, | 309 const std::string& search_query, |
| 310 const google_apis::GetResourceListCallback& callback) { | 310 const google_apis::GetResourceListCallback& callback) { |
| 311 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 311 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 312 DCHECK(!callback.is_null()); | 312 DCHECK(!callback.is_null()); |
| 313 | 313 |
| 314 JobEntry* new_job = CreateNewJob(TYPE_SEARCH); | 314 JobEntry* new_job = CreateNewJob(TYPE_SEARCH); |
| 315 new_job->task = base::Bind( | 315 new_job->task = base::Bind( |
| 316 &DriveServiceInterface::Search, | 316 &DriveServiceInterface::Search, |
| 317 base::Unretained(drive_service_), | 317 base::Unretained(drive_service_), |
| 318 search_query, | 318 search_query, |
| 319 base::Bind(&JobScheduler::OnGetResourceListJobDone, | 319 base::Bind(&JobScheduler::OnGetFileListJobDone, |
| 320 weak_ptr_factory_.GetWeakPtr(), | 320 weak_ptr_factory_.GetWeakPtr(), |
| 321 new_job->job_info.job_id, | 321 new_job->job_info.job_id, |
| 322 callback)); | 322 callback)); |
| 323 new_job->abort_callback = CreateErrorRunCallback(callback); | 323 new_job->abort_callback = CreateErrorRunCallback(callback); |
| 324 StartJob(new_job); | 324 StartJob(new_job); |
| 325 } | 325 } |
| 326 | 326 |
| 327 void JobScheduler::GetChangeList( | 327 void JobScheduler::GetChangeList( |
| 328 int64 start_changestamp, | 328 int64 start_changestamp, |
| 329 const google_apis::GetResourceListCallback& callback) { | 329 const google_apis::GetResourceListCallback& callback) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 const GURL& next_link, | 366 const GURL& next_link, |
| 367 const google_apis::GetResourceListCallback& callback) { | 367 const google_apis::GetResourceListCallback& callback) { |
| 368 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 368 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 369 DCHECK(!callback.is_null()); | 369 DCHECK(!callback.is_null()); |
| 370 | 370 |
| 371 JobEntry* new_job = CreateNewJob(TYPE_GET_REMAINING_FILE_LIST); | 371 JobEntry* new_job = CreateNewJob(TYPE_GET_REMAINING_FILE_LIST); |
| 372 new_job->task = base::Bind( | 372 new_job->task = base::Bind( |
| 373 &DriveServiceInterface::GetRemainingFileList, | 373 &DriveServiceInterface::GetRemainingFileList, |
| 374 base::Unretained(drive_service_), | 374 base::Unretained(drive_service_), |
| 375 next_link, | 375 next_link, |
| 376 base::Bind(&JobScheduler::OnGetResourceListJobDone, | 376 base::Bind(&JobScheduler::OnGetFileListJobDone, |
| 377 weak_ptr_factory_.GetWeakPtr(), | 377 weak_ptr_factory_.GetWeakPtr(), |
| 378 new_job->job_info.job_id, | 378 new_job->job_info.job_id, |
| 379 callback)); | 379 callback)); |
| 380 new_job->abort_callback = CreateErrorRunCallback(callback); | 380 new_job->abort_callback = CreateErrorRunCallback(callback); |
| 381 StartJob(new_job); | 381 StartJob(new_job); |
| 382 } | 382 } |
| 383 | 383 |
| 384 void JobScheduler::GetResourceEntry( | 384 void JobScheduler::GetResourceEntry( |
| 385 const std::string& resource_id, | 385 const std::string& resource_id, |
| 386 const ClientContext& context, | 386 const ClientContext& context, |
| (...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 892 | 892 |
| 893 // Post a task to continue the job loop. This allows us to finish handling | 893 // Post a task to continue the job loop. This allows us to finish handling |
| 894 // the current job before starting the next one. | 894 // the current job before starting the next one. |
| 895 base::MessageLoopProxy::current()->PostTask(FROM_HERE, | 895 base::MessageLoopProxy::current()->PostTask(FROM_HERE, |
| 896 base::Bind(&JobScheduler::DoJobLoop, | 896 base::Bind(&JobScheduler::DoJobLoop, |
| 897 weak_ptr_factory_.GetWeakPtr(), | 897 weak_ptr_factory_.GetWeakPtr(), |
| 898 queue_type)); | 898 queue_type)); |
| 899 return !should_retry; | 899 return !should_retry; |
| 900 } | 900 } |
| 901 | 901 |
| 902 void JobScheduler::OnGetFileListJobDone( |
| 903 JobID job_id, |
| 904 const google_apis::GetResourceListCallback& callback, |
| 905 google_apis::GDataErrorCode error, |
| 906 scoped_ptr<google_apis::FileList> file_list) { |
| 907 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 908 DCHECK(!callback.is_null()); |
| 909 |
| 910 if (OnJobDone(job_id, error)) { |
| 911 callback.Run(error, file_list ? |
| 912 util::ConvertFileListToResourceList(*file_list) : |
| 913 scoped_ptr<google_apis::ResourceList>()); |
| 914 } |
| 915 } |
| 916 |
| 902 void JobScheduler::OnGetChangeListJobDone( | 917 void JobScheduler::OnGetChangeListJobDone( |
| 903 JobID job_id, | 918 JobID job_id, |
| 904 const google_apis::GetResourceListCallback& callback, | 919 const google_apis::GetResourceListCallback& callback, |
| 905 google_apis::GDataErrorCode error, | 920 google_apis::GDataErrorCode error, |
| 906 scoped_ptr<google_apis::ChangeList> change_list) { | 921 scoped_ptr<google_apis::ChangeList> change_list) { |
| 907 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 922 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 908 DCHECK(!callback.is_null()); | 923 DCHECK(!callback.is_null()); |
| 909 | 924 |
| 910 if (OnJobDone(job_id, error)) { | 925 if (OnJobDone(job_id, error)) { |
| 911 callback.Run(error, change_list ? | 926 callback.Run(error, change_list ? |
| 912 util::ConvertChangeListToResourceList(*change_list) : | 927 util::ConvertChangeListToResourceList(*change_list) : |
| 913 scoped_ptr<google_apis::ResourceList>()); | 928 scoped_ptr<google_apis::ResourceList>()); |
| 914 | 929 |
| 915 } | 930 } |
| 916 } | 931 } |
| 917 | 932 |
| 918 void JobScheduler::OnGetResourceListJobDone( | |
| 919 JobID job_id, | |
| 920 const google_apis::GetResourceListCallback& callback, | |
| 921 google_apis::GDataErrorCode error, | |
| 922 scoped_ptr<google_apis::ResourceList> resource_list) { | |
| 923 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 924 DCHECK(!callback.is_null()); | |
| 925 | |
| 926 if (OnJobDone(job_id, error)) | |
| 927 callback.Run(error, resource_list.Pass()); | |
| 928 } | |
| 929 | |
| 930 void JobScheduler::OnGetResourceEntryJobDone( | 933 void JobScheduler::OnGetResourceEntryJobDone( |
| 931 JobID job_id, | 934 JobID job_id, |
| 932 const google_apis::GetResourceEntryCallback& callback, | 935 const google_apis::GetResourceEntryCallback& callback, |
| 933 google_apis::GDataErrorCode error, | 936 google_apis::GDataErrorCode error, |
| 934 scoped_ptr<google_apis::ResourceEntry> entry) { | 937 scoped_ptr<google_apis::ResourceEntry> entry) { |
| 935 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 938 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 936 DCHECK(!callback.is_null()); | 939 DCHECK(!callback.is_null()); |
| 937 | 940 |
| 938 if (OnJobDone(job_id, error)) | 941 if (OnJobDone(job_id, error)) |
| 939 callback.Run(error, entry.Pass()); | 942 callback.Run(error, entry.Pass()); |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1162 case FILE_QUEUE: | 1165 case FILE_QUEUE: |
| 1163 return "FILE_QUEUE"; | 1166 return "FILE_QUEUE"; |
| 1164 case NUM_QUEUES: | 1167 case NUM_QUEUES: |
| 1165 break; // This value is just a sentinel. Should never be used. | 1168 break; // This value is just a sentinel. Should never be used. |
| 1166 } | 1169 } |
| 1167 NOTREACHED(); | 1170 NOTREACHED(); |
| 1168 return ""; | 1171 return ""; |
| 1169 } | 1172 } |
| 1170 | 1173 |
| 1171 } // namespace drive | 1174 } // namespace drive |
| OLD | NEW |