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

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

Issue 148283003: drive: Make sync performers aware of locally created files (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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/remove_performer.h" 5 #include "chrome/browser/chromeos/drive/sync/remove_performer.h"
6 6
7 #include "base/sequenced_task_runner.h" 7 #include "base/sequenced_task_runner.h"
8 #include "chrome/browser/chromeos/drive/drive.pb.h" 8 #include "chrome/browser/chromeos/drive/drive.pb.h"
9 #include "chrome/browser/chromeos/drive/file_system/operation_observer.h" 9 #include "chrome/browser/chromeos/drive/file_system/operation_observer.h"
10 #include "chrome/browser/chromeos/drive/file_system_util.h" 10 #include "chrome/browser/chromeos/drive/file_system_util.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 scheduler, 60 scheduler,
61 metadata)), 61 metadata)),
62 weak_ptr_factory_(this) { 62 weak_ptr_factory_(this) {
63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
64 } 64 }
65 65
66 RemovePerformer::~RemovePerformer() { 66 RemovePerformer::~RemovePerformer() {
67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
68 } 68 }
69 69
70 // Returns |entry| corresponding to |local_id|.
71 // Adding to that, removes the entry when it does not exist on the server.
72 FileError TryToRemoveLocally(ResourceMetadata* metadata,
73 const std::string& local_id,
74 ResourceEntry* entry) {
75 FileError error = metadata->GetResourceEntryById(local_id, entry);
76 if (error != FILE_ERROR_OK || !entry->resource_id().empty())
77 return error;
78 return metadata->RemoveEntry(local_id);
79 }
80
70 void RemovePerformer::Remove(const std::string& local_id, 81 void RemovePerformer::Remove(const std::string& local_id,
71 const ClientContext& context, 82 const ClientContext& context,
72 const FileOperationCallback& callback) { 83 const FileOperationCallback& callback) {
73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 84 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
74 DCHECK(!callback.is_null()); 85 DCHECK(!callback.is_null());
75 86
76 ResourceEntry* entry = new ResourceEntry; 87 ResourceEntry* entry = new ResourceEntry;
77 base::PostTaskAndReplyWithResult( 88 base::PostTaskAndReplyWithResult(
78 blocking_task_runner_.get(), 89 blocking_task_runner_.get(),
79 FROM_HERE, 90 FROM_HERE,
80 base::Bind(&ResourceMetadata::GetResourceEntryById, 91 base::Bind(&TryToRemoveLocally, metadata_, local_id, entry),
81 base::Unretained(metadata_),
82 local_id,
83 entry),
84 base::Bind(&RemovePerformer::RemoveAfterGetResourceEntry, 92 base::Bind(&RemovePerformer::RemoveAfterGetResourceEntry,
85 weak_ptr_factory_.GetWeakPtr(), 93 weak_ptr_factory_.GetWeakPtr(),
86 context, 94 context,
87 callback, 95 callback,
88 base::Owned(entry))); 96 base::Owned(entry)));
89 } 97 }
90 98
91 void RemovePerformer::RemoveAfterGetResourceEntry( 99 void RemovePerformer::RemoveAfterGetResourceEntry(
92 const ClientContext& context, 100 const ClientContext& context,
93 const FileOperationCallback& callback, 101 const FileOperationCallback& callback,
94 const ResourceEntry* entry, 102 const ResourceEntry* entry,
95 FileError error) { 103 FileError error) {
96 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 104 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
97 DCHECK(!callback.is_null()); 105 DCHECK(!callback.is_null());
98 106
99 if (error != FILE_ERROR_OK) { 107 if (error != FILE_ERROR_OK || entry->resource_id().empty()) {
100 callback.Run(error); 108 callback.Run(error);
101 return; 109 return;
102 } 110 }
103 111
104 // To match with the behavior of drive.google.com: 112 // To match with the behavior of drive.google.com:
105 // Removal of shared entries under MyDrive is just removing from the parent. 113 // Removal of shared entries under MyDrive is just removing from the parent.
106 // The entry will stay in shared-with-me (in other words, in "drive/other".) 114 // The entry will stay in shared-with-me (in other words, in "drive/other".)
107 // 115 //
108 // TODO(kinaba): to be more precise, we might be better to branch by whether 116 // TODO(kinaba): to be more precise, we might be better to branch by whether
109 // or not the current account is an owner of the file. The code below is 117 // or not the current account is an owner of the file. The code below is
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 246
239 base::PostTaskAndReplyWithResult( 247 base::PostTaskAndReplyWithResult(
240 blocking_task_runner_.get(), 248 blocking_task_runner_.get(),
241 FROM_HERE, 249 FROM_HERE,
242 base::Bind(&UpdateLocalStateAfterUnparent, metadata_, local_id), 250 base::Bind(&UpdateLocalStateAfterUnparent, metadata_, local_id),
243 callback); 251 callback);
244 } 252 }
245 253
246 } // namespace internal 254 } // namespace internal
247 } // namespace drive 255 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698