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_DRIVE_CHANGE_LIST_PROCESSOR_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_CHANGE_LIST_PROCESSOR_H_ |
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_CHANGE_LIST_PROCESSOR_H_ | 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_CHANGE_LIST_PROCESSOR_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 10 matching lines...) Expand all Loading... |
21 } // google_apis | 21 } // google_apis |
22 | 22 |
23 namespace drive { | 23 namespace drive { |
24 | 24 |
25 class ResourceEntry; | 25 class ResourceEntry; |
26 | 26 |
27 namespace internal { | 27 namespace internal { |
28 | 28 |
29 class ResourceMetadata; | 29 class ResourceMetadata; |
30 | 30 |
| 31 // Holds information needed to fetch contents of a directory. |
| 32 // This object is copyable. |
| 33 class DirectoryFetchInfo { |
| 34 public: |
| 35 DirectoryFetchInfo() : changestamp_(0) {} |
| 36 DirectoryFetchInfo(const std::string& resource_id, |
| 37 int64 changestamp) |
| 38 : resource_id_(resource_id), |
| 39 changestamp_(changestamp) { |
| 40 } |
| 41 |
| 42 // Returns true if the object is empty. |
| 43 bool empty() const { return resource_id_.empty(); } |
| 44 |
| 45 // Resource ID of the directory. |
| 46 const std::string& resource_id() const { return resource_id_; } |
| 47 |
| 48 // Changestamp of the directory. The changestamp is used to determine if |
| 49 // the directory contents should be fetched. |
| 50 int64 changestamp() const { return changestamp_; } |
| 51 |
| 52 // Returns a string representation of this object. |
| 53 std::string ToString() const; |
| 54 |
| 55 private: |
| 56 const std::string resource_id_; |
| 57 const int64 changestamp_; |
| 58 }; |
| 59 |
31 // Class to represent a change list. | 60 // Class to represent a change list. |
32 class ChangeList { | 61 class ChangeList { |
33 public: | 62 public: |
34 explicit ChangeList(const google_apis::ResourceList& resource_list); | 63 explicit ChangeList(const google_apis::ResourceList& resource_list); |
35 ~ChangeList(); | 64 ~ChangeList(); |
36 | 65 |
37 const std::vector<ResourceEntry>& entries() const { return entries_; } | 66 const std::vector<ResourceEntry>& entries() const { return entries_; } |
38 std::vector<ResourceEntry>* mutable_entries() { return &entries_; } | 67 std::vector<ResourceEntry>* mutable_entries() { return &entries_; } |
39 const GURL& next_url() const { return next_url_; } | 68 const GURL& next_url() const { return next_url_; } |
40 int64 largest_changestamp() const { return largest_changestamp_; } | 69 int64 largest_changestamp() const { return largest_changestamp_; } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 | 104 |
76 // Converts change lists into a ResourceEntryMap. | 105 // Converts change lists into a ResourceEntryMap. |
77 // |uma_stats| may be NULL. | 106 // |uma_stats| may be NULL. |
78 static void ConvertToMap(ScopedVector<ChangeList> change_lists, | 107 static void ConvertToMap(ScopedVector<ChangeList> change_lists, |
79 ResourceEntryMap* entry_map, | 108 ResourceEntryMap* entry_map, |
80 ChangeListToEntryMapUMAStats* uma_stats); | 109 ChangeListToEntryMapUMAStats* uma_stats); |
81 | 110 |
82 // The set of changed directories as a result of change list processing. | 111 // The set of changed directories as a result of change list processing. |
83 const std::set<base::FilePath>& changed_dirs() const { return changed_dirs_; } | 112 const std::set<base::FilePath>& changed_dirs() const { return changed_dirs_; } |
84 | 113 |
| 114 // Updates the changestamp of a directory according to |directory_fetch_info| |
| 115 // and adds or refreshes the child entries from |entry_map|. |
| 116 static FileError RefreshDirectory( |
| 117 ResourceMetadata* resource_metadata, |
| 118 const DirectoryFetchInfo& directory_fetch_info, |
| 119 const ResourceEntryMap& entry_map, |
| 120 base::FilePath* out_file_path); |
| 121 |
85 private: | 122 private: |
86 // Applies the pre-processed metadata from entry_map_ onto the resource | 123 // Applies the pre-processed metadata from entry_map_ onto the resource |
87 // metadata. If this is not delta update (i.e. |is_delta_update| is false), | 124 // metadata. If this is not delta update (i.e. |is_delta_update| is false), |
88 // |about_resource| must not be null. | 125 // |about_resource| must not be null. |
89 void ApplyEntryMap(bool is_delta_update, | 126 void ApplyEntryMap(bool is_delta_update, |
90 scoped_ptr<google_apis::AboutResource> about_resource); | 127 scoped_ptr<google_apis::AboutResource> about_resource); |
91 | 128 |
92 // Apply the next item from entry_map_ to the file system. The async | 129 // Apply the next item from entry_map_ to the file system. The async |
93 // version posts to the message loop to avoid recursive stack-overflow. | 130 // version posts to the message loop to avoid recursive stack-overflow. |
94 void ApplyNextEntry(); | 131 void ApplyNextEntry(); |
(...skipping 24 matching lines...) Expand all Loading... |
119 ResourceEntryMap entry_map_; | 156 ResourceEntryMap entry_map_; |
120 std::set<base::FilePath> changed_dirs_; | 157 std::set<base::FilePath> changed_dirs_; |
121 | 158 |
122 DISALLOW_COPY_AND_ASSIGN(ChangeListProcessor); | 159 DISALLOW_COPY_AND_ASSIGN(ChangeListProcessor); |
123 }; | 160 }; |
124 | 161 |
125 } // namespace internal | 162 } // namespace internal |
126 } // namespace drive | 163 } // namespace drive |
127 | 164 |
128 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_CHANGE_LIST_PROCESSOR_H_ | 165 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_CHANGE_LIST_PROCESSOR_H_ |
OLD | NEW |