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

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

Issue 343073003: Files.app: Provide detailed change information on onDirectoryChanged event (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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"
11 #include "chrome/browser/chromeos/drive/file_cache.h" 11 #include "chrome/browser/chromeos/drive/file_cache.h"
12 #include "chrome/browser/chromeos/drive/file_change.h"
12 #include "chrome/browser/chromeos/drive/file_system/operation_observer.h" 13 #include "chrome/browser/chromeos/drive/file_system/operation_observer.h"
13 #include "chrome/browser/chromeos/drive/file_system_util.h" 14 #include "chrome/browser/chromeos/drive/file_system_util.h"
14 #include "chrome/browser/chromeos/drive/job_scheduler.h" 15 #include "chrome/browser/chromeos/drive/job_scheduler.h"
15 #include "chrome/browser/chromeos/drive/resource_metadata.h" 16 #include "chrome/browser/chromeos/drive/resource_metadata.h"
16 #include "chrome/browser/chromeos/drive/sync/entry_revert_performer.h" 17 #include "chrome/browser/chromeos/drive/sync/entry_revert_performer.h"
17 #include "chrome/browser/chromeos/drive/sync/remove_performer.h" 18 #include "chrome/browser/chromeos/drive/sync/remove_performer.h"
18 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
19 #include "google_apis/drive/drive_api_parser.h" 20 #include "google_apis/drive/drive_api_parser.h"
20 #include "google_apis/drive/gdata_wapi_parser.h" 21 #include "google_apis/drive/gdata_wapi_parser.h"
21 22
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 return error; 113 return error;
113 break; 114 break;
114 } 115 }
115 return FILE_ERROR_OK; 116 return FILE_ERROR_OK;
116 } 117 }
117 118
118 FileError FinishUpdate(ResourceMetadata* metadata, 119 FileError FinishUpdate(ResourceMetadata* metadata,
119 FileCache* cache, 120 FileCache* cache,
120 const std::string& local_id, 121 const std::string& local_id,
121 scoped_ptr<google_apis::FileResource> file_resource, 122 scoped_ptr<google_apis::FileResource> file_resource,
122 base::FilePath* changed_directory) { 123 FileChange* changed_files) {
123 // When creating new entries, update check may add a new entry with the same 124 // When creating new entries, update check may add a new entry with the same
124 // resource ID before us. If such an entry exists, remove it. 125 // resource ID before us. If such an entry exists, remove it.
125 std::string existing_local_id; 126 std::string existing_local_id;
126 FileError error = metadata->GetIdByResourceId( 127 FileError error = metadata->GetIdByResourceId(
127 file_resource->file_id(), &existing_local_id); 128 file_resource->file_id(), &existing_local_id);
kinaba 2014/06/23 05:37:43 The |error| value for this call must be checked in
yoshiki 2014/06/24 02:02:22 Done.
129 ResourceEntry entry;
130 error = metadata->GetResourceEntryById(local_id, &entry);
131 if (error != FILE_ERROR_OK)
132 return error;
133
128 switch (error) { 134 switch (error) {
129 case FILE_ERROR_OK: 135 case FILE_ERROR_OK:
130 if (existing_local_id != local_id) { 136 if (existing_local_id != local_id && !existing_local_id.empty()) {
kinaba 2014/06/23 05:37:43 and if the above |error| is properly checked, exis
yoshiki 2014/06/24 02:02:22 Done.
131 base::FilePath existing_entry_path; 137 base::FilePath existing_entry_path;
132 error = metadata->GetFilePath(existing_local_id, &existing_entry_path); 138 error = metadata->GetFilePath(existing_local_id, &existing_entry_path);
133 if (error != FILE_ERROR_OK) 139 if (error != FILE_ERROR_OK)
134 return error; 140 return error;
135 error = metadata->RemoveEntry(existing_local_id); 141 error = metadata->RemoveEntry(existing_local_id);
136 if (error != FILE_ERROR_OK) 142 if (error != FILE_ERROR_OK)
137 return error; 143 return error;
138 *changed_directory = existing_entry_path.DirName(); 144 changed_files->Update(existing_entry_path, entry, FileChange::DELETE);
139 } 145 }
140 break; 146 break;
141 case FILE_ERROR_NOT_FOUND: 147 case FILE_ERROR_NOT_FOUND:
142 break; 148 break;
143 default: 149 default:
144 return error; 150 return error;
145 } 151 }
146 152
147 ResourceEntry entry;
148 error = metadata->GetResourceEntryById(local_id, &entry);
149 if (error != FILE_ERROR_OK)
150 return error;
151
152 // Update metadata_edit_state and MD5. 153 // Update metadata_edit_state and MD5.
153 switch (entry.metadata_edit_state()) { 154 switch (entry.metadata_edit_state()) {
154 case ResourceEntry::CLEAN: // Nothing to do. 155 case ResourceEntry::CLEAN: // Nothing to do.
155 case ResourceEntry::DIRTY: // Entry was edited again during the update. 156 case ResourceEntry::DIRTY: // Entry was edited again during the update.
156 break; 157 break;
157 158
158 case ResourceEntry::SYNCING: 159 case ResourceEntry::SYNCING:
159 entry.set_metadata_edit_state(ResourceEntry::CLEAN); 160 entry.set_metadata_edit_state(ResourceEntry::CLEAN);
160 break; 161 break;
161 } 162 }
162 if (!entry.file_info().is_directory()) 163 if (!entry.file_info().is_directory())
163 entry.mutable_file_specific_info()->set_md5(file_resource->md5_checksum()); 164 entry.mutable_file_specific_info()->set_md5(file_resource->md5_checksum());
164 entry.set_resource_id(file_resource->file_id()); 165 entry.set_resource_id(file_resource->file_id());
165 error = metadata->RefreshEntry(entry); 166 error = metadata->RefreshEntry(entry);
166 if (error != FILE_ERROR_OK) 167 if (error != FILE_ERROR_OK)
167 return error; 168 return error;
169 base::FilePath entry_path;
170 error = metadata->GetFilePath(local_id, &entry_path);
171 if (error != FILE_ERROR_OK)
172 return error;
173 changed_files->Update(entry_path, entry, FileChange::ADD_OR_UPDATE);
168 174
169 // Clear dirty bit unless the file has been edited during update. 175 // Clear dirty bit unless the file has been edited during update.
170 if (entry.file_specific_info().cache_state().is_dirty() && 176 if (entry.file_specific_info().cache_state().is_dirty() &&
171 entry.file_specific_info().cache_state().md5() == 177 entry.file_specific_info().cache_state().md5() ==
172 entry.file_specific_info().md5()) { 178 entry.file_specific_info().md5()) {
173 error = cache->ClearDirty(local_id); 179 error = cache->ClearDirty(local_id);
174 if (error != FILE_ERROR_OK) 180 if (error != FILE_ERROR_OK)
175 return error; 181 return error;
176 } 182 }
177 return FILE_ERROR_OK; 183 return FILE_ERROR_OK;
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 entry_revert_performer_->RevertEntry(local_id, context, callback); 368 entry_revert_performer_->RevertEntry(local_id, context, callback);
363 return; 369 return;
364 } 370 }
365 371
366 FileError error = GDataToFileError(status); 372 FileError error = GDataToFileError(status);
367 if (error != FILE_ERROR_OK) { 373 if (error != FILE_ERROR_OK) {
368 callback.Run(error); 374 callback.Run(error);
369 return; 375 return;
370 } 376 }
371 377
372 base::FilePath* changed_directory = new base::FilePath; 378 FileChange* changed_files = new FileChange;
373 base::PostTaskAndReplyWithResult( 379 base::PostTaskAndReplyWithResult(
374 blocking_task_runner_.get(), 380 blocking_task_runner_.get(),
375 FROM_HERE, 381 FROM_HERE,
376 base::Bind(&FinishUpdate, 382 base::Bind(&FinishUpdate,
377 metadata_, cache_, local_id, base::Passed(&entry), 383 metadata_,
378 changed_directory), 384 cache_,
385 local_id,
386 base::Passed(&entry),
387 changed_files),
379 base::Bind(&EntryUpdatePerformer::UpdateEntryAfterFinish, 388 base::Bind(&EntryUpdatePerformer::UpdateEntryAfterFinish,
380 weak_ptr_factory_.GetWeakPtr(), callback, 389 weak_ptr_factory_.GetWeakPtr(),
381 base::Owned(changed_directory))); 390 callback,
391 base::Owned(changed_files)));
382 } 392 }
383 393
384 void EntryUpdatePerformer::UpdateEntryAfterFinish( 394 void EntryUpdatePerformer::UpdateEntryAfterFinish(
385 const FileOperationCallback& callback, 395 const FileOperationCallback& callback,
386 const base::FilePath* changed_directory, 396 const FileChange* changed_files,
387 FileError error) { 397 FileError error) {
388 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 398 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
389 DCHECK(!callback.is_null()); 399 DCHECK(!callback.is_null());
390 400
391 if (!changed_directory->empty()) 401 observer_->OnDirectoryChangedByOperation(*changed_files);
392 observer_->OnDirectoryChangedByOperation(*changed_directory);
393 callback.Run(error); 402 callback.Run(error);
394 } 403 }
395 404
396 } // namespace internal 405 } // namespace internal
397 } // namespace drive 406 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698