| 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_DRIVE_CHANGE_LIST_PROCESSOR_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_CHANGE_LIST_PROCESSOR_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <set> | |
| 10 #include <string> | |
| 11 | |
| 12 #include "base/files/file_path.h" | |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "base/memory/scoped_vector.h" | |
| 15 #include "components/drive/file_errors.h" | |
| 16 #include "components/drive/file_errors.h" | |
| 17 #include "url/gurl.h" | |
| 18 | |
| 19 namespace base { | |
| 20 class CancellationFlag; | |
| 21 } // namespace base | |
| 22 | |
| 23 namespace google_apis { | |
| 24 class AboutResource; | |
| 25 class ChangeList; | |
| 26 class FileList; | |
| 27 } // namespace google_apis | |
| 28 | |
| 29 namespace drive { | |
| 30 | |
| 31 class FileChange; | |
| 32 class ResourceEntry; | |
| 33 | |
| 34 namespace internal { | |
| 35 | |
| 36 class ResourceMetadata; | |
| 37 | |
| 38 // Holds information needed to fetch contents of a directory. | |
| 39 // This object is copyable. | |
| 40 class DirectoryFetchInfo { | |
| 41 public: | |
| 42 DirectoryFetchInfo() : changestamp_(0) {} | |
| 43 DirectoryFetchInfo(const std::string& local_id, | |
| 44 const std::string& resource_id, | |
| 45 int64 changestamp) | |
| 46 : local_id_(local_id), | |
| 47 resource_id_(resource_id), | |
| 48 changestamp_(changestamp) { | |
| 49 } | |
| 50 | |
| 51 // Returns true if the object is empty. | |
| 52 bool empty() const { return local_id_.empty(); } | |
| 53 | |
| 54 // Local ID of the directory. | |
| 55 const std::string& local_id() const { return local_id_; } | |
| 56 | |
| 57 // Resource ID of the directory. | |
| 58 const std::string& resource_id() const { return resource_id_; } | |
| 59 | |
| 60 // Changestamp of the directory. The changestamp is used to determine if | |
| 61 // the directory contents should be fetched. | |
| 62 int64 changestamp() const { return changestamp_; } | |
| 63 | |
| 64 // Returns a string representation of this object. | |
| 65 std::string ToString() const; | |
| 66 | |
| 67 private: | |
| 68 const std::string local_id_; | |
| 69 const std::string resource_id_; | |
| 70 const int64 changestamp_; | |
| 71 }; | |
| 72 | |
| 73 // Class to represent a change list. | |
| 74 class ChangeList { | |
| 75 public: | |
| 76 ChangeList(); // For tests. | |
| 77 explicit ChangeList(const google_apis::ChangeList& change_list); | |
| 78 explicit ChangeList(const google_apis::FileList& file_list); | |
| 79 ~ChangeList(); | |
| 80 | |
| 81 const std::vector<ResourceEntry>& entries() const { return entries_; } | |
| 82 std::vector<ResourceEntry>* mutable_entries() { return &entries_; } | |
| 83 const std::vector<std::string>& parent_resource_ids() const { | |
| 84 return parent_resource_ids_; | |
| 85 } | |
| 86 std::vector<std::string>* mutable_parent_resource_ids() { | |
| 87 return &parent_resource_ids_; | |
| 88 } | |
| 89 const GURL& next_url() const { return next_url_; } | |
| 90 int64 largest_changestamp() const { return largest_changestamp_; } | |
| 91 | |
| 92 void set_largest_changestamp(int64 largest_changestamp) { | |
| 93 largest_changestamp_ = largest_changestamp; | |
| 94 } | |
| 95 | |
| 96 private: | |
| 97 std::vector<ResourceEntry> entries_; | |
| 98 std::vector<std::string> parent_resource_ids_; | |
| 99 GURL next_url_; | |
| 100 int64 largest_changestamp_; | |
| 101 | |
| 102 DISALLOW_COPY_AND_ASSIGN(ChangeList); | |
| 103 }; | |
| 104 | |
| 105 // ChangeListProcessor is used to process change lists, or full resource | |
| 106 // lists from WAPI (codename for Documents List API) or Google Drive API, and | |
| 107 // updates the resource metadata stored locally. | |
| 108 class ChangeListProcessor { | |
| 109 public: | |
| 110 ChangeListProcessor(ResourceMetadata* resource_metadata, | |
| 111 base::CancellationFlag* in_shutdown); | |
| 112 ~ChangeListProcessor(); | |
| 113 | |
| 114 // Applies change lists or full resource lists to |resource_metadata_|. | |
| 115 // | |
| 116 // |is_delta_update| determines the type of input data to process, whether | |
| 117 // it is full resource lists (false) or change lists (true). | |
| 118 // | |
| 119 // Must be run on the same task runner as |resource_metadata_| uses. | |
| 120 FileError Apply(scoped_ptr<google_apis::AboutResource> about_resource, | |
| 121 ScopedVector<ChangeList> change_lists, | |
| 122 bool is_delta_update); | |
| 123 | |
| 124 // The set of changed files as a result of change list processing. | |
| 125 const FileChange& changed_files() const { return *changed_files_; } | |
| 126 | |
| 127 // Adds or refreshes the child entries from |change_list| to the directory. | |
| 128 static FileError RefreshDirectory( | |
| 129 ResourceMetadata* resource_metadata, | |
| 130 const DirectoryFetchInfo& directory_fetch_info, | |
| 131 scoped_ptr<ChangeList> change_list, | |
| 132 std::vector<ResourceEntry>* out_refreshed_entries); | |
| 133 | |
| 134 // Sets |entry|'s parent_local_id. | |
| 135 static FileError SetParentLocalIdOfEntry( | |
| 136 ResourceMetadata* resource_metadata, | |
| 137 ResourceEntry* entry, | |
| 138 const std::string& parent_resource_id); | |
| 139 | |
| 140 private: | |
| 141 typedef std::map<std::string /* resource_id */, ResourceEntry> | |
| 142 ResourceEntryMap; | |
| 143 typedef std::map<std::string /* resource_id */, | |
| 144 std::string /* parent_resource_id*/> ParentResourceIdMap; | |
| 145 | |
| 146 // Applies the pre-processed metadata from entry_map_ onto the resource | |
| 147 // metadata. |about_resource| must not be null. | |
| 148 FileError ApplyEntryMap( | |
| 149 int64 changestamp, | |
| 150 scoped_ptr<google_apis::AboutResource> about_resource); | |
| 151 | |
| 152 // Apply |entry| to resource_metadata_. | |
| 153 FileError ApplyEntry(const ResourceEntry& entry); | |
| 154 | |
| 155 // Adds the directories changed by the update on |entry| to |changed_dirs_|. | |
| 156 void UpdateChangedDirs(const ResourceEntry& entry); | |
| 157 | |
| 158 ResourceMetadata* resource_metadata_; // Not owned. | |
| 159 base::CancellationFlag* in_shutdown_; // Not owned. | |
| 160 | |
| 161 ResourceEntryMap entry_map_; | |
| 162 ParentResourceIdMap parent_resource_id_map_; | |
| 163 scoped_ptr<FileChange> changed_files_; | |
| 164 | |
| 165 DISALLOW_COPY_AND_ASSIGN(ChangeListProcessor); | |
| 166 }; | |
| 167 | |
| 168 } // namespace internal | |
| 169 } // namespace drive | |
| 170 | |
| 171 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_CHANGE_LIST_PROCESSOR_H_ | |
| OLD | NEW |