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

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

Issue 321753002: drive: Stop returning ResourceEntry from JobScheduler (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_system/operation_observer.h" 12 #include "chrome/browser/chromeos/drive/file_system/operation_observer.h"
13 #include "chrome/browser/chromeos/drive/file_system_util.h" 13 #include "chrome/browser/chromeos/drive/file_system_util.h"
14 #include "chrome/browser/chromeos/drive/job_scheduler.h" 14 #include "chrome/browser/chromeos/drive/job_scheduler.h"
15 #include "chrome/browser/chromeos/drive/resource_metadata.h" 15 #include "chrome/browser/chromeos/drive/resource_metadata.h"
16 #include "chrome/browser/chromeos/drive/sync/entry_revert_performer.h" 16 #include "chrome/browser/chromeos/drive/sync/entry_revert_performer.h"
17 #include "chrome/browser/chromeos/drive/sync/remove_performer.h" 17 #include "chrome/browser/chromeos/drive/sync/remove_performer.h"
18 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
19 #include "google_apis/drive/drive_api_parser.h"
19 #include "google_apis/drive/gdata_wapi_parser.h" 20 #include "google_apis/drive/gdata_wapi_parser.h"
20 21
21 using content::BrowserThread; 22 using content::BrowserThread;
22 23
23 namespace drive { 24 namespace drive {
24 namespace internal { 25 namespace internal {
25 26
26 struct EntryUpdatePerformer::LocalState { 27 struct EntryUpdatePerformer::LocalState {
27 LocalState() : should_content_update(false) { 28 LocalState() : should_content_update(false) {
28 } 29 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 if (error != FILE_ERROR_OK) 111 if (error != FILE_ERROR_OK)
111 return error; 112 return error;
112 break; 113 break;
113 } 114 }
114 return FILE_ERROR_OK; 115 return FILE_ERROR_OK;
115 } 116 }
116 117
117 FileError FinishUpdate(ResourceMetadata* metadata, 118 FileError FinishUpdate(ResourceMetadata* metadata,
118 FileCache* cache, 119 FileCache* cache,
119 const std::string& local_id, 120 const std::string& local_id,
120 scoped_ptr<google_apis::ResourceEntry> resource_entry, 121 scoped_ptr<google_apis::FileResource> file_resource,
121 base::FilePath* changed_directory) { 122 base::FilePath* changed_directory) {
122 // When creating new entries, update check may add a new entry with the same 123 // When creating new entries, update check may add a new entry with the same
123 // resource ID before us. If such an entry exists, remove it. 124 // resource ID before us. If such an entry exists, remove it.
124 std::string existing_local_id; 125 std::string existing_local_id;
125 FileError error = metadata->GetIdByResourceId( 126 FileError error = metadata->GetIdByResourceId(
126 resource_entry->resource_id(), &existing_local_id); 127 file_resource->file_id(), &existing_local_id);
127 switch (error) { 128 switch (error) {
128 case FILE_ERROR_OK: 129 case FILE_ERROR_OK:
129 if (existing_local_id != local_id) { 130 if (existing_local_id != local_id) {
130 base::FilePath existing_entry_path; 131 base::FilePath existing_entry_path;
131 error = metadata->GetFilePath(existing_local_id, &existing_entry_path); 132 error = metadata->GetFilePath(existing_local_id, &existing_entry_path);
132 if (error != FILE_ERROR_OK) 133 if (error != FILE_ERROR_OK)
133 return error; 134 return error;
134 error = metadata->RemoveEntry(existing_local_id); 135 error = metadata->RemoveEntry(existing_local_id);
135 if (error != FILE_ERROR_OK) 136 if (error != FILE_ERROR_OK)
136 return error; 137 return error;
(...skipping 15 matching lines...) Expand all
152 switch (entry.metadata_edit_state()) { 153 switch (entry.metadata_edit_state()) {
153 case ResourceEntry::CLEAN: // Nothing to do. 154 case ResourceEntry::CLEAN: // Nothing to do.
154 case ResourceEntry::DIRTY: // Entry was edited again during the update. 155 case ResourceEntry::DIRTY: // Entry was edited again during the update.
155 break; 156 break;
156 157
157 case ResourceEntry::SYNCING: 158 case ResourceEntry::SYNCING:
158 entry.set_metadata_edit_state(ResourceEntry::CLEAN); 159 entry.set_metadata_edit_state(ResourceEntry::CLEAN);
159 break; 160 break;
160 } 161 }
161 if (!entry.file_info().is_directory()) 162 if (!entry.file_info().is_directory())
162 entry.mutable_file_specific_info()->set_md5(resource_entry->file_md5()); 163 entry.mutable_file_specific_info()->set_md5(file_resource->md5_checksum());
163 entry.set_resource_id(resource_entry->resource_id()); 164 entry.set_resource_id(file_resource->file_id());
164 error = metadata->RefreshEntry(entry); 165 error = metadata->RefreshEntry(entry);
165 if (error != FILE_ERROR_OK) 166 if (error != FILE_ERROR_OK)
166 return error; 167 return error;
167 168
168 // Clear dirty bit unless the file has been edited during update. 169 // Clear dirty bit unless the file has been edited during update.
169 if (entry.file_specific_info().cache_state().is_dirty() && 170 if (entry.file_specific_info().cache_state().is_dirty() &&
170 entry.file_specific_info().cache_state().md5() == 171 entry.file_specific_info().cache_state().md5() ==
171 entry.file_specific_info().md5()) { 172 entry.file_specific_info().md5()) {
172 error = cache->ClearDirty(local_id); 173 error = cache->ClearDirty(local_id);
173 if (error != FILE_ERROR_OK) 174 if (error != FILE_ERROR_OK)
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 context, callback, local_state->entry.local_id(), 346 context, callback, local_state->entry.local_id(),
346 base::Passed(scoped_ptr<base::ScopedClosureRunner>()))); 347 base::Passed(scoped_ptr<base::ScopedClosureRunner>())));
347 } 348 }
348 349
349 void EntryUpdatePerformer::UpdateEntryAfterUpdateResource( 350 void EntryUpdatePerformer::UpdateEntryAfterUpdateResource(
350 const ClientContext& context, 351 const ClientContext& context,
351 const FileOperationCallback& callback, 352 const FileOperationCallback& callback,
352 const std::string& local_id, 353 const std::string& local_id,
353 scoped_ptr<base::ScopedClosureRunner> loader_lock, 354 scoped_ptr<base::ScopedClosureRunner> loader_lock,
354 google_apis::GDataErrorCode status, 355 google_apis::GDataErrorCode status,
355 scoped_ptr<google_apis::ResourceEntry> resource_entry) { 356 scoped_ptr<google_apis::FileResource> entry) {
356 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 357 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
357 DCHECK(!callback.is_null()); 358 DCHECK(!callback.is_null());
358 359
359 if (status == google_apis::HTTP_FORBIDDEN) { 360 if (status == google_apis::HTTP_FORBIDDEN) {
360 // Editing this entry is not allowed, revert local changes. 361 // Editing this entry is not allowed, revert local changes.
361 entry_revert_performer_->RevertEntry(local_id, context, callback); 362 entry_revert_performer_->RevertEntry(local_id, context, callback);
362 return; 363 return;
363 } 364 }
364 365
365 FileError error = GDataToFileError(status); 366 FileError error = GDataToFileError(status);
366 if (error != FILE_ERROR_OK) { 367 if (error != FILE_ERROR_OK) {
367 callback.Run(error); 368 callback.Run(error);
368 return; 369 return;
369 } 370 }
370 371
371 base::FilePath* changed_directory = new base::FilePath; 372 base::FilePath* changed_directory = new base::FilePath;
372 base::PostTaskAndReplyWithResult( 373 base::PostTaskAndReplyWithResult(
373 blocking_task_runner_.get(), 374 blocking_task_runner_.get(),
374 FROM_HERE, 375 FROM_HERE,
375 base::Bind(&FinishUpdate, 376 base::Bind(&FinishUpdate,
376 metadata_, cache_, local_id, base::Passed(&resource_entry), 377 metadata_, cache_, local_id, base::Passed(&entry),
377 changed_directory), 378 changed_directory),
378 base::Bind(&EntryUpdatePerformer::UpdateEntryAfterFinish, 379 base::Bind(&EntryUpdatePerformer::UpdateEntryAfterFinish,
379 weak_ptr_factory_.GetWeakPtr(), callback, 380 weak_ptr_factory_.GetWeakPtr(), callback,
380 base::Owned(changed_directory))); 381 base::Owned(changed_directory)));
381 } 382 }
382 383
383 void EntryUpdatePerformer::UpdateEntryAfterFinish( 384 void EntryUpdatePerformer::UpdateEntryAfterFinish(
384 const FileOperationCallback& callback, 385 const FileOperationCallback& callback,
385 const base::FilePath* changed_directory, 386 const base::FilePath* changed_directory,
386 FileError error) { 387 FileError error) {
387 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 388 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
388 DCHECK(!callback.is_null()); 389 DCHECK(!callback.is_null());
389 390
390 if (!changed_directory->empty()) 391 if (!changed_directory->empty())
391 observer_->OnDirectoryChangedByOperation(*changed_directory); 392 observer_->OnDirectoryChangedByOperation(*changed_directory);
392 callback.Run(error); 393 callback.Run(error);
393 } 394 }
394 395
395 } // namespace internal 396 } // namespace internal
396 } // namespace drive 397 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/sync/entry_update_performer.h ('k') | chrome/browser/chromeos/drive/sync/remove_performer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698