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

Side by Side Diff: webkit/fileapi/syncable/file_change.cc

Issue 15806012: Move webkit/fileapi/syncable/* code to webkit/browser/fileapi (final!) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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
« no previous file with comments | « webkit/fileapi/syncable/file_change.h ('k') | webkit/fileapi/syncable/file_change_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 #include <sstream>
6
7 #include "base/stringprintf.h"
8 #include "webkit/fileapi/syncable/file_change.h"
9
10 #include "base/logging.h"
11
12 namespace sync_file_system {
13
14 FileChange::FileChange(
15 ChangeType change,
16 SyncFileType file_type)
17 : change_(change),
18 file_type_(file_type) {}
19
20 std::string FileChange::DebugString() const {
21 const char* change_string = NULL;
22 switch (change()) {
23 case FILE_CHANGE_ADD_OR_UPDATE:
24 change_string = "ADD_OR_UPDATE";
25 break;
26 case FILE_CHANGE_DELETE:
27 change_string = "DELETE";
28 break;
29 }
30 const char* type_string = "UNKNOWN";
31 switch (file_type()) {
32 case SYNC_FILE_TYPE_FILE:
33 type_string = "FILE";
34 break;
35 case SYNC_FILE_TYPE_DIRECTORY:
36 type_string = "DIRECTORY";
37 break;
38 case SYNC_FILE_TYPE_UNKNOWN:
39 type_string = "UNKNOWN";
40 break;
41 }
42 return base::StringPrintf("%s:%s", change_string, type_string);
43 }
44
45 FileChangeList::FileChangeList() {}
46 FileChangeList::~FileChangeList() {}
47
48 void FileChangeList::Update(const FileChange& new_change) {
49 if (list_.empty()) {
50 list_.push_back(new_change);
51 return;
52 }
53
54 FileChange& last = list_.back();
55 if (last.IsFile() != new_change.IsFile()) {
56 list_.push_back(new_change);
57 return;
58 }
59
60 if (last.change() == new_change.change())
61 return;
62
63 // ADD + DELETE on directory -> revert
64 if (!last.IsFile() && last.IsAddOrUpdate() && new_change.IsDelete()) {
65 list_.pop_back();
66 return;
67 }
68
69 // DELETE + ADD/UPDATE -> ADD/UPDATE
70 // ADD/UPDATE + DELETE -> DELETE
71 last = new_change;
72 }
73
74 FileChangeList FileChangeList::PopAndGetNewList() const {
75 FileChangeList changes;
76 changes.list_ = this->list_;
77 changes.list_.pop_front();
78 return changes;
79 }
80
81 std::string FileChangeList::DebugString() const {
82 std::ostringstream ss;
83 ss << "{ ";
84 for (size_t i = 0; i < list_.size(); ++i)
85 ss << list_[i].DebugString() << ", ";
86 ss << "}";
87 return ss.str();
88 }
89
90 } // namespace sync_file_system
OLDNEW
« no previous file with comments | « webkit/fileapi/syncable/file_change.h ('k') | webkit/fileapi/syncable/file_change_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698