1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef GOOGLE_APIS_DRIVE_FILES_LIST_REQUEST_RUNNER_H_
6 #define GOOGLE_APIS_DRIVE_FILES_LIST_REQUEST_RUNNER_H_
10 #include "base/basictypes.h"
11 #include "base/callback_forward.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "google_apis/drive/drive_api_requests.h"
15 #include "google_apis/drive/drive_api_url_generator.h"
16 #include "google_apis/drive/drive_common_callbacks.h"
18 namespace google_apis
{
22 // Runs file list requests (the FileListRequest class) with a backoff retry
23 // logic in case of the DRIVE_RESPONSE_TOO_LARGE error code.
24 class FilesListRequestRunner
{
26 FilesListRequestRunner(
27 RequestSender
* request_sender
,
28 const google_apis::DriveApiUrlGenerator
& url_generator
);
30 // Creates a FilesListRequest instance and starts the request with a backoff
31 // retry in case of DRIVE_RESPONSE_TOO_LARGE error code.
32 CancelCallback
CreateAndStartWithSizeBackoff(
35 const std::string
& fields
,
36 const FileListCallback
& callback
);
38 ~FilesListRequestRunner();
40 void SetRequestCompletedCallbackForTesting(const base::Closure
& callback
);
43 // Called when the cancelling callback returned by
44 // CreateAndStartWithSizeBackoff is invoked. Once called cancels the current
46 void OnCancel(CancelCallback
* cancel_callback
);
48 // Called when a single request is completed with either a success or an
49 // error. In case of DRIVE_RESPONSE_TOO_LARGE it will retry the request with
50 // half of the requests.
51 void OnCompleted(int max_results
,
53 const std::string
& fields
,
54 const FileListCallback
& callback
,
55 CancelCallback
* cancel_callback
,
56 DriveApiErrorCode error
,
57 scoped_ptr
<FileList
> entry
);
59 RequestSender
* request_sender_
; // Not owned.
60 const google_apis::DriveApiUrlGenerator url_generator_
; // Not owned.
61 base::Closure request_completed_callback_for_testing_
;
63 // Note: This should remain the last member so it'll be destroyed and
64 // invalidate its weak pointers before any other members are destroyed.
65 base::WeakPtrFactory
<FilesListRequestRunner
> weak_ptr_factory_
;
66 DISALLOW_COPY_AND_ASSIGN(FilesListRequestRunner
);
69 } // namespace google_apis
71 #endif // GOOGLE_APIS_DRIVE_FILES_LIST_REQUEST_RUNNER_H_