OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/create_file_operation.h" | 5 #include "chrome/browser/chromeos/drive/file_system/create_file_operation.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
| 9 #include "base/file_util.h" |
9 #include "chrome/browser/chromeos/drive/drive.pb.h" | 10 #include "chrome/browser/chromeos/drive/drive.pb.h" |
10 #include "chrome/browser/chromeos/drive/file_cache.h" | 11 #include "chrome/browser/chromeos/drive/file_cache.h" |
11 #include "chrome/browser/chromeos/drive/file_system/operation_observer.h" | 12 #include "chrome/browser/chromeos/drive/file_system/operation_observer.h" |
12 #include "chrome/browser/chromeos/drive/file_system_util.h" | 13 #include "chrome/browser/chromeos/drive/file_system_util.h" |
13 #include "chrome/browser/chromeos/drive/job_scheduler.h" | 14 #include "chrome/browser/chromeos/drive/job_scheduler.h" |
14 #include "chrome/browser/chromeos/drive/resource_entry_conversion.h" | 15 #include "chrome/browser/chromeos/drive/resource_entry_conversion.h" |
15 #include "chrome/browser/chromeos/drive/resource_metadata.h" | 16 #include "chrome/browser/chromeos/drive/resource_metadata.h" |
16 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
17 #include "net/base/mime_util.h" | 18 #include "net/base/mime_util.h" |
18 | 19 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 // Depending on timing, the metadata may have inserted via change list feed | 88 // Depending on timing, the metadata may have inserted via change list feed |
88 // already. So, FILE_ERROR_EXISTS is not an error. | 89 // already. So, FILE_ERROR_EXISTS is not an error. |
89 if (error == FILE_ERROR_EXISTS) | 90 if (error == FILE_ERROR_EXISTS) |
90 error = FILE_ERROR_OK; | 91 error = FILE_ERROR_OK; |
91 | 92 |
92 if (error == FILE_ERROR_OK) { | 93 if (error == FILE_ERROR_OK) { |
93 // At this point, upload to the server is fully succeeded. | 94 // At this point, upload to the server is fully succeeded. |
94 // Populate the |file_path| which will be used to notify the observer. | 95 // Populate the |file_path| which will be used to notify the observer. |
95 *file_path = metadata->GetFilePath(entry.resource_id()); | 96 *file_path = metadata->GetFilePath(entry.resource_id()); |
96 | 97 |
97 // Also store the entry to the cache. Here, failure is not a fatal error, | 98 // Also store an empty file to the cache. |
98 // so ignore the returned code. | 99 // Here, failure is not a fatal error, so ignore the returned code. |
99 FileError cache_store_error = cache->Store( | 100 FileError cache_store_error = FILE_ERROR_FAILED; |
100 entry.resource_id(), | 101 base::FilePath empty_file; |
101 entry.file_specific_info().file_md5(), | 102 if (file_util::CreateTemporaryFile(&empty_file)) { |
102 base::FilePath(util::kSymLinkToDevNull), | 103 cache_store_error = cache->Store( |
103 internal::FileCache::FILE_OPERATION_COPY); | 104 entry.resource_id(), |
104 | 105 entry.file_specific_info().file_md5(), |
| 106 empty_file, |
| 107 internal::FileCache::FILE_OPERATION_MOVE); |
| 108 } |
105 DLOG_IF(WARNING, cache_store_error != FILE_ERROR_OK) | 109 DLOG_IF(WARNING, cache_store_error != FILE_ERROR_OK) |
106 << "Failed to store a cache file: " | 110 << "Failed to store a cache file: " |
107 << FileErrorToString(cache_store_error) | 111 << FileErrorToString(cache_store_error) |
108 << ", resource_id: " << entry.resource_id(); | 112 << ", resource_id: " << entry.resource_id(); |
109 } | 113 } |
110 | 114 |
111 return error; | 115 return error; |
112 } | 116 } |
113 | 117 |
114 } // namespace | 118 } // namespace |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 | 220 |
217 // Notify observer if the file creation process is successfully done. | 221 // Notify observer if the file creation process is successfully done. |
218 if (error == FILE_ERROR_OK) | 222 if (error == FILE_ERROR_OK) |
219 observer_->OnDirectoryChangedByOperation(file_path->DirName()); | 223 observer_->OnDirectoryChangedByOperation(file_path->DirName()); |
220 | 224 |
221 callback.Run(error); | 225 callback.Run(error); |
222 } | 226 } |
223 | 227 |
224 } // namespace file_system | 228 } // namespace file_system |
225 } // namespace drive | 229 } // namespace drive |
OLD | NEW |