Chromium Code Reviews| 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_DRIVE_RESOURCE_METADATA_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_RESOURCE_METADATA_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_RESOURCE_METADATA_H_ | 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_RESOURCE_METADATA_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | |
| 9 #include <string> | 10 #include <string> |
| 10 #include <vector> | 11 #include <vector> |
| 11 | 12 |
| 12 #include "base/callback_forward.h" | 13 #include "base/callback_forward.h" |
| 13 #include "base/file_path.h" | 14 #include "base/file_path.h" |
| 14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 16 #include "base/time.h" | 17 #include "base/time.h" |
| 17 #include "chrome/browser/chromeos/drive/drive_file_error.h" | 18 #include "chrome/browser/chromeos/drive/drive_file_error.h" |
| 18 | 19 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 82 // If |error| is not DRIVE_FILE_OK, |entry_proto| is set to NULL. | 83 // If |error| is not DRIVE_FILE_OK, |entry_proto| is set to NULL. |
| 83 // | 84 // |
| 84 // |drive_file_path| parameter is provided as DriveEntryProto does not contain | 85 // |drive_file_path| parameter is provided as DriveEntryProto does not contain |
| 85 // the Drive file path (i.e. only contains the base name without parent | 86 // the Drive file path (i.e. only contains the base name without parent |
| 86 // directory names). | 87 // directory names). |
| 87 typedef base::Callback<void(DriveFileError error, | 88 typedef base::Callback<void(DriveFileError error, |
| 88 const FilePath& drive_file_path, | 89 const FilePath& drive_file_path, |
| 89 scoped_ptr<DriveEntryProto> entry_proto)> | 90 scoped_ptr<DriveEntryProto> entry_proto)> |
| 90 GetEntryInfoWithFilePathCallback; | 91 GetEntryInfoWithFilePathCallback; |
| 91 | 92 |
| 93 // Used to get a set of changed directories for feed processing. | |
| 94 typedef base::Callback<void(const std::set<FilePath>&)> | |
| 95 ChangedDirectoriesCallback; | |
| 96 | |
| 92 // This is a part of EntryInfoPairResult. | 97 // This is a part of EntryInfoPairResult. |
| 93 struct EntryInfoResult { | 98 struct EntryInfoResult { |
| 94 EntryInfoResult(); | 99 EntryInfoResult(); |
| 95 ~EntryInfoResult(); | 100 ~EntryInfoResult(); |
| 96 | 101 |
| 97 FilePath path; | 102 FilePath path; |
| 98 DriveFileError error; | 103 DriveFileError error; |
| 99 scoped_ptr<DriveEntryProto> proto; | 104 scoped_ptr<DriveEntryProto> proto; |
| 100 }; | 105 }; |
| 101 | 106 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 217 // |first_path| is not found, this function does not try to get the | 222 // |first_path| is not found, this function does not try to get the |
| 218 // entry of |second_path|. | 223 // entry of |second_path|. |
| 219 // | 224 // |
| 220 // Must be called from UI thread. |callback| is run on UI thread. | 225 // Must be called from UI thread. |callback| is run on UI thread. |
| 221 // |callback| must not be null. | 226 // |callback| must not be null. |
| 222 void GetEntryInfoPairByPaths( | 227 void GetEntryInfoPairByPaths( |
| 223 const FilePath& first_path, | 228 const FilePath& first_path, |
| 224 const FilePath& second_path, | 229 const FilePath& second_path, |
| 225 const GetEntryInfoPairCallback& callback); | 230 const GetEntryInfoPairCallback& callback); |
| 226 | 231 |
| 227 // Replaces a file entry with the same resource id as |doc_entry| by deleting | 232 // Refreshes a drive entry with the same resource id as |entry_proto|. |
| 228 // the existing entry, creating a new DriveFile from |doc_entry|, and adding | 233 // |callback| is run with the error, file path and proto of the entry. |
| 229 // it to the parent of the old entry. For directories, this just returns the | 234 // |callback| must not be null. |
| 230 // existing directory proto. |callback| is run with the error, file path and | 235 void RefreshEntryProto(const DriveEntryProto& entry_proto, |
| 231 // proto of the entry. |callback| must not be null. | 236 const GetEntryInfoWithFilePathCallback& callback); |
| 237 | |
| 238 // Refresh a drive entry with resource_id that matches that of |doc_entry|, | |
| 239 // with |doc_entry|. | |
| 240 // |callback| must not be null. | |
| 241 // TODO(achuith): Deprecate this in favor of RefreshEntryProto above. | |
| 232 void RefreshFile(scoped_ptr<google_apis::DocumentEntry> doc_entry, | 242 void RefreshFile(scoped_ptr<google_apis::DocumentEntry> doc_entry, |
| 233 const GetEntryInfoWithFilePathCallback& callback); | 243 const GetEntryInfoWithFilePathCallback& callback); |
| 234 | 244 |
| 235 // Removes all child files of |directory| and replaces them with | 245 // Removes all child files of |directory| and replaces them with |
| 236 // |entry_proto_map|. |callback| is called with the directory path. | 246 // |entry_proto_map|. |callback| is called with the directory path. |
| 237 // |callback| must not be null. | 247 // |callback| must not be null. |
| 238 void RefreshDirectory(const std::string& directory_resource_id, | 248 void RefreshDirectory(const std::string& directory_resource_id, |
| 239 const DriveEntryProtoMap& entry_proto_map, | 249 const DriveEntryProtoMap& entry_proto_map, |
| 240 const FileMoveCallback& callback); | 250 const FileMoveCallback& callback); |
| 241 | 251 |
| 252 // Add |entry_proto| to the metadata tree. | |
| 253 // |callback| must not be null. | |
| 254 void AddEntryToParent(const DriveEntryProto& entry_proto, | |
|
hashimoto
2012/11/14 10:15:56
Why are you adding this method instead of rewritin
achuithb
2012/11/14 11:11:29
AddEntryToParent has a DriveEntryProto, but does n
| |
| 255 const FileMoveCallback& callback); | |
| 256 | |
| 257 // Get changed directories related to entry pointed to by |resource_id|. This | |
| 258 // includes the immediate parent, self, and children. | |
| 259 void GetChangedDirectories( | |
|
hashimoto
2012/11/14 10:15:56
The term 'changed' seems not obvious in the contex
achuithb
2012/11/14 11:11:29
Ah, I can't do that. The code necessary to determi
hashimoto
2012/11/15 04:10:41
The main problem here is that, to understand what
achuithb
2012/11/15 23:39:54
I've decided to go with (3). The problem with (2)
| |
| 260 const std::string& resource_id, | |
| 261 const ChangedDirectoriesCallback& changed_dirs_callback); | |
| 262 | |
| 263 // Helper function to get a parent directory given |parent_resource_id|. | |
| 264 // Returns root if |parent_resource_id| is empty. Returns NULL if | |
| 265 // |parent_resource_id| is not empty and the corresponding entry is not a | |
| 266 // directory. | |
| 267 DriveDirectory* GetParent(const std::string& parent_resource_id); | |
|
hashimoto
2012/11/14 10:15:56
Does this method need to be public?
achuithb
2012/11/14 11:11:29
Done.
| |
| 268 | |
| 242 // Moves all child entries from the directory represented by | 269 // Moves all child entries from the directory represented by |
| 243 // |source_resource_id| to the directory respresented by | 270 // |source_resource_id| to the directory respresented by |
| 244 // |destination_resource_id|. |callback| must not be null. | 271 // |destination_resource_id|. |callback| must not be null. |
| 272 // TODO(achuith): Delete this. | |
| 245 void TakeOverEntries(const std::string& source_resource_id, | 273 void TakeOverEntries(const std::string& source_resource_id, |
| 246 const std::string& destination_resource_id, | 274 const std::string& destination_resource_id, |
| 247 const FileMoveCallback& callback); | 275 const FileMoveCallback& callback); |
| 248 | 276 |
| 249 // Serializes/Parses to/from string via proto classes. | 277 // Serializes/Parses to/from string via proto classes. |
| 250 void SerializeToString(std::string* serialized_proto) const; | 278 void SerializeToString(std::string* serialized_proto) const; |
| 251 bool ParseFromString(const std::string& serialized_proto); | 279 bool ParseFromString(const std::string& serialized_proto); |
| 252 | 280 |
| 253 // Restores from and saves to database, calling |callback| asynchronously. | 281 // Restores from and saves to database, calling |callback| asynchronously. |
| 254 // |callback| must not be null. | 282 // |callback| must not be null. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 288 // Continues with GetIntroInfoPairByPaths after the second DriveEntry has been | 316 // Continues with GetIntroInfoPairByPaths after the second DriveEntry has been |
| 289 // asynchronously fetched. | 317 // asynchronously fetched. |
| 290 void GetEntryInfoPairByPathsAfterGetSecond( | 318 void GetEntryInfoPairByPathsAfterGetSecond( |
| 291 const FilePath& second_path, | 319 const FilePath& second_path, |
| 292 const GetEntryInfoPairCallback& callback, | 320 const GetEntryInfoPairCallback& callback, |
| 293 scoped_ptr<EntryInfoPairResult> result, | 321 scoped_ptr<EntryInfoPairResult> result, |
| 294 DriveFileError error, | 322 DriveFileError error, |
| 295 scoped_ptr<DriveEntryProto> entry_proto); | 323 scoped_ptr<DriveEntryProto> entry_proto); |
| 296 | 324 |
| 297 // Searches for |file_path| synchronously. | 325 // Searches for |file_path| synchronously. |
| 298 // TODO(satorux): Replace this with an async version crbug.com/137160 | |
| 299 DriveEntry* FindEntryByPathSync(const FilePath& file_path); | 326 DriveEntry* FindEntryByPathSync(const FilePath& file_path); |
| 300 | 327 |
| 328 // Helper function to add |entry_proto| as a child to |directory|. | |
| 329 // |callback| must not be null. | |
| 330 void AddEntryToDirectoryInternal(DriveDirectory* directory, | |
| 331 const DriveEntryProto& entry_proto, | |
| 332 const FileMoveCallback& callback); | |
| 333 | |
| 301 // Private data members. | 334 // Private data members. |
| 302 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | 335 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; |
| 303 scoped_ptr<ResourceMetadataDB> resource_metadata_db_; | 336 scoped_ptr<ResourceMetadataDB> resource_metadata_db_; |
| 304 | 337 |
| 305 ResourceMap resource_map_; | 338 ResourceMap resource_map_; |
| 306 | 339 |
| 307 scoped_ptr<DriveDirectory> root_; // Stored in the serialized proto. | 340 scoped_ptr<DriveDirectory> root_; // Stored in the serialized proto. |
| 308 | 341 |
| 309 base::Time last_serialized_; | 342 base::Time last_serialized_; |
| 310 size_t serialized_size_; | 343 size_t serialized_size_; |
| 311 int64 largest_changestamp_; // Stored in the serialized proto. | 344 int64 largest_changestamp_; // Stored in the serialized proto. |
| 312 bool loaded_; | 345 bool loaded_; |
| 313 | 346 |
| 314 // This should remain the last member so it'll be destroyed first and | 347 // This should remain the last member so it'll be destroyed first and |
| 315 // invalidate its weak pointers before other members are destroyed. | 348 // invalidate its weak pointers before other members are destroyed. |
| 316 base::WeakPtrFactory<DriveResourceMetadata> weak_ptr_factory_; | 349 base::WeakPtrFactory<DriveResourceMetadata> weak_ptr_factory_; |
| 317 | 350 |
| 318 DISALLOW_COPY_AND_ASSIGN(DriveResourceMetadata); | 351 DISALLOW_COPY_AND_ASSIGN(DriveResourceMetadata); |
| 319 }; | 352 }; |
| 320 | 353 |
| 321 } // namespace drive | 354 } // namespace drive |
| 322 | 355 |
| 323 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_RESOURCE_METADATA_H_ | 356 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_RESOURCE_METADATA_H_ |
| OLD | NEW |