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

Side by Side Diff: chrome/browser/chromeos/drive/file_system/download_operation.h

Issue 15681009: Extract GetResolveFile into DownloadOperation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 7 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
(Empty)
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.
4
5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_DOWNLOAD_OPERATION_H_
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_DOWNLOAD_OPERATION_H_
7
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 "chrome/browser/google_apis/drive_service_interface.h"
14 #include "chrome/browser/google_apis/gdata_errorcode.h"
15
16 namespace base {
17 class FilePath;
18 class SequencedTaskRunner;
19 } // namespace base
20
21 namespace google_apis {
22 class ResourceEntry;
23 } // namespace google_apis
24
25 namespace drive {
26
27 class JobScheduler;
28 class ResourceEntry;
29
30 namespace internal {
31 class FileCache;
32 class ResourceMetadtata;
33 } // namespace internal
34
35 namespace file_system {
36
37 class OperationObserver;
38
39 class DownloadOperation {
40 public:
41 DownloadOperation(base::SequencedTaskRunner* blocking_task_runner,
42 OperationObserver* observer,
43 JobScheduler* scheduler,
44 internal::ResourceMetadata* metadata,
45 internal::FileCache* cache);
46 ~DownloadOperation();
47
48 // Ensures that the file content is locally downloaded.
49 // For hosted documents, this method may create a JSON file representing the
50 // file.
51 // For regular files, if the locally cached file is found, returns it.
52 // If not found, start to download the file from the server.
53 // When a JSON file is created, the cache file is found or downloading is
54 // being started, |initialized_callback| is called with |local_file|
55 // for JSON file or the cache file, or with |cancel_download_closure| for
56 // downloading.
57 // During the downloading |get_content_callback| will be called periodically
58 // with the downloaded content.
59 // Upon completion or an error is found, |completion_callback| will be
60 // called.
61 // |initialized_callback| and |get_content_callback| can be null if not
62 // needed.
63 // |completion_callback| must not be null.
64 void EnsureFileDownloaded(
65 const base::FilePath& file_path,
66 DriveClientContext context,
67 const GetFileContentInitializedCallback& initialized_callback,
68 const google_apis::GetContentCallback& get_content_callback,
69 const GetFileCallback& completion_callback);
70
71 private:
72 // Thin wrapper of Callbacks for EnsureFileDownloaded.
73 class DownloadCallback;
74
75 // Parameters for JobScheduler::DownloadFile.
76 struct DownloadParams;
77
78 // Part of EnsureFileDownloaded(). Called upon the completion of precondition
79 // check.
80 void EnsureFileDownloadedAfterCheckPreCondition(
81 const base::FilePath& file_path,
82 DriveClientContext context,
83 const DownloadCallback& callback,
84 scoped_ptr<ResourceEntry> entry,
85 base::FilePath* cache_file_path,
86 FileError error);
87
88 // Part of EnsureFileDownloaded(). Called upon the completion of fetching
89 // ResourceEntry from the server.
90 void EnsureFileDownloadedAfterGetResourceEntry(
91 DriveClientContext context,
92 const DownloadCallback& callback,
93 google_apis::GDataErrorCode gdata_error,
94 scoped_ptr<google_apis::ResourceEntry> resource_entry);
95
96 // Part of EnsureFileDownloaded(). Called when it is ready to start
97 // downloading the file.
98 void EnsureFileDownloadedAfterPrepareForDownloadFile(
99 DownloadParams* params,
100 const DownloadCallback& callback,
101 FileError error);
102
103 // Part of EnsureFileDownloaded(). Called after the actual downloading.
104 void EnsureFileDownloadedAfterDownloadFile(
105 const base::FilePath& drive_file_path,
106 scoped_ptr<ResourceEntry> entry,
107 const DownloadCallback& callback,
108 google_apis::GDataErrorCode gdata_error,
109 const base::FilePath& downloaded_file_path);
110
111 // Part of EnsureFileDownloaded(). Called after updating local state is
112 // completed.
113 void EnsureFileDownloadedAfterUpdateLocalState(
114 const base::FilePath& file_path,
115 const DownloadCallback& callback,
116 scoped_ptr<ResourceEntry> entry,
117 base::FilePath* cache_file_path,
118 FileError error);
119
120 // Cancels the job with |job_id| in the scheduler.
121 void CancelJob(JobID job_id);
122
123 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
124 OperationObserver* observer_;
125 JobScheduler* scheduler_;
126 internal::ResourceMetadata* metadata_;
127 internal::FileCache* cache_;
128
129 // Note: This should remain the last member so it'll be destroyed and
130 // invalidate its weak pointers before any other members are destroyed.
131 base::WeakPtrFactory<DownloadOperation> weak_ptr_factory_;
132 DISALLOW_COPY_AND_ASSIGN(DownloadOperation);
133 };
134
135 } // namespace file_system
136 } // namespace drive
137
138 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_DOWNLOAD_OPERATION_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/file_system.cc ('k') | chrome/browser/chromeos/drive/file_system/download_operation.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698