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_GDATA_GDATA_FILES_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILES_H_ |
6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILES_H_ | 6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILES_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/memory/singleton.h" | 14 #include "base/memory/singleton.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/platform_file.h" | 16 #include "base/platform_file.h" |
17 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
18 #include "chrome/browser/chromeos/gdata/gdata_params.h" | 18 #include "chrome/browser/chromeos/gdata/gdata_params.h" |
19 #include "chrome/browser/chromeos/gdata/gdata_uploader.h" | 19 #include "chrome/browser/chromeos/gdata/gdata_uploader.h" |
20 #include "chrome/browser/chromeos/gdata/gdata_wapi_parser.h" | 20 #include "chrome/browser/chromeos/gdata/gdata_wapi_parser.h" |
21 #include "chrome/browser/profiles/profile_keyed_service.h" | 21 #include "chrome/browser/profiles/profile_keyed_service.h" |
22 #include "chrome/browser/profiles/profile_keyed_service_factory.h" | 22 #include "chrome/browser/profiles/profile_keyed_service_factory.h" |
23 | 23 |
24 namespace base { | |
25 class SequencedTaskRunner; | |
26 } | |
27 | |
24 namespace gdata { | 28 namespace gdata { |
25 | 29 |
30 struct CreateDBParams; | |
26 class GDataFile; | 31 class GDataFile; |
27 class GDataDirectory; | 32 class GDataDirectory; |
28 class GDataDirectoryService; | 33 class GDataDirectoryService; |
34 class GDataDirectoryServiceDB; | |
29 | 35 |
30 class GDataEntryProto; | 36 class GDataEntryProto; |
31 class GDataDirectoryProto; | 37 class GDataDirectoryProto; |
32 class GDataRootDirectoryProto; | 38 class GDataRootDirectoryProto; |
33 class PlatformFileInfoProto; | 39 class PlatformFileInfoProto; |
34 | 40 |
35 // The root directory content origin. | 41 // The root directory content origin. |
36 enum ContentOrigin { | 42 enum ContentOrigin { |
37 UNINITIALIZED, | 43 UNINITIALIZED, |
38 // Content is currently loading from somewhere. Needs to wait. | 44 // Content is currently loading from somewhere. Needs to wait. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 const GDataFile* AsGDataFileConst() const; | 88 const GDataFile* AsGDataFileConst() const; |
83 const GDataDirectory* AsGDataDirectoryConst() const; | 89 const GDataDirectory* AsGDataDirectoryConst() const; |
84 | 90 |
85 // Converts DocumentEntry into GDataEntry. | 91 // Converts DocumentEntry into GDataEntry. |
86 static GDataEntry* FromDocumentEntry( | 92 static GDataEntry* FromDocumentEntry( |
87 GDataDirectory* parent, | 93 GDataDirectory* parent, |
88 DocumentEntry* doc, | 94 DocumentEntry* doc, |
89 GDataDirectoryService* directory_service); | 95 GDataDirectoryService* directory_service); |
90 | 96 |
91 // Serialize/Parse to/from string via proto classes. | 97 // Serialize/Parse to/from string via proto classes. |
92 // TODO(achuith): Correctly set up parent_ and root_ links in | |
93 // FromProtoString. | |
94 void SerializeToString(std::string* serialized_proto) const; | 98 void SerializeToString(std::string* serialized_proto) const; |
99 // TODO(achuith): Get rid of this. | |
satorux1
2012/08/02 17:24:03
Please add a url to the bug
achuithb
2012/08/02 20:26:25
Done.
| |
95 static scoped_ptr<GDataEntry> FromProtoString( | 100 static scoped_ptr<GDataEntry> FromProtoString( |
96 const std::string& serialized_proto); | 101 const std::string& serialized_proto); |
97 | 102 |
98 // Converts the proto representation to the platform file. | 103 // Converts the proto representation to the platform file. |
99 static void ConvertProtoToPlatformFileInfo( | 104 static void ConvertProtoToPlatformFileInfo( |
100 const PlatformFileInfoProto& proto, | 105 const PlatformFileInfoProto& proto, |
101 base::PlatformFileInfo* file_info); | 106 base::PlatformFileInfo* file_info); |
102 | 107 |
103 // Converts the platform file info to the proto representation. | 108 // Converts the platform file info to the proto representation. |
104 static void ConvertPlatformFileInfoToProto( | 109 static void ConvertPlatformFileInfoToProto( |
105 const base::PlatformFileInfo& file_info, | 110 const base::PlatformFileInfo& file_info, |
106 PlatformFileInfoProto* proto); | 111 PlatformFileInfoProto* proto); |
107 | 112 |
108 // Converts to/from proto. Only handles the common part (i.e. does not | 113 // Converts to/from proto. Only handles the common part (i.e. does not |
109 // touch |file_specific_info| and |directory_specific_info|. | 114 // touch |file_specific_info|). |
110 bool FromProto(const GDataEntryProto& proto) WARN_UNUSED_RESULT; | 115 bool FromProto(const GDataEntryProto& proto) WARN_UNUSED_RESULT; |
111 void ToProto(GDataEntryProto* proto) const; | 116 void ToProto(GDataEntryProto* proto) const; |
112 | 117 |
113 // Similar to ToProto() but this fills in |file_specific_info| and | 118 // Similar to ToProto() but this fills in |file_specific_info| and |
114 // |directory_specific_info| based on the actual type of the entry. | 119 // |directory_specific_info| based on the actual type of the entry. |
115 // Used to obtain full metadata of a file or a directory as | 120 // Used to obtain full metadata of a file or a directory as |
116 // GDataEntryProto. | 121 // GDataEntryProto. |
117 void ToProtoFull(GDataEntryProto* proto) const; | 122 void ToProtoFull(GDataEntryProto* proto) const; |
118 | 123 |
119 // Escapes forward slashes from file names with magic unicode character | 124 // Escapes forward slashes from file names with magic unicode character |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
329 // entry instance. | 334 // entry instance. |
330 bool RemoveChild(GDataEntry* entry); | 335 bool RemoveChild(GDataEntry* entry); |
331 | 336 |
332 // Collection of children GDataEntry items. | 337 // Collection of children GDataEntry items. |
333 GDataFileCollection child_files_; | 338 GDataFileCollection child_files_; |
334 GDataDirectoryCollection child_directories_; | 339 GDataDirectoryCollection child_directories_; |
335 | 340 |
336 DISALLOW_COPY_AND_ASSIGN(GDataDirectory); | 341 DISALLOW_COPY_AND_ASSIGN(GDataDirectory); |
337 }; | 342 }; |
338 | 343 |
344 // TODO(achuith,hashimoto,satorux): Move this to a separate file. | |
satorux1
2012/08/02 17:24:03
could you file a bug and add a url to it? I'll fin
achuithb
2012/08/02 20:26:25
Done.
| |
339 // Class to handle GDataEntry* lookups, add/remove GDataEntry*. | 345 // Class to handle GDataEntry* lookups, add/remove GDataEntry*. |
340 class GDataDirectoryService { | 346 class GDataDirectoryService { |
341 public: | 347 public: |
342 // Callback for GetEntryByResourceIdAsync. | 348 // Callback for GetEntryByResourceIdAsync. |
343 typedef base::Callback<void(GDataEntry* entry)> GetEntryByResourceIdCallback; | 349 typedef base::Callback<void(GDataEntry* entry)> GetEntryByResourceIdCallback; |
344 | 350 |
351 // Map of resource id and serialized GDataEntry. | |
352 typedef std::map<std::string, std::string> SerializedMap; | |
353 | |
345 GDataDirectoryService(); | 354 GDataDirectoryService(); |
346 ~GDataDirectoryService(); | 355 ~GDataDirectoryService(); |
347 | 356 |
348 GDataDirectory* root() { return root_.get(); } | 357 GDataDirectory* root() { return root_.get(); } |
349 | 358 |
350 // Last time when we dumped serialized file system to disk. | 359 // Last time when we dumped serialized file system to disk. |
351 const base::Time& last_serialized() const { return last_serialized_; } | 360 const base::Time& last_serialized() const { return last_serialized_; } |
352 void set_last_serialized(const base::Time& time) { last_serialized_ = time; } | 361 void set_last_serialized(const base::Time& time) { last_serialized_ = time; } |
353 // Size of serialized file system on disk in bytes. | 362 // Size of serialized file system on disk in bytes. |
354 const size_t serialized_size() const { return serialized_size_; } | 363 const size_t serialized_size() const { return serialized_size_; } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
393 void RefreshFile(scoped_ptr<GDataFile> fresh_file); | 402 void RefreshFile(scoped_ptr<GDataFile> fresh_file); |
394 | 403 |
395 // Replaces file entry |old_entry| with its fresh value |fresh_file|. | 404 // Replaces file entry |old_entry| with its fresh value |fresh_file|. |
396 static void RefreshFileInternal(scoped_ptr<GDataFile> fresh_file, | 405 static void RefreshFileInternal(scoped_ptr<GDataFile> fresh_file, |
397 GDataEntry* old_entry); | 406 GDataEntry* old_entry); |
398 | 407 |
399 // Serializes/Parses to/from string via proto classes. | 408 // Serializes/Parses to/from string via proto classes. |
400 void SerializeToString(std::string* serialized_proto) const; | 409 void SerializeToString(std::string* serialized_proto) const; |
401 bool ParseFromString(const std::string& serialized_proto); | 410 bool ParseFromString(const std::string& serialized_proto); |
402 | 411 |
412 // Restore from and save to database. | |
satorux1
2012/08/02 17:24:03
Restores/saves
achuithb
2012/08/02 20:26:25
Done.
| |
413 void InitFromDB(const FilePath& db_path, | |
414 base::SequencedTaskRunner* blocking_task_runner, | |
415 LoadRootFeedParams* load_params, | |
416 const base::Closure& callback); | |
417 void SaveToDB(); | |
418 | |
403 private: | 419 private: |
404 // A map table of file's resource string to its GDataFile* entry. | 420 // A map table of file's resource string to its GDataFile* entry. |
405 typedef std::map<std::string, GDataEntry*> ResourceMap; | 421 typedef std::map<std::string, GDataEntry*> ResourceMap; |
406 | 422 |
423 // Initialize the resource map using serialized_resources fetched from the db. | |
satorux1
2012/08/02 17:24:03
please fix other paces too
achuithb
2012/08/02 20:26:25
Done.
| |
424 void InitResourceMap(CreateDBParams* create_params, | |
425 LoadRootFeedParams* load_params, | |
426 const base::Closure& callback); | |
427 | |
428 // Clear root_ and the resource map. | |
429 void ClearRoot(); | |
430 | |
431 // Create GDataEntry from serialized string. | |
432 scoped_ptr<GDataEntry> FromProtoString( | |
433 const std::string& serialized_proto); | |
434 | |
435 // Private data members. | |
436 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | |
437 scoped_ptr<GDataDirectoryServiceDB> directory_service_db_; | |
438 | |
439 ResourceMap resource_map_; | |
440 | |
407 scoped_ptr<GDataDirectory> root_; // Stored in the serialized proto. | 441 scoped_ptr<GDataDirectory> root_; // Stored in the serialized proto. |
408 ResourceMap resource_map_; | |
409 | 442 |
410 base::Time last_serialized_; | 443 base::Time last_serialized_; |
411 size_t serialized_size_; | 444 size_t serialized_size_; |
412 int largest_changestamp_; // Stored in the serialized proto. | 445 int largest_changestamp_; // Stored in the serialized proto. |
413 ContentOrigin origin_; | 446 ContentOrigin origin_; |
414 | 447 |
448 base::WeakPtrFactory<GDataDirectoryService> ui_weak_ptr_factory_; | |
satorux1
2012/08/02 17:24:03
omit "ui_"?
achuithb
2012/08/02 20:26:25
Done.
| |
449 | |
415 DISALLOW_COPY_AND_ASSIGN(GDataDirectoryService); | 450 DISALLOW_COPY_AND_ASSIGN(GDataDirectoryService); |
416 }; | 451 }; |
417 | 452 |
418 } // namespace gdata | 453 } // namespace gdata |
419 | 454 |
420 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILES_H_ | 455 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILES_H_ |
OLD | NEW |