OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_GDATA_WAPI_FEED_PROCESSOR_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_WAPI_FEED_PROCESSOR_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <set> |
| 10 #include <string> |
| 11 #include <vector> |
| 12 |
| 13 #include "base/file_path.h" |
| 14 #include "chrome/browser/chromeos/gdata/gdata_errorcode.h" |
| 15 #include "chrome/browser/chromeos/gdata/gdata_wapi_parser.h" |
| 16 |
| 17 namespace gdata { |
| 18 |
| 19 class GDataDirectory; |
| 20 class GDataDirectoryService; |
| 21 class GDataEntry; |
| 22 |
| 23 typedef std::map<std::string /* resource_id */, GDataEntry*> |
| 24 FileResourceIdMap; |
| 25 |
| 26 // Struct used to record UMA stats with FeedToFileResourceMap(). |
| 27 struct FeedToFileResourceMapUmaStats { |
| 28 FeedToFileResourceMapUmaStats(); |
| 29 ~FeedToFileResourceMapUmaStats(); |
| 30 |
| 31 typedef std::map<DocumentEntry::EntryKind, int> EntryKindToCountMap; |
| 32 int num_regular_files; |
| 33 int num_hosted_documents; |
| 34 EntryKindToCountMap num_files_with_entry_kind; |
| 35 }; |
| 36 |
| 37 // GDataWapiFeedProcessor is used to process feeds from WAPI (codename for |
| 38 // Documents List API). |
| 39 class GDataWapiFeedProcessor { |
| 40 public: |
| 41 explicit GDataWapiFeedProcessor(GDataDirectoryService* directory_service); |
| 42 ~GDataWapiFeedProcessor(); |
| 43 |
| 44 // Applies the documents feeds to the file system using |directory_service_|. |
| 45 // |
| 46 // |start_changestamp| determines the type of feed to process. The value is |
| 47 // set to zero for the root feeds, every other value is for the delta feeds. |
| 48 // |
| 49 // In the case of processing the root feeds |root_feed_changestamp| is used |
| 50 // as its initial changestamp value. The value comes from |
| 51 // AccountMetadataFeed. |
| 52 GDataFileError ApplyFeeds(const std::vector<DocumentFeed*>& feed_list, |
| 53 int start_changestamp, |
| 54 int root_feed_changestamp, |
| 55 std::set<FilePath>* changed_dirs); |
| 56 |
| 57 // Converts list of document feeds from collected feeds into |
| 58 // FileResourceIdMap. |
| 59 GDataFileError FeedToFileResourceMap( |
| 60 const std::vector<DocumentFeed*>& feed_list, |
| 61 FileResourceIdMap* file_map, |
| 62 int* feed_changestamp, |
| 63 FeedToFileResourceMapUmaStats* uma_stats); |
| 64 |
| 65 private: |
| 66 // Updates UMA histograms about file counts. |
| 67 void UpdateFileCountUmaHistograms( |
| 68 const FeedToFileResourceMapUmaStats& uma_stats) const; |
| 69 |
| 70 // Applies the pre-processed feed from |file_map| map onto the file system. |
| 71 // All entries in |file_map| will be erased (i.e. the map becomes empty), |
| 72 // and values are deleted. |
| 73 void ApplyFeedFromFileUrlMap(bool is_delta_feed, |
| 74 int feed_changestamp, |
| 75 FileResourceIdMap* file_map, |
| 76 std::set<FilePath>* changed_dirs); |
| 77 |
| 78 // Helper function for adding new |file| from the feed into |directory|. It |
| 79 // checks the type of file and updates |changed_dirs| if this file adding |
| 80 // operation needs to raise directory notification update. If file is being |
| 81 // added to |orphaned_dir_service| such notifications are not raised since |
| 82 // we ignore such files and don't add them to the file system now. |
| 83 static void AddEntryToDirectoryAndCollectChangedDirectories( |
| 84 GDataEntry* entry, |
| 85 GDataDirectory* directory, |
| 86 GDataDirectoryService* orphaned_dir_service, |
| 87 std::set<FilePath>* changed_dirs); |
| 88 |
| 89 // Helper function for removing |entry| from |directory|. If |entry| is a |
| 90 // directory too, it will collect all its children file paths into |
| 91 // |changed_dirs| as well. |
| 92 static void RemoveEntryFromDirectoryAndCollectChangedDirectories( |
| 93 GDataDirectory* directory, |
| 94 GDataEntry* entry, |
| 95 std::set<FilePath>* changed_dirs); |
| 96 |
| 97 // Finds directory where new |file| should be added to during feed processing. |
| 98 // |orphaned_entries_dir| collects files/dirs that don't have a parent in |
| 99 // either locally cached file system or in this new feed. |
| 100 GDataDirectory* FindDirectoryForNewEntry( |
| 101 GDataEntry* new_entry, |
| 102 const FileResourceIdMap& file_map, |
| 103 GDataDirectoryService* orphaned_dir_service); |
| 104 |
| 105 GDataDirectoryService* directory_service_; // Not owned by the class. |
| 106 DISALLOW_COPY_AND_ASSIGN(GDataWapiFeedProcessor); |
| 107 }; |
| 108 |
| 109 } // namespace gdata |
| 110 |
| 111 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_WAPI_FEED_PROCESSOR_H_ |
OLD | NEW |