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

Side by Side Diff: chrome/browser/chromeos/drive/file_system/remove_operation.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 (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 "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_cache.h" 9 #include "chrome/browser/chromeos/drive/file_cache.h"
10 #include "chrome/browser/chromeos/drive/file_change.h"
10 #include "chrome/browser/chromeos/drive/file_system/operation_observer.h" 11 #include "chrome/browser/chromeos/drive/file_system/operation_observer.h"
11 #include "chrome/browser/chromeos/drive/file_system_util.h" 12 #include "chrome/browser/chromeos/drive/file_system_util.h"
12 #include "chrome/browser/chromeos/drive/resource_metadata.h" 13 #include "chrome/browser/chromeos/drive/resource_metadata.h"
13 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
14 15
15 using content::BrowserThread; 16 using content::BrowserThread;
16 17
17 namespace drive { 18 namespace drive {
18 namespace file_system { 19 namespace file_system {
19 20
20 namespace { 21 namespace {
21 22
22 // Removes cache file and moves the metadata entry to the trash. 23 // Removes cache file and moves the metadata entry to the trash.
23 FileError UpdateLocalState(internal::ResourceMetadata* metadata, 24 FileError UpdateLocalState(internal::ResourceMetadata* metadata,
24 internal::FileCache* cache, 25 internal::FileCache* cache,
25 const base::FilePath& path, 26 const base::FilePath& path,
26 bool is_recursive, 27 bool is_recursive,
27 std::string* local_id, 28 std::string* local_id,
28 base::FilePath* changed_directory_path) { 29 base::FilePath* changed_path) {
29 FileError error = metadata->GetIdByPath(path, local_id); 30 FileError error = metadata->GetIdByPath(path, local_id);
30 if (error != FILE_ERROR_OK) 31 if (error != FILE_ERROR_OK)
31 return error; 32 return error;
32 33
33 ResourceEntry entry; 34 ResourceEntry entry;
34 error = metadata->GetResourceEntryById(*local_id, &entry); 35 error = metadata->GetResourceEntryById(*local_id, &entry);
35 if (error != FILE_ERROR_OK) 36 if (error != FILE_ERROR_OK)
36 return error; 37 return error;
37 38
38 if (entry.file_info().is_directory() && !is_recursive) { 39 if (entry.file_info().is_directory() && !is_recursive) {
39 // Check emptiness of the directory. 40 // Check emptiness of the directory.
40 ResourceEntryVector entries; 41 ResourceEntryVector entries;
41 error = metadata->ReadDirectoryByPath(path, &entries); 42 error = metadata->ReadDirectoryByPath(path, &entries);
42 if (error != FILE_ERROR_OK) 43 if (error != FILE_ERROR_OK)
43 return error; 44 return error;
44 if (!entries.empty()) 45 if (!entries.empty())
45 return FILE_ERROR_NOT_EMPTY; 46 return FILE_ERROR_NOT_EMPTY;
46 } 47 }
47 48
48 error = cache->Remove(*local_id); 49 error = cache->Remove(*local_id);
49 if (error != FILE_ERROR_OK) 50 if (error != FILE_ERROR_OK)
50 return error; 51 return error;
51 52
52 *changed_directory_path = path.DirName(); 53 *changed_path = path;
53 54
54 // Move to the trash. 55 // Move to the trash.
55 entry.set_parent_local_id(util::kDriveTrashDirLocalId); 56 entry.set_parent_local_id(util::kDriveTrashDirLocalId);
56 return metadata->RefreshEntry(entry); 57 return metadata->RefreshEntry(entry);
57 } 58 }
58 59
59 } // namespace 60 } // namespace
60 61
61 RemoveOperation::RemoveOperation( 62 RemoveOperation::RemoveOperation(
62 base::SequencedTaskRunner* blocking_task_runner, 63 base::SequencedTaskRunner* blocking_task_runner,
(...skipping 12 matching lines...) Expand all
75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
76 } 77 }
77 78
78 void RemoveOperation::Remove(const base::FilePath& path, 79 void RemoveOperation::Remove(const base::FilePath& path,
79 bool is_recursive, 80 bool is_recursive,
80 const FileOperationCallback& callback) { 81 const FileOperationCallback& callback) {
81 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 82 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
82 DCHECK(!callback.is_null()); 83 DCHECK(!callback.is_null());
83 84
84 std::string* local_id = new std::string; 85 std::string* local_id = new std::string;
85 base::FilePath* changed_directory_path = new base::FilePath; 86 base::FilePath* changed_path = new base::FilePath;
86 base::PostTaskAndReplyWithResult( 87 base::PostTaskAndReplyWithResult(
87 blocking_task_runner_.get(), 88 blocking_task_runner_.get(),
88 FROM_HERE, 89 FROM_HERE,
89 base::Bind(&UpdateLocalState, 90 base::Bind(&UpdateLocalState,
90 metadata_, 91 metadata_,
91 cache_, 92 cache_,
92 path, 93 path,
93 is_recursive, 94 is_recursive,
94 local_id, 95 local_id,
95 changed_directory_path), 96 changed_path),
96 base::Bind(&RemoveOperation::RemoveAfterUpdateLocalState, 97 base::Bind(&RemoveOperation::RemoveAfterUpdateLocalState,
97 weak_ptr_factory_.GetWeakPtr(), 98 weak_ptr_factory_.GetWeakPtr(),
98 callback, 99 callback,
99 base::Owned(local_id), 100 base::Owned(local_id),
100 base::Owned(changed_directory_path))); 101 base::Owned(changed_path)));
101 } 102 }
102 103
103 void RemoveOperation::RemoveAfterUpdateLocalState( 104 void RemoveOperation::RemoveAfterUpdateLocalState(
104 const FileOperationCallback& callback, 105 const FileOperationCallback& callback,
105 const std::string* local_id, 106 const std::string* local_id,
106 const base::FilePath* changed_directory_path, 107 const base::FilePath* changed_path,
107 FileError error) { 108 FileError error) {
108 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 109 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
109 DCHECK(!callback.is_null()); 110 DCHECK(!callback.is_null());
110 111
111 if (error == FILE_ERROR_OK) { 112 ResourceEntry entry;
112 observer_->OnDirectoryChangedByOperation(*changed_directory_path); 113 FileError error2 = metadata_->GetResourceEntryById(*local_id, &entry);
kinaba 2014/06/23 05:37:43 this is violating thread restriction (metadata mus
yoshiki 2014/06/24 02:02:22 Done.
113 observer_->OnEntryUpdatedByOperation(*local_id); 114 DCHECK(error2 == FILE_ERROR_OK);
115
116 if (!changed_path->empty()) {
117 FileChange changed_file;
118 changed_file.Update(*changed_path, entry, FileChange::DELETE);
119 if (error == FILE_ERROR_OK) {
120 observer_->OnDirectoryChangedByOperation(changed_file);
121 observer_->OnEntryUpdatedByOperation(*local_id);
122 }
114 } 123 }
115 124
116 callback.Run(error); 125 callback.Run(error);
117 } 126 }
118 127
119 } // namespace file_system 128 } // namespace file_system
120 } // namespace drive 129 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698