OLD | NEW |
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/gdata/gdata_file_system.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_file_system.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 for (GDataDirectoryCollection::const_iterator it = | 147 for (GDataDirectoryCollection::const_iterator it = |
148 dir->child_directories().begin(); | 148 dir->child_directories().begin(); |
149 it != dir->child_directories().end(); ++it) { | 149 it != dir->child_directories().end(); ++it) { |
150 GDataDirectory* child_dir = it->second; | 150 GDataDirectory* child_dir = it->second; |
151 changed_dirs->insert(child_dir->GetFilePath()); | 151 changed_dirs->insert(child_dir->GetFilePath()); |
152 GetChildDirectoryPaths(child_dir, changed_dirs); | 152 GetChildDirectoryPaths(child_dir, changed_dirs); |
153 } | 153 } |
154 } | 154 } |
155 | 155 |
156 | 156 |
157 // Helper function for removing |entry| from |directory|. If |entry| is a | |
158 // directory too, it will collect all its children file paths into | |
159 // |changed_dirs| as well. | |
160 void RemoveEntryFromDirectoryAndCollectChangedDirectories( | |
161 GDataDirectory* directory, | |
162 GDataEntry* entry, | |
163 std::set<FilePath>* changed_dirs) { | |
164 // Get the list of all sub-directory paths, so we can notify their listeners | |
165 // that they are smoked. | |
166 GetChildDirectoryPaths(entry, changed_dirs); | |
167 directory->RemoveEntry(entry); | |
168 } | |
169 | |
170 // Helper function for adding new |file| from the feed into |directory|. It | |
171 // checks the type of file and updates |changed_dirs| if this file adding | |
172 // operation needs to raise directory notification update. If file is being | |
173 // added to |orphaned_dir_service| such notifications are not raised since | |
174 // we ignore such files and don't add them to the file system now. | |
175 void AddEntryToDirectoryAndCollectChangedDirectories( | |
176 GDataEntry* entry, | |
177 GDataDirectory* directory, | |
178 GDataDirectoryService* orphaned_dir_service, | |
179 std::set<FilePath>* changed_dirs) { | |
180 directory->AddEntry(entry); | |
181 if (entry->AsGDataDirectory() && directory != orphaned_dir_service->root()) | |
182 changed_dirs->insert(entry->GetFilePath()); | |
183 } | |
184 | |
185 // Invoked upon completion of TransferRegularFile initiated by Copy. | 157 // Invoked upon completion of TransferRegularFile initiated by Copy. |
186 // | 158 // |
187 // |callback| is run on the thread represented by |relay_proxy|. | 159 // |callback| is run on the thread represented by |relay_proxy|. |
188 void OnTransferRegularFileCompleteForCopy( | 160 void OnTransferRegularFileCompleteForCopy( |
189 const FileOperationCallback& callback, | 161 const FileOperationCallback& callback, |
190 scoped_refptr<base::MessageLoopProxy> relay_proxy, | 162 scoped_refptr<base::MessageLoopProxy> relay_proxy, |
191 GDataFileError error) { | 163 GDataFileError error) { |
192 if (!callback.is_null()) | 164 if (!callback.is_null()) |
193 relay_proxy->PostTask(FROM_HERE, base::Bind(callback, error)); | 165 relay_proxy->PostTask(FROM_HERE, base::Bind(callback, error)); |
194 } | 166 } |
(...skipping 3277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3472 DCHECK(file_map->empty()); | 3444 DCHECK(file_map->empty()); |
3473 | 3445 |
3474 if (should_notify_directory_changed) { | 3446 if (should_notify_directory_changed) { |
3475 for (std::set<FilePath>::iterator dir_iter = changed_dirs.begin(); | 3447 for (std::set<FilePath>::iterator dir_iter = changed_dirs.begin(); |
3476 dir_iter != changed_dirs.end(); ++dir_iter) { | 3448 dir_iter != changed_dirs.end(); ++dir_iter) { |
3477 NotifyDirectoryChanged(*dir_iter); | 3449 NotifyDirectoryChanged(*dir_iter); |
3478 } | 3450 } |
3479 } | 3451 } |
3480 } | 3452 } |
3481 | 3453 |
| 3454 // Helper function for adding new |file| from the feed into |directory|. It |
| 3455 // checks the type of file and updates |changed_dirs| if this file adding |
| 3456 // operation needs to raise directory notification update. If file is being |
| 3457 // added to |orphaned_dir_service| such notifications are not raised since |
| 3458 // we ignore such files and don't add them to the file system now. |
| 3459 // static |
| 3460 void GDataFileSystem::AddEntryToDirectoryAndCollectChangedDirectories( |
| 3461 GDataEntry* entry, |
| 3462 GDataDirectory* directory, |
| 3463 GDataDirectoryService* orphaned_dir_service, |
| 3464 std::set<FilePath>* changed_dirs) { |
| 3465 directory->AddEntry(entry); |
| 3466 if (entry->AsGDataDirectory() && directory != orphaned_dir_service->root()) |
| 3467 changed_dirs->insert(entry->GetFilePath()); |
| 3468 } |
| 3469 |
| 3470 // Helper function for removing |entry| from |directory|. If |entry| is a |
| 3471 // directory too, it will collect all its children file paths into |
| 3472 // |changed_dirs| as well. |
| 3473 // static |
| 3474 void GDataFileSystem::RemoveEntryFromDirectoryAndCollectChangedDirectories( |
| 3475 GDataDirectory* directory, |
| 3476 GDataEntry* entry, |
| 3477 std::set<FilePath>* changed_dirs) { |
| 3478 // Get the list of all sub-directory paths, so we can notify their listeners |
| 3479 // that they are smoked. |
| 3480 GetChildDirectoryPaths(entry, changed_dirs); |
| 3481 directory->RemoveEntry(entry); |
| 3482 } |
| 3483 |
3482 GDataDirectory* GDataFileSystem::FindDirectoryForNewEntry( | 3484 GDataDirectory* GDataFileSystem::FindDirectoryForNewEntry( |
3483 GDataEntry* new_entry, | 3485 GDataEntry* new_entry, |
3484 const FileResourceIdMap& file_map, | 3486 const FileResourceIdMap& file_map, |
3485 GDataDirectoryService* orphaned_dir_service) { | 3487 GDataDirectoryService* orphaned_dir_service) { |
3486 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3488 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3487 GDataDirectory* dir = NULL; | 3489 GDataDirectory* dir = NULL; |
3488 // Added file. | 3490 // Added file. |
3489 const std::string& parent_id = new_entry->parent_resource_id(); | 3491 const std::string& parent_id = new_entry->parent_resource_id(); |
3490 if (parent_id.empty()) { | 3492 if (parent_id.empty()) { |
3491 dir = directory_service_->root(); | 3493 dir = directory_service_->root(); |
(...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4267 } | 4269 } |
4268 | 4270 |
4269 PlatformFileInfoProto entry_file_info; | 4271 PlatformFileInfoProto entry_file_info; |
4270 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); | 4272 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); |
4271 *entry_proto->mutable_file_info() = entry_file_info; | 4273 *entry_proto->mutable_file_info() = entry_file_info; |
4272 if (!callback.is_null()) | 4274 if (!callback.is_null()) |
4273 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); | 4275 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); |
4274 } | 4276 } |
4275 | 4277 |
4276 } // namespace gdata | 4278 } // namespace gdata |
OLD | NEW |