| 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/singleton.h" | 15 #include "base/memory/singleton.h" |
| 16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "base/platform_file.h" | 17 #include "base/platform_file.h" |
| 18 #include "base/synchronization/lock.h" | 18 #include "base/synchronization/lock.h" |
| 19 #include "chrome/browser/chromeos/gdata/gdata_params.h" | 19 #include "chrome/browser/chromeos/gdata/gdata_params.h" |
| 20 #include "chrome/browser/chromeos/gdata/gdata_parser.h" | 20 #include "chrome/browser/chromeos/gdata/gdata_parser.h" |
| 21 #include "chrome/browser/chromeos/gdata/gdata_uploader.h" | 21 #include "chrome/browser/chromeos/gdata/gdata_uploader.h" |
| 22 #include "chrome/browser/profiles/profile_keyed_service.h" | 22 #include "chrome/browser/profiles/profile_keyed_service.h" |
| 23 #include "chrome/browser/profiles/profile_keyed_service_factory.h" | 23 #include "chrome/browser/profiles/profile_keyed_service_factory.h" |
| 24 | 24 |
| 25 namespace gdata { | 25 namespace gdata { |
| 26 | 26 |
| 27 class FindEntryDelegate; |
| 27 class GDataFile; | 28 class GDataFile; |
| 28 class GDataDirectory; | 29 class GDataDirectory; |
| 29 class GDataRootDirectory; | 30 class GDataRootDirectory; |
| 30 | 31 |
| 31 class GDataEntryProto; | 32 class GDataEntryProto; |
| 32 class GDataFileProto; | 33 class GDataFileProto; |
| 33 class GDataDirectoryProto; | 34 class GDataDirectoryProto; |
| 34 class GDataRootDirectoryProto; | 35 class GDataRootDirectoryProto; |
| 35 | 36 |
| 36 // Directory content origin. | 37 // Directory content origin. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 DocumentEntry* doc, | 74 DocumentEntry* doc, |
| 74 GDataRootDirectory* root); | 75 GDataRootDirectory* root); |
| 75 | 76 |
| 76 // Serialize/Parse to/from string via proto classes. | 77 // Serialize/Parse to/from string via proto classes. |
| 77 // TODO(achuith): Correctly set up parent_ and root_ links in | 78 // TODO(achuith): Correctly set up parent_ and root_ links in |
| 78 // FromProtoString. | 79 // FromProtoString. |
| 79 void SerializeToString(std::string* serialized_proto) const; | 80 void SerializeToString(std::string* serialized_proto) const; |
| 80 static scoped_ptr<GDataEntry> FromProtoString( | 81 static scoped_ptr<GDataEntry> FromProtoString( |
| 81 const std::string& serialized_proto); | 82 const std::string& serialized_proto); |
| 82 | 83 |
| 83 // Convert to/from proto. | 84 // Converts to/from proto. |
| 84 void FromProto(const GDataEntryProto& proto); | 85 void FromProto(const GDataEntryProto& proto); |
| 85 void ToProto(GDataEntryProto* proto) const; | 86 void ToProto(GDataEntryProto* proto) const; |
| 86 | 87 |
| 87 // Escapes forward slashes from file names with magic unicode character | 88 // Escapes forward slashes from file names with magic unicode character |
| 88 // \u2215 pretty much looks the same in UI. | 89 // \u2215 pretty much looks the same in UI. |
| 89 static std::string EscapeUtf8FileName(const std::string& input); | 90 static std::string EscapeUtf8FileName(const std::string& input); |
| 90 | 91 |
| 91 // Unescapes what was escaped in EScapeUtf8FileName. | 92 // Unescapes what was escaped in EScapeUtf8FileName. |
| 92 static std::string UnescapeUtf8FileName(const std::string& input); | 93 static std::string UnescapeUtf8FileName(const std::string& input); |
| 93 | 94 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 }; | 179 }; |
| 179 | 180 |
| 180 explicit GDataFile(GDataDirectory* parent, GDataRootDirectory* root); | 181 explicit GDataFile(GDataDirectory* parent, GDataRootDirectory* root); |
| 181 virtual ~GDataFile(); | 182 virtual ~GDataFile(); |
| 182 virtual GDataFile* AsGDataFile() OVERRIDE; | 183 virtual GDataFile* AsGDataFile() OVERRIDE; |
| 183 | 184 |
| 184 static GDataEntry* FromDocumentEntry(GDataDirectory* parent, | 185 static GDataEntry* FromDocumentEntry(GDataDirectory* parent, |
| 185 DocumentEntry* doc, | 186 DocumentEntry* doc, |
| 186 GDataRootDirectory* root); | 187 GDataRootDirectory* root); |
| 187 | 188 |
| 188 // Convert to/from proto. | 189 // Converts to/from proto. |
| 189 void FromProto(const GDataFileProto& proto); | 190 void FromProto(const GDataFileProto& proto); |
| 190 void ToProto(GDataFileProto* proto) const; | 191 void ToProto(GDataFileProto* proto) const; |
| 191 | 192 |
| 192 static bool IsCachePresent(int cache_state) { | 193 static bool IsCachePresent(int cache_state) { |
| 193 return cache_state & CACHE_STATE_PRESENT; | 194 return cache_state & CACHE_STATE_PRESENT; |
| 194 } | 195 } |
| 195 static bool IsCachePinned(int cache_state) { | 196 static bool IsCachePinned(int cache_state) { |
| 196 return cache_state & CACHE_STATE_PINNED; | 197 return cache_state & CACHE_STATE_PINNED; |
| 197 } | 198 } |
| 198 static bool IsCacheDirty(int cache_state) { | 199 static bool IsCacheDirty(int cache_state) { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 class GDataDirectory : public GDataEntry { | 263 class GDataDirectory : public GDataEntry { |
| 263 public: | 264 public: |
| 264 GDataDirectory(GDataDirectory* parent, GDataRootDirectory* root); | 265 GDataDirectory(GDataDirectory* parent, GDataRootDirectory* root); |
| 265 virtual ~GDataDirectory(); | 266 virtual ~GDataDirectory(); |
| 266 virtual GDataDirectory* AsGDataDirectory() OVERRIDE; | 267 virtual GDataDirectory* AsGDataDirectory() OVERRIDE; |
| 267 | 268 |
| 268 static GDataEntry* FromDocumentEntry(GDataDirectory* parent, | 269 static GDataEntry* FromDocumentEntry(GDataDirectory* parent, |
| 269 DocumentEntry* doc, | 270 DocumentEntry* doc, |
| 270 GDataRootDirectory* root); | 271 GDataRootDirectory* root); |
| 271 | 272 |
| 272 // Convert to/from proto. | 273 // Converts to/from proto. |
| 273 void FromProto(const GDataDirectoryProto& proto); | 274 void FromProto(const GDataDirectoryProto& proto); |
| 274 void ToProto(GDataDirectoryProto* proto) const; | 275 void ToProto(GDataDirectoryProto* proto) const; |
| 275 | 276 |
| 276 // Adds child file to the directory and takes over the ownership of |file| | 277 // Adds child file to the directory and takes over the ownership of |file| |
| 277 // object. The method will also do name de-duplication to ensure that the | 278 // object. The method will also do name de-duplication to ensure that the |
| 278 // exposed presentation path does not have naming conflicts. Two files with | 279 // exposed presentation path does not have naming conflicts. Two files with |
| 279 // the same name "Foo" will be renames to "Foo (1)" and "Foo (2)". | 280 // the same name "Foo" will be renames to "Foo (1)" and "Foo (2)". |
| 280 void AddEntry(GDataEntry* entry); | 281 void AddEntry(GDataEntry* entry); |
| 281 | 282 |
| 282 // Takes the ownership of |entry| from its current parent. If this directory | 283 // Takes the ownership of |entry| from its current parent. If this directory |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 // Last time when we dumped serialized file system to disk. | 407 // Last time when we dumped serialized file system to disk. |
| 407 const base::Time& last_serialized() const { return last_serialized_; } | 408 const base::Time& last_serialized() const { return last_serialized_; } |
| 408 void set_last_serialized(const base::Time& time) { last_serialized_ = time; } | 409 void set_last_serialized(const base::Time& time) { last_serialized_ = time; } |
| 409 // Size of serialized file system on disk in bytes. | 410 // Size of serialized file system on disk in bytes. |
| 410 const size_t serialized_size() const { return serialized_size_; } | 411 const size_t serialized_size() const { return serialized_size_; } |
| 411 void set_serialized_size(size_t size) { serialized_size_ = size; } | 412 void set_serialized_size(size_t size) { serialized_size_ = size; } |
| 412 | 413 |
| 413 // GDataEntry implementation. | 414 // GDataEntry implementation. |
| 414 virtual GDataRootDirectory* AsGDataRootDirectory() OVERRIDE; | 415 virtual GDataRootDirectory* AsGDataRootDirectory() OVERRIDE; |
| 415 | 416 |
| 416 // Add the entry to resource map. | 417 // Adds the entry to resource map. |
| 417 void AddEntryToResourceMap(GDataEntry* entry); | 418 void AddEntryToResourceMap(GDataEntry* entry); |
| 418 | 419 |
| 419 // Remove the entry from resource map. | 420 // Removes the entry from resource map. |
| 420 void RemoveEntryFromResourceMap(GDataEntry* entry); | 421 void RemoveEntryFromResourceMap(GDataEntry* entry); |
| 421 | 422 |
| 422 // Remove the entries from resource map. | 423 // Removes the entries from resource map. |
| 423 void RemoveEntriesFromResourceMap(const GDataFileCollection& children); | 424 void RemoveEntriesFromResourceMap(const GDataFileCollection& children); |
| 424 | 425 |
| 426 // Searches for |file_path| triggering callback in |delegate|. |
| 427 void FindEntryByPath(const FilePath& file_path, |
| 428 FindEntryDelegate* delegate); |
| 429 |
| 425 // Returns the GDataEntry* with the corresponding |resource_id|. | 430 // Returns the GDataEntry* with the corresponding |resource_id|. |
| 426 GDataEntry* GetEntryByResourceId(const std::string& resource_id); | 431 GDataEntry* GetEntryByResourceId(const std::string& resource_id); |
| 427 | 432 |
| 428 // Set |cache_map_| data member to formal parameter |new_cache_map|. | 433 // Sets |cache_map_| data member to formal parameter |new_cache_map|. |
| 429 void SetCacheMap(const CacheMap& new_cache_map); | 434 void SetCacheMap(const CacheMap& new_cache_map); |
| 430 | 435 |
| 431 // Updates cache map with entry corresponding to |resource_id|. | 436 // Updates cache map with entry corresponding to |resource_id|. |
| 432 // Creates new entry if it doesn't exist, otherwise update the entry. | 437 // Creates new entry if it doesn't exist, otherwise update the entry. |
| 433 void UpdateCacheMap(const std::string& resource_id, | 438 void UpdateCacheMap(const std::string& resource_id, |
| 434 const std::string& md5, | 439 const std::string& md5, |
| 435 CacheSubDirectoryType subdir, | 440 CacheSubDirectoryType subdir, |
| 436 int cache_state); | 441 int cache_state); |
| 437 | 442 |
| 438 // Removes entry corresponding to |resource_id| from cache map. | 443 // Removes entry corresponding to |resource_id| from cache map. |
| 439 void RemoveFromCacheMap(const std::string& resource_id); | 444 void RemoveFromCacheMap(const std::string& resource_id); |
| 440 | 445 |
| 441 // Returns the cache entry for file corresponding to |resource_id| and |md5| | 446 // Returns the cache entry for file corresponding to |resource_id| and |md5| |
| 442 // if entry exists in cache map. Otherwise, returns NULL. | 447 // if entry exists in cache map. Otherwise, returns NULL. |
| 443 // |md5| can be empty if only matching |resource_id| is desired, which may | 448 // |md5| can be empty if only matching |resource_id| is desired, which may |
| 444 // happen when looking for pinned entries where symlinks' filenames have no | 449 // happen when looking for pinned entries where symlinks' filenames have no |
| 445 // extension and hence no md5. | 450 // extension and hence no md5. |
| 446 CacheEntry* GetCacheEntry(const std::string& resource_id, | 451 CacheEntry* GetCacheEntry(const std::string& resource_id, |
| 447 const std::string& md5); | 452 const std::string& md5); |
| 448 | 453 |
| 449 // Remove temporary files (files in CACHE_TYPE_TMP) from the cache map. | 454 // Removes temporary files (files in CACHE_TYPE_TMP) from the cache map. |
| 450 void RemoveTemporaryFilesFromCacheMap(); | 455 void RemoveTemporaryFilesFromCacheMap(); |
| 451 | 456 |
| 452 // Serialize/Parse to/from string via proto classes. | 457 // Serializes/Parses to/from string via proto classes. |
| 453 void SerializeToString(std::string* serialized_proto) const; | 458 void SerializeToString(std::string* serialized_proto) const; |
| 454 bool ParseFromString(const std::string& serialized_proto); | 459 bool ParseFromString(const std::string& serialized_proto); |
| 455 | 460 |
| 456 // Convert to/from proto. | 461 // Converts to/from proto. |
| 457 void FromProto(const GDataRootDirectoryProto& proto); | 462 void FromProto(const GDataRootDirectoryProto& proto); |
| 458 void ToProto(GDataRootDirectoryProto* proto) const; | 463 void ToProto(GDataRootDirectoryProto* proto) const; |
| 459 | 464 |
| 460 private: | 465 private: |
| 461 ResourceMap resource_map_; | 466 ResourceMap resource_map_; |
| 462 CacheMap cache_map_; | 467 CacheMap cache_map_; |
| 463 | 468 |
| 464 base::Time last_serialized_; | 469 base::Time last_serialized_; |
| 465 int largest_changestamp_; | 470 int largest_changestamp_; |
| 466 size_t serialized_size_; | 471 size_t serialized_size_; |
| 467 | 472 |
| 468 DISALLOW_COPY_AND_ASSIGN(GDataRootDirectory); | 473 DISALLOW_COPY_AND_ASSIGN(GDataRootDirectory); |
| 469 }; | 474 }; |
| 470 | 475 |
| 471 } // namespace gdata | 476 } // namespace gdata |
| 472 | 477 |
| 473 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILES_H_ | 478 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILES_H_ |
| OLD | NEW |