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

Side by Side Diff: chrome/browser/sync_file_system/drive_backend/metadata_database.cc

Issue 107743002: Add 'Dump Database' tab to syncfs-internals (only for v2 for now) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: regular -> Regular, added app_id Created 7 years 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/metadata_database.h" 5 #include "chrome/browser/sync_file_system/drive_backend/metadata_database.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <stack> 8 #include <stack>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 !current.active()) 749 !current.active())
750 return false; 750 return false;
751 } 751 }
752 752
753 if (path) 753 if (path)
754 *path = ReverseConcatPathComponents(components); 754 *path = ReverseConcatPathComponents(components);
755 755
756 return true; 756 return true;
757 } 757 }
758 758
759 base::FilePath MetadataDatabase::BuildDisplayPathForTracker(
760 const FileTracker& tracker) const {
761 base::FilePath path;
762 if (tracker.active()) {
763 BuildPathForTracker(tracker.tracker_id(), &path);
764 return path;
765 }
766 BuildPathForTracker(tracker.parent_tracker_id(), &path);
767 if (tracker.has_synced_details()) {
768 path = path.Append(
769 base::FilePath::FromUTF8Unsafe(tracker.synced_details().title()));
770 } else {
771 path = path.Append(FILE_PATH_LITERAL("<unknown>"));
772 }
773 return path;
774 }
775
759 bool MetadataDatabase::FindNearestActiveAncestor( 776 bool MetadataDatabase::FindNearestActiveAncestor(
760 const std::string& app_id, 777 const std::string& app_id,
761 const base::FilePath& full_path, 778 const base::FilePath& full_path,
762 FileTracker* tracker, 779 FileTracker* tracker,
763 base::FilePath* path) const { 780 base::FilePath* path) const {
764 DCHECK(tracker); 781 DCHECK(tracker);
765 DCHECK(path); 782 DCHECK(path);
766 783
767 if (full_path.IsAbsolute() || 784 if (full_path.IsAbsolute() ||
768 !FindAppRootTracker(app_id, tracker) || 785 !FindAppRootTracker(app_id, tracker) ||
(...skipping 971 matching lines...) Expand 10 before | Expand all | Expand 10 after
1740 std::back_inserter(stack)); 1757 std::back_inserter(stack));
1741 while (!stack.empty()) { 1758 while (!stack.empty()) {
1742 int64 tracker_id = stack.back(); 1759 int64 tracker_id = stack.back();
1743 stack.pop_back(); 1760 stack.pop_back();
1744 PushChildTrackersToContainer( 1761 PushChildTrackersToContainer(
1745 trackers_by_parent_and_title_, tracker_id, std::back_inserter(stack)); 1762 trackers_by_parent_and_title_, tracker_id, std::back_inserter(stack));
1746 1763
1747 FileTracker* tracker = tracker_by_id_[tracker_id]; 1764 FileTracker* tracker = tracker_by_id_[tracker_id];
1748 base::DictionaryValue* file = new DictionaryValue; 1765 base::DictionaryValue* file = new DictionaryValue;
1749 1766
1750 base::FilePath path; 1767 base::FilePath path = BuildDisplayPathForTracker(*tracker);
1751 if (tracker->active()) {
1752 BuildPathForTracker(tracker->tracker_id(), &path);
1753 } else {
1754 BuildPathForTracker(tracker->parent_tracker_id(), &path);
1755 if (tracker->has_synced_details()) {
1756 path = path.Append(
1757 base::FilePath::FromUTF8Unsafe(tracker->synced_details().title()));
1758 } else {
1759 path = path.Append(FILE_PATH_LITERAL("unknown"));
1760 }
1761 }
1762 file->SetString("path", path.AsUTF8Unsafe()); 1768 file->SetString("path", path.AsUTF8Unsafe());
1763 if (tracker->has_synced_details()) { 1769 if (tracker->has_synced_details()) {
1764 file->SetString("title", tracker->synced_details().title()); 1770 file->SetString("title", tracker->synced_details().title());
1765 file->SetString("type", 1771 file->SetString("type",
1766 FileKindToString(tracker->synced_details().file_kind())); 1772 FileKindToString(tracker->synced_details().file_kind()));
1767 } 1773 }
1768 1774
1769 base::DictionaryValue* details = new DictionaryValue; 1775 base::DictionaryValue* details = new DictionaryValue;
1770 details->SetString("file_id", tracker->file_id()); 1776 details->SetString("file_id", tracker->file_id());
1771 if (tracker->has_synced_details() && 1777 if (tracker->has_synced_details() &&
1772 tracker->synced_details().file_kind() == FILE_KIND_FILE) 1778 tracker->synced_details().file_kind() == FILE_KIND_FILE)
1773 details->SetString("md5", tracker->synced_details().md5()); 1779 details->SetString("md5", tracker->synced_details().md5());
1774 details->SetString("active", tracker->active() ? "true" : "false"); 1780 details->SetString("active", tracker->active() ? "true" : "false");
1775 details->SetString("dirty", tracker->dirty() ? "true" : "false"); 1781 details->SetString("dirty", tracker->dirty() ? "true" : "false");
1776 1782
1777 file->Set("details", details); 1783 file->Set("details", details);
1778 1784
1779 files->Append(file); 1785 files->Append(file);
1780 } 1786 }
1781 1787
1782 return files.Pass(); 1788 return files.Pass();
1783 } 1789 }
1784 1790
1791 scoped_ptr<base::ListValue> MetadataDatabase::DumpDatabase() {
1792 scoped_ptr<base::ListValue> list(new base::ListValue);
1793 list->Append(DumpTrackers().release());
1794 list->Append(DumpMetadata().release());
1795 return list.Pass();
1796 }
1797
1785 bool MetadataDatabase::HasNewerFileMetadata(const std::string& file_id, 1798 bool MetadataDatabase::HasNewerFileMetadata(const std::string& file_id,
1786 int64 change_id) { 1799 int64 change_id) {
1787 FileByID::const_iterator found = file_by_id_.find(file_id); 1800 FileByID::const_iterator found = file_by_id_.find(file_id);
1788 if (found == file_by_id_.end()) 1801 if (found == file_by_id_.end())
1789 return false; 1802 return false;
1790 DCHECK(found->second->has_details()); 1803 DCHECK(found->second->has_details());
1791 return found->second->details().change_id() >= change_id; 1804 return found->second->details().change_id() >= change_id;
1792 } 1805 }
1793 1806
1807 scoped_ptr<base::ListValue> MetadataDatabase::DumpTrackers() {
1808 scoped_ptr<base::ListValue> trackers(new base::ListValue);
1809
1810 // Append the first element for metadata.
1811 base::DictionaryValue* metadata = new DictionaryValue;
1812 const char *trackerKeys[] = {
1813 "tracker_id", "path", "file_id", "tracker_kind", "app_id",
1814 "active", "dirty", "folder_listing",
1815 "title", "kind", "md5", "etag", "missing", "change_id",
1816 };
1817 std::vector<std::string> key_strings(
1818 trackerKeys, trackerKeys + ARRAYSIZE_UNSAFE(trackerKeys));
1819 base::ListValue* keys = new ListValue;
1820 keys->AppendStrings(key_strings);
1821 metadata->SetString("title", "Trackers");
1822 metadata->Set("keys", keys);
1823 trackers->Append(metadata);
1824
1825 // Append tracker data.
1826 for (TrackerByID::const_iterator itr = tracker_by_id_.begin();
1827 itr != tracker_by_id_.end(); ++itr) {
1828 const FileTracker& tracker = *itr->second;
1829 base::DictionaryValue* dict = new DictionaryValue;
1830 base::FilePath path = BuildDisplayPathForTracker(tracker);
1831 dict->SetString("tracker_id", base::Int64ToString(tracker.tracker_id()));
1832 dict->SetString("path", path.AsUTF8Unsafe());
1833 dict->SetString("file_id", tracker.file_id());
1834 TrackerKind tracker_kind = tracker.tracker_kind();
1835 dict->SetString(
1836 "tracker_kind",
1837 tracker_kind == TRACKER_KIND_APP_ROOT ? "AppRoot" :
1838 tracker_kind == TRACKER_KIND_DISABLED_APP_ROOT ? "Disabled App" :
1839 tracker.tracker_id() == GetSyncRootTrackerID() ? "SyncRoot" :
1840 "Regular");
1841 dict->SetString("app_id", tracker.app_id());
1842 dict->SetString("active", tracker.active() ? "true" : "false");
1843 dict->SetString("dirty", tracker.dirty() ? "true" : "false");
1844 dict->SetString("folder_listing",
1845 tracker.needs_folder_listing() ? "needed" : "no");
1846 if (tracker.has_synced_details()) {
1847 const FileDetails& details = tracker.synced_details();
1848 dict->SetString("title", details.title());
1849 dict->SetString("kind", FileKindToString(details.file_kind()));
1850 dict->SetString("md5", details.md5());
1851 dict->SetString("etag", details.etag());
1852 dict->SetString("missing", details.missing() ? "true" : "false");
1853 dict->SetString("change_id", base::Int64ToString(details.change_id()));
1854 }
1855 trackers->Append(dict);
1856 }
1857 return trackers.Pass();
1858 }
1859
1860 scoped_ptr<base::ListValue> MetadataDatabase::DumpMetadata() {
1861 scoped_ptr<base::ListValue> files(new base::ListValue);
1862
1863 // Append the first element for metadata.
1864 base::DictionaryValue* metadata = new DictionaryValue;
1865 const char *fileKeys[] = {
1866 "file_id", "title", "type", "md5", "etag", "missing",
1867 "change_id", "parents"
1868 };
1869 std::vector<std::string> key_strings(
1870 fileKeys, fileKeys + ARRAYSIZE_UNSAFE(fileKeys));
1871 base::ListValue* keys = new ListValue;
1872 keys->AppendStrings(key_strings);
1873 metadata->SetString("title", "Metadata");
1874 metadata->Set("keys", keys);
1875 files->Append(metadata);
1876
1877 // Append metadata data.
1878 for (FileByID::const_iterator itr = file_by_id_.begin();
1879 itr != file_by_id_.end(); ++itr) {
1880 const FileMetadata& file = *itr->second;
1881
1882 base::DictionaryValue* dict = new DictionaryValue;
1883 dict->SetString("file_id", file.file_id());
1884 if (file.has_details()) {
1885 const FileDetails& details = file.details();
1886 dict->SetString("title", details.title());
1887 dict->SetString("type", FileKindToString(details.file_kind()));
1888 dict->SetString("md5", details.md5());
1889 dict->SetString("etag", details.etag());
1890 dict->SetString("missing", details.missing() ? "true" : "false");
1891 dict->SetString("change_id", base::Int64ToString(details.change_id()));
1892
1893 std::vector<std::string> parents;
1894 for (int i = 0; i < details.parent_folder_ids_size(); ++i)
1895 parents.push_back(details.parent_folder_ids(i));
1896 dict->SetString("parents", JoinString(parents, ","));
1897 }
1898 files->Append(dict);
1899 }
1900 return files.Pass();
1901 }
1902
1794 } // namespace drive_backend 1903 } // namespace drive_backend
1795 } // namespace sync_file_system 1904 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698