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

Side by Side Diff: chrome/browser/chromeos/drive/file_system/remove_operation.cc

Issue 16094003: drive: Respect is_recursive parameter in RemoveOperation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix DriveFileSystemExtensionApiTest Created 7 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/file_system/remove_operation.h" 5 #include "chrome/browser/chromeos/drive/file_system/remove_operation.h"
6 6
7 #include "chrome/browser/chromeos/drive/drive.pb.h" 7 #include "chrome/browser/chromeos/drive/drive.pb.h"
8 #include "chrome/browser/chromeos/drive/file_cache.h" 8 #include "chrome/browser/chromeos/drive/file_cache.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 14 matching lines...) Expand all
25 metadata_(metadata), 25 metadata_(metadata),
26 cache_(cache), 26 cache_(cache),
27 weak_ptr_factory_(this) { 27 weak_ptr_factory_(this) {
28 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 28 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
29 } 29 }
30 30
31 RemoveOperation::~RemoveOperation() { 31 RemoveOperation::~RemoveOperation() {
32 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 32 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
33 } 33 }
34 34
35 void RemoveOperation::Remove(const base::FilePath& file_path, 35 void RemoveOperation::Remove(const base::FilePath& path,
36 bool is_recursive, 36 bool is_recursive,
37 const FileOperationCallback& callback) { 37 const FileOperationCallback& callback) {
38 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 38 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
39 DCHECK(!callback.is_null()); 39 DCHECK(!callback.is_null());
40 40
41 // Get the edit URL of an entry at |file_path|. 41 // Get the edit URL of an entry at |path|.
42 metadata_->GetResourceEntryByPathOnUIThread( 42 metadata_->GetResourceEntryByPathOnUIThread(
43 file_path, 43 path,
44 base::Bind( 44 base::Bind(
45 &RemoveOperation::RemoveAfterGetResourceEntry, 45 &RemoveOperation::RemoveAfterGetResourceEntry,
46 weak_ptr_factory_.GetWeakPtr(), 46 weak_ptr_factory_.GetWeakPtr(),
47 path,
48 is_recursive,
47 callback)); 49 callback));
48 } 50 }
49 51
50 void RemoveOperation::RemoveAfterGetResourceEntry( 52 void RemoveOperation::RemoveAfterGetResourceEntry(
53 const base::FilePath& path,
54 bool is_recursive,
51 const FileOperationCallback& callback, 55 const FileOperationCallback& callback,
52 FileError error, 56 FileError error,
53 scoped_ptr<ResourceEntry> entry) { 57 scoped_ptr<ResourceEntry> entry) {
54 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
55 DCHECK(!callback.is_null()); 59 DCHECK(!callback.is_null());
56 60
57 if (error != FILE_ERROR_OK) { 61 if (error != FILE_ERROR_OK) {
58 callback.Run(error); 62 callback.Run(error);
59 return; 63 return;
60 } 64 }
61 DCHECK(entry); 65
66 if (entry->file_info().is_directory() && !is_recursive) {
67 // Check emptiness of the directory.
68 metadata_->ReadDirectoryByPathOnUIThread(
69 path,
70 base::Bind(&RemoveOperation::RemoveAfterReadDirectory,
71 weak_ptr_factory_.GetWeakPtr(),
72 entry->resource_id(),
73 callback));
74 return;
75 }
62 76
63 scheduler_->DeleteResource( 77 scheduler_->DeleteResource(
64 entry->resource_id(), 78 entry->resource_id(),
65 base::Bind(&RemoveOperation::RemoveResourceLocally, 79 base::Bind(&RemoveOperation::RemoveResourceLocally,
66 weak_ptr_factory_.GetWeakPtr(), 80 weak_ptr_factory_.GetWeakPtr(),
67 callback, 81 callback,
68 entry->resource_id())); 82 entry->resource_id()));
69 } 83 }
70 84
85 void RemoveOperation::RemoveAfterReadDirectory(
86 const std::string& resource_id,
87 const FileOperationCallback& callback,
88 FileError error,
89 scoped_ptr<ResourceEntryVector> entries) {
90 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
91 DCHECK(!callback.is_null());
92
93 if (error != FILE_ERROR_OK) {
94 callback.Run(error);
95 return;
96 }
97
98 if (!entries->empty()) {
99 callback.Run(FILE_ERROR_NOT_EMPTY);
100 return;
101 }
102
103 scheduler_->DeleteResource(
104 resource_id,
105 base::Bind(&RemoveOperation::RemoveResourceLocally,
106 weak_ptr_factory_.GetWeakPtr(),
107 callback,
108 resource_id));
109 }
110
71 void RemoveOperation::RemoveResourceLocally( 111 void RemoveOperation::RemoveResourceLocally(
72 const FileOperationCallback& callback, 112 const FileOperationCallback& callback,
73 const std::string& resource_id, 113 const std::string& resource_id,
74 google_apis::GDataErrorCode status) { 114 google_apis::GDataErrorCode status) {
75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 115 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
76 DCHECK(!callback.is_null()); 116 DCHECK(!callback.is_null());
77 117
78 FileError error = util::GDataToFileError(status); 118 FileError error = util::GDataToFileError(status);
79 if (error != FILE_ERROR_OK) { 119 if (error != FILE_ERROR_OK) {
80 callback.Run(error); 120 callback.Run(error);
(...skipping 18 matching lines...) Expand all
99 DCHECK(!callback.is_null()); 139 DCHECK(!callback.is_null());
100 140
101 if (error == FILE_ERROR_OK) 141 if (error == FILE_ERROR_OK)
102 observer_->OnDirectoryChangedByOperation(directory_path); 142 observer_->OnDirectoryChangedByOperation(directory_path);
103 143
104 callback.Run(error); 144 callback.Run(error);
105 } 145 }
106 146
107 } // namespace file_system 147 } // namespace file_system
108 } // namespace drive 148 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698