Content settings: remove some plugin-related code/resources when... there are no...
[chromium-blink-merge.git] / components / drive / change_list_processor.h
blob86446ce321c4e191f122fc0715e7c9796b014ecc
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.
5 #ifndef COMPONENTS_DRIVE_CHANGE_LIST_PROCESSOR_H_
6 #define COMPONENTS_DRIVE_CHANGE_LIST_PROCESSOR_H_
8 #include <map>
9 #include <set>
10 #include <string>
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"
19 namespace base {
20 class CancellationFlag;
21 } // namespace base
23 namespace google_apis {
24 class AboutResource;
25 class ChangeList;
26 class FileList;
27 } // namespace google_apis
29 namespace drive {
31 class FileChange;
32 class ResourceEntry;
34 namespace internal {
36 class ResourceMetadata;
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) {
51 // Returns true if the object is empty.
52 bool empty() const { return local_id_.empty(); }
54 // Local ID of the directory.
55 const std::string& local_id() const { return local_id_; }
57 // Resource ID of the directory.
58 const std::string& resource_id() const { return resource_id_; }
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_; }
64 // Returns a string representation of this object.
65 std::string ToString() const;
67 private:
68 const std::string local_id_;
69 const std::string resource_id_;
70 const int64 changestamp_;
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();
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_;
86 std::vector<std::string>* mutable_parent_resource_ids() {
87 return &parent_resource_ids_;
89 const GURL& next_url() const { return next_url_; }
90 int64 largest_changestamp() const { return largest_changestamp_; }
92 void set_largest_changestamp(int64 largest_changestamp) {
93 largest_changestamp_ = largest_changestamp;
96 private:
97 std::vector<ResourceEntry> entries_;
98 std::vector<std::string> parent_resource_ids_;
99 GURL next_url_;
100 int64 largest_changestamp_;
102 DISALLOW_COPY_AND_ASSIGN(ChangeList);
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();
114 // Applies change lists or full resource lists to |resource_metadata_|.
116 // |is_delta_update| determines the type of input data to process, whether
117 // it is full resource lists (false) or change lists (true).
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);
124 // The set of changed files as a result of change list processing.
125 const FileChange& changed_files() const { return *changed_files_; }
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);
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);
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;
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);
152 // Apply |entry| to resource_metadata_.
153 FileError ApplyEntry(const ResourceEntry& entry);
155 // Adds the directories changed by the update on |entry| to |changed_dirs_|.
156 void UpdateChangedDirs(const ResourceEntry& entry);
158 ResourceMetadata* resource_metadata_; // Not owned.
159 base::CancellationFlag* in_shutdown_; // Not owned.
161 ResourceEntryMap entry_map_;
162 ParentResourceIdMap parent_resource_id_map_;
163 scoped_ptr<FileChange> changed_files_;
165 DISALLOW_COPY_AND_ASSIGN(ChangeListProcessor);
168 } // namespace internal
169 } // namespace drive
171 #endif // COMPONENTS_DRIVE_CHANGE_LIST_PROCESSOR_H_