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

Side by Side Diff: chrome/browser/chromeos/drive/sync/entry_update_performer.cc

Issue 276313002: drive: Change FileCache::GetCacheEntry's return type to FileError (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 local_state->drive_file_path = metadata->GetFilePath(local_id);
54 if (local_state->drive_file_path.empty()) 54 if (local_state->drive_file_path.empty())
55 return FILE_ERROR_NOT_FOUND; 55 return FILE_ERROR_NOT_FOUND;
56 56
57 FileCacheEntry cache_entry; 57 FileCacheEntry cache_entry;
58 cache->GetCacheEntry(local_id, &cache_entry); 58 error = cache->GetCacheEntry(local_id, &cache_entry);
59 if (error != FILE_ERROR_OK && error != FILE_ERROR_NOT_FOUND)
60 return error;
59 if (!local_state->entry.file_info().is_directory() && 61 if (!local_state->entry.file_info().is_directory() &&
60 !cache_entry.is_present() && local_state->entry.resource_id().empty()) { 62 !cache_entry.is_present() && local_state->entry.resource_id().empty()) {
61 // Locally created file with no cache file, store an empty file. 63 // Locally created file with no cache file, store an empty file.
62 base::FilePath empty_file; 64 base::FilePath empty_file;
63 if (!base::CreateTemporaryFile(&empty_file)) 65 if (!base::CreateTemporaryFile(&empty_file))
64 return FILE_ERROR_FAILED; 66 return FILE_ERROR_FAILED;
65 error = cache->Store(local_id, std::string(), empty_file, 67 error = cache->Store(local_id, std::string(), empty_file,
66 FileCache::FILE_OPERATION_MOVE); 68 FileCache::FILE_OPERATION_MOVE);
67 if (error != FILE_ERROR_OK) 69 if (error != FILE_ERROR_OK)
68 return error; 70 return error;
69 if (!cache->GetCacheEntry(local_id, &cache_entry)) 71 error = cache->GetCacheEntry(local_id, &cache_entry);
70 return FILE_ERROR_NOT_FOUND; 72 if (error != FILE_ERROR_OK)
73 return error;
71 } 74 }
72 75
73 // Check if content update is needed or not. 76 // Check if content update is needed or not.
74 if (cache_entry.is_dirty() && !cache->IsOpenedForWrite(local_id)) { 77 if (cache_entry.is_dirty() && !cache->IsOpenedForWrite(local_id)) {
75 // Update cache entry's MD5 if needed. 78 // Update cache entry's MD5 if needed.
76 if (cache_entry.md5().empty()) { 79 if (cache_entry.md5().empty()) {
77 error = cache->UpdateMd5(local_id); 80 error = cache->UpdateMd5(local_id);
78 if (error != FILE_ERROR_OK) 81 if (error != FILE_ERROR_OK)
79 return error; 82 return error;
80 if (!cache->GetCacheEntry(local_id, &cache_entry)) 83 error = cache->GetCacheEntry(local_id, &cache_entry);
81 return FILE_ERROR_NOT_FOUND; 84 if (error != FILE_ERROR_OK)
85 return error;
82 } 86 }
83 87
84 if (cache_entry.md5() == local_state->entry.file_specific_info().md5()) { 88 if (cache_entry.md5() == local_state->entry.file_specific_info().md5()) {
85 error = cache->ClearDirty(local_id); 89 error = cache->ClearDirty(local_id);
86 if (error != FILE_ERROR_OK) 90 if (error != FILE_ERROR_OK)
87 return error; 91 return error;
88 } else { 92 } else {
89 error = cache->GetFile(local_id, &local_state->cache_file_path); 93 error = cache->GetFile(local_id, &local_state->cache_file_path);
90 if (error != FILE_ERROR_OK) 94 if (error != FILE_ERROR_OK)
91 return error; 95 return error;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 } 158 }
155 if (!entry.file_info().is_directory()) 159 if (!entry.file_info().is_directory())
156 entry.mutable_file_specific_info()->set_md5(resource_entry->file_md5()); 160 entry.mutable_file_specific_info()->set_md5(resource_entry->file_md5());
157 entry.set_resource_id(resource_entry->resource_id()); 161 entry.set_resource_id(resource_entry->resource_id());
158 error = metadata->RefreshEntry(entry); 162 error = metadata->RefreshEntry(entry);
159 if (error != FILE_ERROR_OK) 163 if (error != FILE_ERROR_OK)
160 return error; 164 return error;
161 165
162 // Clear dirty bit unless the file has been edited during update. 166 // Clear dirty bit unless the file has been edited during update.
163 FileCacheEntry cache_entry; 167 FileCacheEntry cache_entry;
164 if (cache->GetCacheEntry(local_id, &cache_entry) && 168 error = cache->GetCacheEntry(local_id, &cache_entry);
165 cache_entry.is_dirty() && 169 if (error != FILE_ERROR_OK && error != FILE_ERROR_NOT_FOUND)
170 return error;
171 if (cache_entry.is_dirty() &&
166 cache_entry.md5() == entry.file_specific_info().md5()) { 172 cache_entry.md5() == entry.file_specific_info().md5()) {
167 error = cache->ClearDirty(local_id); 173 error = cache->ClearDirty(local_id);
168 if (error != FILE_ERROR_OK) 174 if (error != FILE_ERROR_OK)
169 return error; 175 return error;
170 } 176 }
171 return FILE_ERROR_OK; 177 return FILE_ERROR_OK;
172 } 178 }
173 179
174 } // namespace 180 } // namespace
175 181
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 388 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
383 DCHECK(!callback.is_null()); 389 DCHECK(!callback.is_null());
384 390
385 if (!changed_directory->empty()) 391 if (!changed_directory->empty())
386 observer_->OnDirectoryChangedByOperation(*changed_directory); 392 observer_->OnDirectoryChangedByOperation(*changed_directory);
387 callback.Run(error); 393 callback.Run(error);
388 } 394 }
389 395
390 } // namespace internal 396 } // namespace internal
391 } // namespace drive 397 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698