| 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 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_RESOURCE_METADATA_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_RESOURCE_METADATA_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_RESOURCE_METADATA_H_ | 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_RESOURCE_METADATA_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/callback_forward.h" | 13 #include "base/callback_forward.h" |
| 14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "base/time.h" | 17 #include "base/time.h" |
| 18 #include "chrome/browser/chromeos/drive/file_errors.h" | 18 #include "chrome/browser/chromeos/drive/file_errors.h" |
| 19 #include "chrome/browser/chromeos/drive/resource_metadata_storage.h" | 19 #include "chrome/browser/chromeos/drive/resource_metadata_storage.h" |
| 20 | 20 |
| 21 namespace base { | 21 namespace base { |
| 22 class SequencedTaskRunner; | 22 class SequencedTaskRunner; |
| 23 } | 23 } |
| 24 | 24 |
| 25 namespace drive { | 25 namespace drive { |
| 26 | 26 |
| 27 class ResourceEntry; | 27 class ResourceEntry; |
| 28 class ResourceMetadataStorage; | |
| 29 | 28 |
| 30 typedef std::vector<ResourceEntry> ResourceEntryVector; | 29 typedef std::vector<ResourceEntry> ResourceEntryVector; |
| 31 typedef std::map<std::string /* resource_id */, ResourceEntry> | 30 typedef std::map<std::string /* resource_id */, ResourceEntry> |
| 32 ResourceEntryMap; | 31 ResourceEntryMap; |
| 33 | 32 |
| 34 // Holds information needed to fetch contents of a directory. | 33 // Holds information needed to fetch contents of a directory. |
| 35 // This object is copyable. | 34 // This object is copyable. |
| 36 class DirectoryFetchInfo { | 35 class DirectoryFetchInfo { |
| 37 public: | 36 public: |
| 38 DirectoryFetchInfo() : changestamp_(0) {} | 37 DirectoryFetchInfo() : changestamp_(0) {} |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 typedef base::Callback<void(const ResourceEntry& entry)> IterateCallback; | 104 typedef base::Callback<void(const ResourceEntry& entry)> IterateCallback; |
| 106 | 105 |
| 107 namespace internal { | 106 namespace internal { |
| 108 | 107 |
| 109 // Storage for Drive Metadata. | 108 // Storage for Drive Metadata. |
| 110 // All methods must be run with |blocking_task_runner| unless otherwise noted. | 109 // All methods must be run with |blocking_task_runner| unless otherwise noted. |
| 111 class ResourceMetadata { | 110 class ResourceMetadata { |
| 112 public: | 111 public: |
| 113 typedef ResourceMetadataStorage::Iterator Iterator; | 112 typedef ResourceMetadataStorage::Iterator Iterator; |
| 114 | 113 |
| 115 // |root_resource_id| is the resource id for the root directory. | |
| 116 // Must be called on the UI thread. | |
| 117 ResourceMetadata( | 114 ResourceMetadata( |
| 118 const base::FilePath& data_directory_path, | 115 ResourceMetadataStorage* storage, |
| 119 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner); | 116 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner); |
| 120 | 117 |
| 121 // Initializes this object. | 118 // Initializes this object. |
| 122 // This method should be called before any other methods. | 119 // This method should be called before any other methods. |
| 123 FileError Initialize() WARN_UNUSED_RESULT; | 120 FileError Initialize() WARN_UNUSED_RESULT; |
| 124 | 121 |
| 125 // Destroys this object. This method posts a task to |blocking_task_runner_| | 122 // Destroys this object. This method posts a task to |blocking_task_runner_| |
| 126 // to safely delete this object. | 123 // to safely delete this object. |
| 127 // Must be called on the UI thread. | 124 // Must be called on the UI thread. |
| 128 void Destroy(); | 125 void Destroy(); |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 | 294 |
| 298 // Puts an entry under its parent directory. Removes the child from the old | 295 // Puts an entry under its parent directory. Removes the child from the old |
| 299 // parent if there is. This method will also do name de-duplication to ensure | 296 // parent if there is. This method will also do name de-duplication to ensure |
| 300 // that the exposed presentation path does not have naming conflicts. Two | 297 // that the exposed presentation path does not have naming conflicts. Two |
| 301 // files with the same name "Foo" will be renames to "Foo (1)" and "Foo (2)". | 298 // files with the same name "Foo" will be renames to "Foo (1)" and "Foo (2)". |
| 302 bool PutEntryUnderDirectory(const ResourceEntry& entry); | 299 bool PutEntryUnderDirectory(const ResourceEntry& entry); |
| 303 | 300 |
| 304 // Removes the entry and its descendants. | 301 // Removes the entry and its descendants. |
| 305 bool RemoveEntryRecursively(const std::string& resource_id); | 302 bool RemoveEntryRecursively(const std::string& resource_id); |
| 306 | 303 |
| 307 const base::FilePath data_directory_path_; | |
| 308 | |
| 309 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | 304 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; |
| 310 | 305 |
| 311 scoped_ptr<ResourceMetadataStorage> storage_; | 306 ResourceMetadataStorage* storage_; |
| 312 | 307 |
| 313 // This should remain the last member so it'll be destroyed first and | 308 // This should remain the last member so it'll be destroyed first and |
| 314 // invalidate its weak pointers before other members are destroyed. | 309 // invalidate its weak pointers before other members are destroyed. |
| 315 base::WeakPtrFactory<ResourceMetadata> weak_ptr_factory_; | 310 base::WeakPtrFactory<ResourceMetadata> weak_ptr_factory_; |
| 316 | 311 |
| 317 DISALLOW_COPY_AND_ASSIGN(ResourceMetadata); | 312 DISALLOW_COPY_AND_ASSIGN(ResourceMetadata); |
| 318 }; | 313 }; |
| 319 | 314 |
| 320 } // namespace internal | 315 } // namespace internal |
| 321 } // namespace drive | 316 } // namespace drive |
| 322 | 317 |
| 323 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_RESOURCE_METADATA_H_ | 318 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_RESOURCE_METADATA_H_ |
| OLD | NEW |