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

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: rebase Created 6 years, 5 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) {
124 ResourceEntry entry;
125 FileError error = metadata->GetResourceEntryById(local_id, &entry);
126 if (error != FILE_ERROR_OK)
127 return error;
128
123 // When creating new entries, update check may add a new entry with the same 129 // 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. 130 // resource ID before us. If such an entry exists, remove it.
125 std::string existing_local_id; 131 std::string existing_local_id;
126 FileError error = metadata->GetIdByResourceId( 132 error =
127 file_resource->file_id(), &existing_local_id); 133 metadata->GetIdByResourceId(file_resource->file_id(), &existing_local_id);
134
128 switch (error) { 135 switch (error) {
129 case FILE_ERROR_OK: 136 case FILE_ERROR_OK:
130 if (existing_local_id != local_id) { 137 if (existing_local_id != local_id) {
131 base::FilePath existing_entry_path; 138 base::FilePath existing_entry_path;
132 error = metadata->GetFilePath(existing_local_id, &existing_entry_path); 139 error = metadata->GetFilePath(existing_local_id, &existing_entry_path);
133 if (error != FILE_ERROR_OK) 140 if (error != FILE_ERROR_OK)
134 return error; 141 return error;
135 error = metadata->RemoveEntry(existing_local_id); 142 error = metadata->RemoveEntry(existing_local_id);
136 if (error != FILE_ERROR_OK) 143 if (error != FILE_ERROR_OK)
137 return error; 144 return error;
138 *changed_directory = existing_entry_path.DirName(); 145 changed_files->Update(existing_entry_path, entry, FileChange::DELETE);
139 } 146 }
140 break; 147 break;
141 case FILE_ERROR_NOT_FOUND: 148 case FILE_ERROR_NOT_FOUND:
142 break; 149 break;
143 default: 150 default:
144 return error; 151 return error;
145 } 152 }
146 153
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. 154 // Update metadata_edit_state and MD5.
153 switch (entry.metadata_edit_state()) { 155 switch (entry.metadata_edit_state()) {
154 case ResourceEntry::CLEAN: // Nothing to do. 156 case ResourceEntry::CLEAN: // Nothing to do.
155 case ResourceEntry::DIRTY: // Entry was edited again during the update. 157 case ResourceEntry::DIRTY: // Entry was edited again during the update.
156 break; 158 break;
157 159
158 case ResourceEntry::SYNCING: 160 case ResourceEntry::SYNCING:
159 entry.set_metadata_edit_state(ResourceEntry::CLEAN); 161 entry.set_metadata_edit_state(ResourceEntry::CLEAN);
160 break; 162 break;
161 } 163 }
162 if (!entry.file_info().is_directory()) 164 if (!entry.file_info().is_directory())
163 entry.mutable_file_specific_info()->set_md5(file_resource->md5_checksum()); 165 entry.mutable_file_specific_info()->set_md5(file_resource->md5_checksum());
164 entry.set_resource_id(file_resource->file_id()); 166 entry.set_resource_id(file_resource->file_id());
165 error = metadata->RefreshEntry(entry); 167 error = metadata->RefreshEntry(entry);
166 if (error != FILE_ERROR_OK) 168 if (error != FILE_ERROR_OK)
167 return error; 169 return error;
170 base::FilePath entry_path;
171 error = metadata->GetFilePath(local_id, &entry_path);
172 if (error != FILE_ERROR_OK)
173 return error;
174 changed_files->Update(entry_path, entry, FileChange::ADD_OR_UPDATE);
168 175
169 // Clear dirty bit unless the file has been edited during update. 176 // Clear dirty bit unless the file has been edited during update.
170 if (entry.file_specific_info().cache_state().is_dirty() && 177 if (entry.file_specific_info().cache_state().is_dirty() &&
171 entry.file_specific_info().cache_state().md5() == 178 entry.file_specific_info().cache_state().md5() ==
172 entry.file_specific_info().md5()) { 179 entry.file_specific_info().md5()) {
173 error = cache->ClearDirty(local_id); 180 error = cache->ClearDirty(local_id);
174 if (error != FILE_ERROR_OK) 181 if (error != FILE_ERROR_OK)
175 return error; 182 return error;
176 } 183 }
177 return FILE_ERROR_OK; 184 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); 369 entry_revert_performer_->RevertEntry(local_id, context, callback);
363 return; 370 return;
364 } 371 }
365 372
366 FileError error = GDataToFileError(status); 373 FileError error = GDataToFileError(status);
367 if (error != FILE_ERROR_OK) { 374 if (error != FILE_ERROR_OK) {
368 callback.Run(error); 375 callback.Run(error);
369 return; 376 return;
370 } 377 }
371 378
372 base::FilePath* changed_directory = new base::FilePath; 379 FileChange* changed_files = new FileChange;
373 base::PostTaskAndReplyWithResult( 380 base::PostTaskAndReplyWithResult(
374 blocking_task_runner_.get(), 381 blocking_task_runner_.get(),
375 FROM_HERE, 382 FROM_HERE,
376 base::Bind(&FinishUpdate, 383 base::Bind(&FinishUpdate,
377 metadata_, cache_, local_id, base::Passed(&entry), 384 metadata_,
378 changed_directory), 385 cache_,
386 local_id,
387 base::Passed(&entry),
388 changed_files),
379 base::Bind(&EntryUpdatePerformer::UpdateEntryAfterFinish, 389 base::Bind(&EntryUpdatePerformer::UpdateEntryAfterFinish,
380 weak_ptr_factory_.GetWeakPtr(), callback, 390 weak_ptr_factory_.GetWeakPtr(),
381 base::Owned(changed_directory))); 391 callback,
392 base::Owned(changed_files)));
382 } 393 }
383 394
384 void EntryUpdatePerformer::UpdateEntryAfterFinish( 395 void EntryUpdatePerformer::UpdateEntryAfterFinish(
385 const FileOperationCallback& callback, 396 const FileOperationCallback& callback,
386 const base::FilePath* changed_directory, 397 const FileChange* changed_files,
387 FileError error) { 398 FileError error) {
388 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 399 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
389 DCHECK(!callback.is_null()); 400 DCHECK(!callback.is_null());
390 401
391 if (!changed_directory->empty()) 402 observer_->OnFileChangedByOperation(*changed_files);
392 observer_->OnDirectoryChangedByOperation(*changed_directory);
393 callback.Run(error); 403 callback.Run(error);
394 } 404 }
395 405
396 } // namespace internal 406 } // namespace internal
397 } // namespace drive 407 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/sync/entry_update_performer.h ('k') | chrome/browser/chromeos/drive/sync_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698