| 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 <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 // Content is initialized from disk cache. | 52 // Content is initialized from disk cache. |
| 53 FROM_CACHE, | 53 FROM_CACHE, |
| 54 // Content is initialized from the direct server response. | 54 // Content is initialized from the direct server response. |
| 55 FROM_SERVER, | 55 FROM_SERVER, |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 // The root directory name used for the Google Drive file system tree. The | 58 // The root directory name used for the Google Drive file system tree. The |
| 59 // name is used in URLs for the file manager, hence user-visible. | 59 // name is used in URLs for the file manager, hence user-visible. |
| 60 const FilePath::CharType kDriveRootDirectory[] = FILE_PATH_LITERAL("drive"); | 60 const FilePath::CharType kDriveRootDirectory[] = FILE_PATH_LITERAL("drive"); |
| 61 | 61 |
| 62 // The resource ID for the root directory is defined in the spec: | |
| 63 // https://developers.google.com/google-apps/documents-list/ | |
| 64 const char kDriveRootDirectoryResourceId[] = "folder:root"; | |
| 65 | |
| 66 // This should be incremented when incompatibility change is made in | 62 // This should be incremented when incompatibility change is made in |
| 67 // drive.proto. | 63 // drive.proto. |
| 68 const int32 kProtoVersion = 2; | 64 const int32 kProtoVersion = 2; |
| 69 | 65 |
| 70 // Used for file operations like removing files. | 66 // Used for file operations like removing files. |
| 71 typedef base::Callback<void(DriveFileError error)> | 67 typedef base::Callback<void(DriveFileError error)> |
| 72 FileOperationCallback; | 68 FileOperationCallback; |
| 73 | 69 |
| 74 // Callback similar to FileOperationCallback but with a given |file_path|. | 70 // Callback similar to FileOperationCallback but with a given |file_path|. |
| 75 // Used for operations that change a file path like moving files. | 71 // Used for operations that change a file path like moving files. |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 void SerializeToString(std::string* serialized_proto) const; | 251 void SerializeToString(std::string* serialized_proto) const; |
| 256 bool ParseFromString(const std::string& serialized_proto); | 252 bool ParseFromString(const std::string& serialized_proto); |
| 257 | 253 |
| 258 // Restores from and saves to database, calling |callback| asynchronously. | 254 // Restores from and saves to database, calling |callback| asynchronously. |
| 259 // |callback| must not be null. | 255 // |callback| must not be null. |
| 260 void InitFromDB(const FilePath& db_path, | 256 void InitFromDB(const FilePath& db_path, |
| 261 base::SequencedTaskRunner* blocking_task_runner, | 257 base::SequencedTaskRunner* blocking_task_runner, |
| 262 const FileOperationCallback& callback); | 258 const FileOperationCallback& callback); |
| 263 void SaveToDB(); | 259 void SaveToDB(); |
| 264 | 260 |
| 261 // Returns the resource ID of the root directory or empty string if it is |
| 262 // not initialized. |
| 263 const std::string& root_resource_id() const; |
| 264 |
| 265 private: | 265 private: |
| 266 // Initializes the resource map using serialized_resources fetched from the | 266 // Initializes the resource map using serialized_resources fetched from the |
| 267 // database. | 267 // database. |
| 268 // |callback| must not be null. | 268 // |callback| must not be null. |
| 269 void InitResourceMap(CreateDBParams* create_params, | 269 void InitResourceMap(CreateDBParams* create_params, |
| 270 const FileOperationCallback& callback); | 270 const FileOperationCallback& callback); |
| 271 | 271 |
| 272 // Clears root_ and the resource map. | 272 // Clears root_ and the resource map. |
| 273 void ClearRoot(); | 273 void ClearRoot(); |
| 274 | 274 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 300 DriveEntry* FindEntryByPathSync(const FilePath& file_path); | 300 DriveEntry* FindEntryByPathSync(const FilePath& file_path); |
| 301 | 301 |
| 302 // Private data members. | 302 // Private data members. |
| 303 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | 303 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; |
| 304 scoped_ptr<ResourceMetadataDB> resource_metadata_db_; | 304 scoped_ptr<ResourceMetadataDB> resource_metadata_db_; |
| 305 | 305 |
| 306 ResourceMap resource_map_; | 306 ResourceMap resource_map_; |
| 307 | 307 |
| 308 scoped_ptr<DriveDirectory> root_; // Stored in the serialized proto. | 308 scoped_ptr<DriveDirectory> root_; // Stored in the serialized proto. |
| 309 | 309 |
| 310 // Retains special resource ID for the root directory across |ClearRoot()|. |
| 311 // This must be initialized only once using |InitializeRootEntry()|. |
| 312 // This value will be used to look up the root direcotry in |InitFromDB()|. |
| 313 std::string saved_root_resource_id_; |
| 314 |
| 310 base::Time last_serialized_; | 315 base::Time last_serialized_; |
| 311 size_t serialized_size_; | 316 size_t serialized_size_; |
| 312 int64 largest_changestamp_; // Stored in the serialized proto. | 317 int64 largest_changestamp_; // Stored in the serialized proto. |
| 313 ContentOrigin origin_; | 318 ContentOrigin origin_; |
| 314 | 319 |
| 315 // This should remain the last member so it'll be destroyed first and | 320 // This should remain the last member so it'll be destroyed first and |
| 316 // invalidate its weak pointers before other members are destroyed. | 321 // invalidate its weak pointers before other members are destroyed. |
| 317 base::WeakPtrFactory<DriveResourceMetadata> weak_ptr_factory_; | 322 base::WeakPtrFactory<DriveResourceMetadata> weak_ptr_factory_; |
| 318 | 323 |
| 319 DISALLOW_COPY_AND_ASSIGN(DriveResourceMetadata); | 324 DISALLOW_COPY_AND_ASSIGN(DriveResourceMetadata); |
| 320 }; | 325 }; |
| 321 | 326 |
| 322 } // namespace drive | 327 } // namespace drive |
| 323 | 328 |
| 324 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_RESOURCE_METADATA_H_ | 329 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_RESOURCE_METADATA_H_ |
| OLD | NEW |