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

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

Issue 14884015: drive: Remove DriveFileType (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
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/file_system.h" 5 #include "chrome/browser/chromeos/drive/file_system.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/message_loop_proxy.h" 9 #include "base/message_loop_proxy.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 89
90 metadata.largest_changestamp = largest_changestamp; 90 metadata.largest_changestamp = largest_changestamp;
91 callback.Run(metadata); 91 callback.Run(metadata);
92 } 92 }
93 93
94 // Thin adapter to map GetFileCallback to FileOperationCallback. 94 // Thin adapter to map GetFileCallback to FileOperationCallback.
95 void GetFileCallbackToFileOperationCallbackAdapter( 95 void GetFileCallbackToFileOperationCallbackAdapter(
96 const FileOperationCallback& callback, 96 const FileOperationCallback& callback,
97 FileError error, 97 FileError error,
98 const base::FilePath& unused_file_path, 98 const base::FilePath& unused_file_path,
99 const std::string& unused_mime_type, 99 scoped_ptr<ResourceEntry> unused_entry) {
100 DriveFileType unused_file_type) {
101 callback.Run(error); 100 callback.Run(error);
102 } 101 }
103 102
104 // Wraps |callback| and always passes FILE_ERROR_OK when invoked. 103 // Wraps |callback| and always passes FILE_ERROR_OK when invoked.
105 // This is used for adopting |callback| to wait for a non-fatal operation. 104 // This is used for adopting |callback| to wait for a non-fatal operation.
106 void IgnoreError(const FileOperationCallback& callback, FileError error) { 105 void IgnoreError(const FileOperationCallback& callback, FileError error) {
107 callback.Run(FILE_ERROR_OK); 106 callback.Run(FILE_ERROR_OK);
108 } 107 }
109 108
110 // Creates a file with unique name in |dir| and stores the path to |temp_file|. 109 // Creates a file with unique name in |dir| and stores the path to |temp_file|.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 context(context), 159 context(context),
161 entry(entry.Pass()), 160 entry(entry.Pass()),
162 initialized_callback(initialized_callback), 161 initialized_callback(initialized_callback),
163 get_file_callback(get_file_callback), 162 get_file_callback(get_file_callback),
164 get_content_callback(get_content_callback) { 163 get_content_callback(get_content_callback) {
165 DCHECK(!get_file_callback.is_null()); 164 DCHECK(!get_file_callback.is_null());
166 DCHECK(this->entry); 165 DCHECK(this->entry);
167 } 166 }
168 167
169 void OnError(FileError error) { 168 void OnError(FileError error) {
170 get_file_callback.Run( 169 get_file_callback.Run(error, base::FilePath(), scoped_ptr<ResourceEntry>());
171 error, base::FilePath(), std::string(), REGULAR_FILE);
172 } 170 }
173 171
174 void OnCacheFileFound(const base::FilePath& local_file_path) { 172 void OnCacheFileFound(const base::FilePath& local_file_path) {
175 if (initialized_callback.is_null()) { 173 if (initialized_callback.is_null()) {
176 return; 174 return;
177 } 175 }
178 176
179 scoped_ptr<ResourceEntry> new_entry(new ResourceEntry(*entry)); 177 scoped_ptr<ResourceEntry> new_entry(new ResourceEntry(*entry));
180 initialized_callback.Run(FILE_ERROR_OK, 178 initialized_callback.Run(FILE_ERROR_OK,
181 new_entry.Pass(), 179 new_entry.Pass(),
182 local_file_path, 180 local_file_path,
183 base::Closure()); 181 base::Closure());
184 } 182 }
185 183
186 void OnStartDownloading(const base::Closure& cancel_download_closure) { 184 void OnStartDownloading(const base::Closure& cancel_download_closure) {
187 if (initialized_callback.is_null()) { 185 if (initialized_callback.is_null()) {
188 return; 186 return;
189 } 187 }
190 188
191 scoped_ptr<ResourceEntry> new_entry(new ResourceEntry(*entry)); 189 scoped_ptr<ResourceEntry> new_entry(new ResourceEntry(*entry));
192 initialized_callback.Run(FILE_ERROR_OK, 190 initialized_callback.Run(FILE_ERROR_OK,
193 new_entry.Pass(), 191 new_entry.Pass(),
194 base::FilePath(), 192 base::FilePath(),
195 cancel_download_closure); 193 cancel_download_closure);
196 } 194 }
197 195
198 void OnComplete(const base::FilePath& local_file_path) { 196 void OnComplete(const base::FilePath& local_file_path) {
199 if (entry->file_specific_info().is_hosted_document()) { 197 get_file_callback.Run(FILE_ERROR_OK, local_file_path,
200 get_file_callback.Run( 198 scoped_ptr<ResourceEntry>(new ResourceEntry(*entry)));
201 FILE_ERROR_OK, local_file_path, kMimeTypeJson, HOSTED_DOCUMENT);
202 } else {
203 get_file_callback.Run(
204 FILE_ERROR_OK, local_file_path,
205 entry->file_specific_info().content_mime_type(), REGULAR_FILE);
206 }
207 } 199 }
208 200
209 const base::FilePath drive_file_path; 201 const base::FilePath drive_file_path;
210 const DriveClientContext context; 202 const DriveClientContext context;
211 scoped_ptr<ResourceEntry> entry; 203 scoped_ptr<ResourceEntry> entry;
212 const GetFileContentInitializedCallback initialized_callback; 204 const GetFileContentInitializedCallback initialized_callback;
213 const GetFileCallback get_file_callback; 205 const GetFileCallback get_file_callback;
214 const google_apis::GetContentCallback get_content_callback; 206 const google_apis::GetContentCallback get_content_callback;
215 }; 207 };
216 208
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 530
539 void FileSystem::OnGetEntryInfoCompleteForGetFileByPath( 531 void FileSystem::OnGetEntryInfoCompleteForGetFileByPath(
540 const base::FilePath& file_path, 532 const base::FilePath& file_path,
541 const GetFileCallback& callback, 533 const GetFileCallback& callback,
542 FileError error, 534 FileError error,
543 scoped_ptr<ResourceEntry> entry) { 535 scoped_ptr<ResourceEntry> entry) {
544 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 536 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
545 DCHECK(!callback.is_null()); 537 DCHECK(!callback.is_null());
546 538
547 if (error != FILE_ERROR_OK) { 539 if (error != FILE_ERROR_OK) {
548 callback.Run(error, base::FilePath(), std::string(), REGULAR_FILE); 540 callback.Run(error, base::FilePath(), scoped_ptr<ResourceEntry>());
549 return; 541 return;
550 } 542 }
551 DCHECK(entry); 543 DCHECK(entry);
552 544
553 GetResolvedFileByPath( 545 GetResolvedFileByPath(
554 make_scoped_ptr(new GetResolvedFileParams( 546 make_scoped_ptr(new GetResolvedFileParams(
555 file_path, 547 file_path,
556 DriveClientContext(USER_INITIATED), 548 DriveClientContext(USER_INITIATED),
557 entry.Pass(), 549 entry.Pass(),
558 GetFileContentInitializedCallback(), 550 GetFileContentInitializedCallback(),
(...skipping 23 matching lines...) Expand all
582 const DriveClientContext& context, 574 const DriveClientContext& context,
583 const GetFileCallback& get_file_callback, 575 const GetFileCallback& get_file_callback,
584 const google_apis::GetContentCallback& get_content_callback, 576 const google_apis::GetContentCallback& get_content_callback,
585 FileError error, 577 FileError error,
586 const base::FilePath& file_path, 578 const base::FilePath& file_path,
587 scoped_ptr<ResourceEntry> entry) { 579 scoped_ptr<ResourceEntry> entry) {
588 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 580 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
589 DCHECK(!get_file_callback.is_null()); 581 DCHECK(!get_file_callback.is_null());
590 582
591 if (error != FILE_ERROR_OK) { 583 if (error != FILE_ERROR_OK) {
592 get_file_callback.Run(FILE_ERROR_NOT_FOUND, 584 get_file_callback.Run(FILE_ERROR_NOT_FOUND, base::FilePath(),
593 base::FilePath(), 585 scoped_ptr<ResourceEntry>());
594 std::string(),
595 REGULAR_FILE);
596 return; 586 return;
597 } 587 }
598 588
599 GetResolvedFileByPath( 589 GetResolvedFileByPath(
600 make_scoped_ptr(new GetResolvedFileParams( 590 make_scoped_ptr(new GetResolvedFileParams(
601 file_path, 591 file_path,
602 context, 592 context,
603 entry.Pass(), 593 entry.Pass(),
604 GetFileContentInitializedCallback(), 594 GetFileContentInitializedCallback(),
605 get_file_callback, 595 get_file_callback,
(...skipping 974 matching lines...) Expand 10 before | Expand all | Expand 10 after
1580 callback, 1570 callback,
1581 entry_ptr->resource_id(), 1571 entry_ptr->resource_id(),
1582 entry_ptr->file_specific_info().file_md5())), 1572 entry_ptr->file_specific_info().file_md5())),
1583 google_apis::GetContentCallback()))); 1573 google_apis::GetContentCallback())));
1584 } 1574 }
1585 1575
1586 void FileSystem::OnGetFileCompleteForOpenFile( 1576 void FileSystem::OnGetFileCompleteForOpenFile(
1587 const GetFileCompleteForOpenParams& params, 1577 const GetFileCompleteForOpenParams& params,
1588 FileError error, 1578 FileError error,
1589 const base::FilePath& file_path, 1579 const base::FilePath& file_path,
1590 const std::string& mime_type, 1580 scoped_ptr<ResourceEntry> entry) {
1591 DriveFileType file_type) {
1592 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1581 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1593 DCHECK(!params.callback.is_null()); 1582 DCHECK(!params.callback.is_null());
1594 1583
1595 if (error != FILE_ERROR_OK) { 1584 if (error != FILE_ERROR_OK) {
1596 params.callback.Run(error, base::FilePath()); 1585 params.callback.Run(error, base::FilePath());
1597 return; 1586 return;
1598 } 1587 }
1599 1588
1600 // OpenFile ensures that the file is a regular file. 1589 // OpenFile ensures that the file is a regular file.
1601 DCHECK_EQ(REGULAR_FILE, file_type); 1590 DCHECK(entry && !entry->file_specific_info().is_hosted_document());
1602 1591
1603 cache_->MarkDirty( 1592 cache_->MarkDirty(
1604 params.resource_id, 1593 params.resource_id,
1605 params.md5, 1594 params.md5,
1606 base::Bind(&FileSystem::OnMarkDirtyInCacheCompleteForOpenFile, 1595 base::Bind(&FileSystem::OnMarkDirtyInCacheCompleteForOpenFile,
1607 weak_ptr_factory_.GetWeakPtr(), 1596 weak_ptr_factory_.GetWeakPtr(),
1608 params)); 1597 params));
1609 } 1598 }
1610 1599
1611 void FileSystem::OnMarkDirtyInCacheCompleteForOpenFile( 1600 void FileSystem::OnMarkDirtyInCacheCompleteForOpenFile(
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
1807 util::ConvertPlatformFileInfoToResourceEntry(*file_info, &entry_file_info); 1796 util::ConvertPlatformFileInfoToResourceEntry(*file_info, &entry_file_info);
1808 *entry->mutable_file_info() = entry_file_info; 1797 *entry->mutable_file_info() = entry_file_info;
1809 callback.Run(FILE_ERROR_OK, entry.Pass()); 1798 callback.Run(FILE_ERROR_OK, entry.Pass());
1810 } 1799 }
1811 1800
1812 void FileSystem::CancelJobInScheduler(JobID id) { 1801 void FileSystem::CancelJobInScheduler(JobID id) {
1813 scheduler_->CancelJob(id); 1802 scheduler_->CancelJob(id);
1814 } 1803 }
1815 1804
1816 } // namespace drive 1805 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/file_system.h ('k') | chrome/browser/chromeos/drive/file_system/copy_operation.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698