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/sync/entry_update_performer.h" | 5 #include "chrome/browser/chromeos/drive/sync/entry_update_performer.h" |
6 | 6 |
7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "chrome/browser/chromeos/drive/change_list_loader.h" | 9 #include "chrome/browser/chromeos/drive/change_list_loader.h" |
10 #include "chrome/browser/chromeos/drive/drive.pb.h" | 10 #include "chrome/browser/chromeos/drive/drive.pb.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 FileError error = metadata->GetResourceEntryById(local_id, | 43 FileError error = metadata->GetResourceEntryById(local_id, |
44 &local_state->entry); | 44 &local_state->entry); |
45 if (error != FILE_ERROR_OK) | 45 if (error != FILE_ERROR_OK) |
46 return error; | 46 return error; |
47 | 47 |
48 error = metadata->GetResourceEntryById(local_state->entry.parent_local_id(), | 48 error = metadata->GetResourceEntryById(local_state->entry.parent_local_id(), |
49 &local_state->parent_entry); | 49 &local_state->parent_entry); |
50 if (error != FILE_ERROR_OK) | 50 if (error != FILE_ERROR_OK) |
51 return error; | 51 return error; |
52 | 52 |
53 local_state->drive_file_path = metadata->GetFilePath(local_id); | 53 error = metadata->GetFilePath(local_id, &local_state->drive_file_path); |
54 if (local_state->drive_file_path.empty()) | 54 if (error != FILE_ERROR_OK) |
55 return FILE_ERROR_NOT_FOUND; | 55 return error; |
56 | 56 |
57 FileCacheEntry cache_entry; | 57 FileCacheEntry cache_entry; |
58 cache->GetCacheEntry(local_id, &cache_entry); | 58 cache->GetCacheEntry(local_id, &cache_entry); |
59 if (!local_state->entry.file_info().is_directory() && | 59 if (!local_state->entry.file_info().is_directory() && |
60 !cache_entry.is_present() && local_state->entry.resource_id().empty()) { | 60 !cache_entry.is_present() && local_state->entry.resource_id().empty()) { |
61 // Locally created file with no cache file, store an empty file. | 61 // Locally created file with no cache file, store an empty file. |
62 base::FilePath empty_file; | 62 base::FilePath empty_file; |
63 if (!base::CreateTemporaryFile(&empty_file)) | 63 if (!base::CreateTemporaryFile(&empty_file)) |
64 return FILE_ERROR_FAILED; | 64 return FILE_ERROR_FAILED; |
65 error = cache->Store(local_id, std::string(), empty_file, | 65 error = cache->Store(local_id, std::string(), empty_file, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 scoped_ptr<google_apis::ResourceEntry> resource_entry, | 116 scoped_ptr<google_apis::ResourceEntry> resource_entry, |
117 base::FilePath* changed_directory) { | 117 base::FilePath* changed_directory) { |
118 // When creating new entries, update check may add a new entry with the same | 118 // When creating new entries, update check may add a new entry with the same |
119 // resource ID before us. If such an entry exists, remove it. | 119 // resource ID before us. If such an entry exists, remove it. |
120 std::string existing_local_id; | 120 std::string existing_local_id; |
121 FileError error = metadata->GetIdByResourceId( | 121 FileError error = metadata->GetIdByResourceId( |
122 resource_entry->resource_id(), &existing_local_id); | 122 resource_entry->resource_id(), &existing_local_id); |
123 switch (error) { | 123 switch (error) { |
124 case FILE_ERROR_OK: | 124 case FILE_ERROR_OK: |
125 if (existing_local_id != local_id) { | 125 if (existing_local_id != local_id) { |
126 base::FilePath existing_entry_path = | 126 base::FilePath existing_entry_path; |
127 metadata->GetFilePath(existing_local_id); | 127 error = metadata->GetFilePath(existing_local_id, &existing_entry_path); |
| 128 if (error != FILE_ERROR_OK) |
| 129 return error; |
128 error = metadata->RemoveEntry(existing_local_id); | 130 error = metadata->RemoveEntry(existing_local_id); |
129 if (error != FILE_ERROR_OK) | 131 if (error != FILE_ERROR_OK) |
130 return error; | 132 return error; |
131 *changed_directory = existing_entry_path.DirName(); | 133 *changed_directory = existing_entry_path.DirName(); |
132 } | 134 } |
133 break; | 135 break; |
134 case FILE_ERROR_NOT_FOUND: | 136 case FILE_ERROR_NOT_FOUND: |
135 break; | 137 break; |
136 default: | 138 default: |
137 return error; | 139 return error; |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 384 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
383 DCHECK(!callback.is_null()); | 385 DCHECK(!callback.is_null()); |
384 | 386 |
385 if (!changed_directory->empty()) | 387 if (!changed_directory->empty()) |
386 observer_->OnDirectoryChangedByOperation(*changed_directory); | 388 observer_->OnDirectoryChangedByOperation(*changed_directory); |
387 callback.Run(error); | 389 callback.Run(error); |
388 } | 390 } |
389 | 391 |
390 } // namespace internal | 392 } // namespace internal |
391 } // namespace drive | 393 } // namespace drive |
OLD | NEW |