1 // Copyright 2013 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 CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_DOWNLOAD_OPERATION_H_
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_DOWNLOAD_OPERATION_H_
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "chrome/browser/chromeos/drive/file_errors.h"
11 #include "chrome/browser/chromeos/drive/file_system_interface.h"
12 #include "chrome/browser/chromeos/drive/job_list.h"
13 #include "google_apis/drive/gdata_errorcode.h"
17 class SequencedTaskRunner
;
20 namespace google_apis
{
22 } // namespace google_apis
31 class ResourceMetadata
;
32 } // namespace internal
34 namespace file_system
{
36 class OperationObserver
;
38 class DownloadOperation
{
40 DownloadOperation(base::SequencedTaskRunner
* blocking_task_runner
,
41 OperationObserver
* observer
,
42 JobScheduler
* scheduler
,
43 internal::ResourceMetadata
* metadata
,
44 internal::FileCache
* cache
,
45 const base::FilePath
& temporary_file_directory
);
48 // Ensures that the file content specified by |local_id| is locally
50 // For hosted documents, this method may create a JSON file representing the
52 // For regular files, if the locally cached file is found, returns it.
53 // If not found, start to download the file from the server.
54 // When a JSON file is created, the cache file is found or downloading is
55 // being started, |initialized_callback| is called with |local_file|
56 // for JSON file or the cache file, or with |cancel_download_closure| for
58 // During the downloading |get_content_callback| will be called periodically
59 // with the downloaded content.
60 // Upon completion or an error is found, |completion_callback| will be called.
61 // |initialized_callback| and |get_content_callback| can be null if not
63 // |completion_callback| must not be null.
64 void EnsureFileDownloadedByLocalId(
65 const std::string
& local_id
,
66 const ClientContext
& context
,
67 const GetFileContentInitializedCallback
& initialized_callback
,
68 const google_apis::GetContentCallback
& get_content_callback
,
69 const GetFileCallback
& completion_callback
);
71 // Does the same thing as EnsureFileDownloadedByLocalId for the file
72 // specified by |file_path|.
73 void EnsureFileDownloadedByPath(
74 const base::FilePath
& file_path
,
75 const ClientContext
& context
,
76 const GetFileContentInitializedCallback
& initialized_callback
,
77 const google_apis::GetContentCallback
& get_content_callback
,
78 const GetFileCallback
& completion_callback
);
81 // Parameters for EnsureFileDownloaded.
84 // Part of EnsureFileDownloaded(). Called upon the completion of precondition
86 void EnsureFileDownloadedAfterCheckPreCondition(
87 scoped_ptr
<DownloadParams
> params
,
88 const ClientContext
& context
,
89 base::FilePath
* drive_file_path
,
90 base::FilePath
* cache_file_path
,
93 // Part of EnsureFileDownloaded(). Called when it is ready to start
94 // downloading the file.
95 void EnsureFileDownloadedAfterPrepareForDownloadFile(
96 scoped_ptr
<DownloadParams
> params
,
97 const ClientContext
& context
,
98 const base::FilePath
& drive_file_path
,
99 base::FilePath
* temp_download_file_path
,
102 // Part of EnsureFileDownloaded(). Called after the actual downloading.
103 void EnsureFileDownloadedAfterDownloadFile(
104 const base::FilePath
& drive_file_path
,
105 scoped_ptr
<DownloadParams
> params
,
106 google_apis::GDataErrorCode gdata_error
,
107 const base::FilePath
& downloaded_file_path
);
109 // Part of EnsureFileDownloaded(). Called after updating local state is
111 void EnsureFileDownloadedAfterUpdateLocalState(
112 const base::FilePath
& file_path
,
113 scoped_ptr
<DownloadParams
> params
,
114 base::FilePath
* cache_file_path
,
117 // Cancels the job with |job_id| in the scheduler.
118 void CancelJob(JobID job_id
);
120 scoped_refptr
<base::SequencedTaskRunner
> blocking_task_runner_
;
121 OperationObserver
* observer_
;
122 JobScheduler
* scheduler_
;
123 internal::ResourceMetadata
* metadata_
;
124 internal::FileCache
* cache_
;
125 const base::FilePath temporary_file_directory_
;
127 // Note: This should remain the last member so it'll be destroyed and
128 // invalidate its weak pointers before any other members are destroyed.
129 base::WeakPtrFactory
<DownloadOperation
> weak_ptr_factory_
;
130 DISALLOW_COPY_AND_ASSIGN(DownloadOperation
);
133 } // namespace file_system
136 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_DOWNLOAD_OPERATION_H_