Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(391)

Side by Side Diff: chrome/browser/sync_file_system/drive_backend_v1/remote_change_handler.cc

Issue 442383002: Move storage-related files from webkit/ to new top-level directory storage/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include "chrome/browser/sync_file_system/drive_backend_v1/remote_change_handler .h" 5 #include "chrome/browser/sync_file_system/drive_backend_v1/remote_change_handler .h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "webkit/common/fileapi/file_system_util.h" 8 #include "storage/common/fileapi/file_system_util.h"
9 9
10 namespace sync_file_system { 10 namespace sync_file_system {
11 11
12 RemoteChangeHandler::ChangeQueueItem::ChangeQueueItem() 12 RemoteChangeHandler::ChangeQueueItem::ChangeQueueItem()
13 : changestamp(0) {} 13 : changestamp(0) {}
14 14
15 RemoteChangeHandler::ChangeQueueItem::ChangeQueueItem( 15 RemoteChangeHandler::ChangeQueueItem::ChangeQueueItem(
16 int64 changestamp, 16 int64 changestamp,
17 const fileapi::FileSystemURL& url) 17 const storage::FileSystemURL& url)
18 : changestamp(changestamp), url(url) {} 18 : changestamp(changestamp), url(url) {
19 }
19 20
20 bool RemoteChangeHandler::ChangeQueueComparator::operator()( 21 bool RemoteChangeHandler::ChangeQueueComparator::operator()(
21 const ChangeQueueItem& left, 22 const ChangeQueueItem& left,
22 const ChangeQueueItem& right) { 23 const ChangeQueueItem& right) {
23 if (left.changestamp != right.changestamp) 24 if (left.changestamp != right.changestamp)
24 return left.changestamp < right.changestamp; 25 return left.changestamp < right.changestamp;
25 return fileapi::FileSystemURL::Comparator()(left.url, right.url); 26 return storage::FileSystemURL::Comparator()(left.url, right.url);
26 } 27 }
27 28
28 RemoteChangeHandler::RemoteChange::RemoteChange() 29 RemoteChangeHandler::RemoteChange::RemoteChange()
29 : changestamp(0), 30 : changestamp(0),
30 change(FileChange::FILE_CHANGE_ADD_OR_UPDATE, SYNC_FILE_TYPE_UNKNOWN) {} 31 change(FileChange::FILE_CHANGE_ADD_OR_UPDATE, SYNC_FILE_TYPE_UNKNOWN) {}
31 32
32 RemoteChangeHandler::RemoteChange::RemoteChange( 33 RemoteChangeHandler::RemoteChange::RemoteChange(
33 int64 changestamp, 34 int64 changestamp,
34 const std::string& resource_id, 35 const std::string& resource_id,
35 const std::string& md5_checksum, 36 const std::string& md5_checksum,
36 const base::Time& updated_time, 37 const base::Time& updated_time,
37 const fileapi::FileSystemURL& url, 38 const storage::FileSystemURL& url,
38 const FileChange& change) 39 const FileChange& change)
39 : changestamp(changestamp), 40 : changestamp(changestamp),
40 resource_id(resource_id), 41 resource_id(resource_id),
41 md5_checksum(md5_checksum), 42 md5_checksum(md5_checksum),
42 updated_time(updated_time), 43 updated_time(updated_time),
43 url(url), 44 url(url),
44 change(change) {} 45 change(change) {
46 }
45 47
46 RemoteChangeHandler::RemoteChange::~RemoteChange() {} 48 RemoteChangeHandler::RemoteChange::~RemoteChange() {}
47 49
48 bool RemoteChangeHandler::RemoteChangeComparator::operator()( 50 bool RemoteChangeHandler::RemoteChangeComparator::operator()(
49 const RemoteChange& left, 51 const RemoteChange& left,
50 const RemoteChange& right) { 52 const RemoteChange& right) {
51 // This should return true if |right| has higher priority than |left|. 53 // This should return true if |right| has higher priority than |left|.
52 // Smaller changestamps have higher priorities (i.e. need to be processed 54 // Smaller changestamps have higher priorities (i.e. need to be processed
53 // earlier). 55 // earlier).
54 if (left.changestamp != right.changestamp) 56 if (left.changestamp != right.changestamp)
55 return left.changestamp > right.changestamp; 57 return left.changestamp > right.changestamp;
56 return false; 58 return false;
57 } 59 }
58 60
59 RemoteChangeHandler::RemoteChangeHandler() {} 61 RemoteChangeHandler::RemoteChangeHandler() {}
60 62
61 RemoteChangeHandler::~RemoteChangeHandler() {} 63 RemoteChangeHandler::~RemoteChangeHandler() {}
62 64
63 bool RemoteChangeHandler::GetChange(RemoteChange* remote_change) { 65 bool RemoteChangeHandler::GetChange(RemoteChange* remote_change) {
64 const fileapi::FileSystemURL& url = changes_.begin()->url; 66 const storage::FileSystemURL& url = changes_.begin()->url;
65 const base::FilePath::StringType& normalized_path = 67 const base::FilePath::StringType& normalized_path =
66 fileapi::VirtualPath::GetNormalizedFilePath(url.path()); 68 storage::VirtualPath::GetNormalizedFilePath(url.path());
67 DCHECK(ContainsKey(origin_to_changes_map_, url.origin())); 69 DCHECK(ContainsKey(origin_to_changes_map_, url.origin()));
68 PathToChangeMap* path_to_change = &origin_to_changes_map_[url.origin()]; 70 PathToChangeMap* path_to_change = &origin_to_changes_map_[url.origin()];
69 DCHECK(ContainsKey(*path_to_change, normalized_path)); 71 DCHECK(ContainsKey(*path_to_change, normalized_path));
70 *remote_change = (*path_to_change)[normalized_path].remote_change; 72 *remote_change = (*path_to_change)[normalized_path].remote_change;
71 return true; 73 return true;
72 } 74 }
73 75
74 bool RemoteChangeHandler::GetChangeForURL( 76 bool RemoteChangeHandler::GetChangeForURL(const storage::FileSystemURL& url,
75 const fileapi::FileSystemURL& url, 77 RemoteChange* remote_change) {
76 RemoteChange* remote_change) {
77 OriginToChangesMap::iterator found_origin = 78 OriginToChangesMap::iterator found_origin =
78 origin_to_changes_map_.find(url.origin()); 79 origin_to_changes_map_.find(url.origin());
79 if (found_origin == origin_to_changes_map_.end()) 80 if (found_origin == origin_to_changes_map_.end())
80 return false; 81 return false;
81 82
82 PathToChangeMap* path_to_change = &found_origin->second; 83 PathToChangeMap* path_to_change = &found_origin->second;
83 PathToChangeMap::iterator found_change = path_to_change->find( 84 PathToChangeMap::iterator found_change = path_to_change->find(
84 fileapi::VirtualPath::GetNormalizedFilePath(url.path())); 85 storage::VirtualPath::GetNormalizedFilePath(url.path()));
85 if (found_change == path_to_change->end()) 86 if (found_change == path_to_change->end())
86 return false; 87 return false;
87 88
88 *remote_change = found_change->second.remote_change; 89 *remote_change = found_change->second.remote_change;
89 return true; 90 return true;
90 } 91 }
91 92
92 void RemoteChangeHandler::AppendChange(const RemoteChange& remote_change) { 93 void RemoteChangeHandler::AppendChange(const RemoteChange& remote_change) {
93 base::FilePath::StringType normalized_path = 94 base::FilePath::StringType normalized_path =
94 fileapi::VirtualPath::GetNormalizedFilePath(remote_change.url.path()); 95 storage::VirtualPath::GetNormalizedFilePath(remote_change.url.path());
95 96
96 PathToChangeMap* path_to_change = 97 PathToChangeMap* path_to_change =
97 &origin_to_changes_map_[remote_change.url.origin()]; 98 &origin_to_changes_map_[remote_change.url.origin()];
98 PathToChangeMap::iterator found = path_to_change->find(normalized_path); 99 PathToChangeMap::iterator found = path_to_change->find(normalized_path);
99 100
100 // Remove an existing change for |remote_change.url.path()|. 101 // Remove an existing change for |remote_change.url.path()|.
101 if (found != path_to_change->end()) 102 if (found != path_to_change->end())
102 changes_.erase(found->second.position_in_queue); 103 changes_.erase(found->second.position_in_queue);
103 104
104 std::pair<PendingChangeQueue::iterator, bool> inserted_to_queue = 105 std::pair<PendingChangeQueue::iterator, bool> inserted_to_queue =
105 changes_.insert(ChangeQueueItem(remote_change.changestamp, 106 changes_.insert(ChangeQueueItem(remote_change.changestamp,
106 remote_change.url)); 107 remote_change.url));
107 DCHECK(inserted_to_queue.second); 108 DCHECK(inserted_to_queue.second);
108 109
109 (*path_to_change)[normalized_path] = 110 (*path_to_change)[normalized_path] =
110 ChangeMapItem(remote_change, inserted_to_queue.first); 111 ChangeMapItem(remote_change, inserted_to_queue.first);
111 } 112 }
112 113
113 bool RemoteChangeHandler::RemoveChangeForURL( 114 bool RemoteChangeHandler::RemoveChangeForURL(
114 const fileapi::FileSystemURL& url) { 115 const storage::FileSystemURL& url) {
115 OriginToChangesMap::iterator found_origin = 116 OriginToChangesMap::iterator found_origin =
116 origin_to_changes_map_.find(url.origin()); 117 origin_to_changes_map_.find(url.origin());
117 if (found_origin == origin_to_changes_map_.end()) 118 if (found_origin == origin_to_changes_map_.end())
118 return false; 119 return false;
119 120
120 PathToChangeMap* path_to_change = &found_origin->second; 121 PathToChangeMap* path_to_change = &found_origin->second;
121 PathToChangeMap::iterator found_change = path_to_change->find( 122 PathToChangeMap::iterator found_change = path_to_change->find(
122 fileapi::VirtualPath::GetNormalizedFilePath(url.path())); 123 storage::VirtualPath::GetNormalizedFilePath(url.path()));
123 if (found_change == path_to_change->end()) 124 if (found_change == path_to_change->end())
124 return false; 125 return false;
125 126
126 changes_.erase(found_change->second.position_in_queue); 127 changes_.erase(found_change->second.position_in_queue);
127 path_to_change->erase(found_change); 128 path_to_change->erase(found_change);
128 if (path_to_change->empty()) 129 if (path_to_change->empty())
129 origin_to_changes_map_.erase(found_origin); 130 origin_to_changes_map_.erase(found_origin);
130 return true; 131 return true;
131 } 132 }
132 133
(...skipping 15 matching lines...) Expand all
148 149
149 RemoteChangeHandler::ChangeMapItem::ChangeMapItem( 150 RemoteChangeHandler::ChangeMapItem::ChangeMapItem(
150 const RemoteChange& remote_change, 151 const RemoteChange& remote_change,
151 PendingChangeQueue::iterator position_in_queue) 152 PendingChangeQueue::iterator position_in_queue)
152 : remote_change(remote_change), 153 : remote_change(remote_change),
153 position_in_queue(position_in_queue) {} 154 position_in_queue(position_in_queue) {}
154 155
155 RemoteChangeHandler::ChangeMapItem::~ChangeMapItem() {} 156 RemoteChangeHandler::ChangeMapItem::~ChangeMapItem() {}
156 157
157 } // namespace sync_file_system 158 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698