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 #include "chrome/browser/extensions/api/downloads/downloads_api.h" | 5 #include "chrome/browser/extensions/api/downloads/downloads_api.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <memory> | 9 #include <memory> |
10 #include <set> | 10 #include <set> |
(...skipping 1806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1817 // json, set the differences in the |delta| object and remember that something | 1817 // json, set the differences in the |delta| object and remember that something |
1818 // significant changed. | 1818 // significant changed. |
1819 for (base::DictionaryValue::Iterator iter(*new_json); !iter.IsAtEnd(); | 1819 for (base::DictionaryValue::Iterator iter(*new_json); !iter.IsAtEnd(); |
1820 iter.Advance()) { | 1820 iter.Advance()) { |
1821 new_fields.insert(iter.key()); | 1821 new_fields.insert(iter.key()); |
1822 if (IsDownloadDeltaField(iter.key())) { | 1822 if (IsDownloadDeltaField(iter.key())) { |
1823 const base::Value* old_value = NULL; | 1823 const base::Value* old_value = NULL; |
1824 if (!data->json().HasKey(iter.key()) || | 1824 if (!data->json().HasKey(iter.key()) || |
1825 (data->json().Get(iter.key(), &old_value) && | 1825 (data->json().Get(iter.key(), &old_value) && |
1826 !iter.value().Equals(old_value))) { | 1826 !iter.value().Equals(old_value))) { |
1827 delta->Set(iter.key() + ".current", iter.value().DeepCopy()); | 1827 delta->Set(iter.key() + ".current", iter.value().CreateDeepCopy()); |
1828 if (old_value) | 1828 if (old_value) |
1829 delta->Set(iter.key() + ".previous", old_value->DeepCopy()); | 1829 delta->Set(iter.key() + ".previous", old_value->CreateDeepCopy()); |
1830 changed = true; | 1830 changed = true; |
1831 } | 1831 } |
1832 } | 1832 } |
1833 } | 1833 } |
1834 | 1834 |
1835 // If a field was in the previous json but is not in the new json, set the | 1835 // If a field was in the previous json but is not in the new json, set the |
1836 // difference in |delta|. | 1836 // difference in |delta|. |
1837 for (base::DictionaryValue::Iterator iter(data->json()); | 1837 for (base::DictionaryValue::Iterator iter(data->json()); |
1838 !iter.IsAtEnd(); iter.Advance()) { | 1838 !iter.IsAtEnd(); iter.Advance()) { |
1839 if ((new_fields.find(iter.key()) == new_fields.end()) && | 1839 if ((new_fields.find(iter.key()) == new_fields.end()) && |
1840 IsDownloadDeltaField(iter.key())) { | 1840 IsDownloadDeltaField(iter.key())) { |
1841 // estimatedEndTime disappears after completion, but bytesReceived stays. | 1841 // estimatedEndTime disappears after completion, but bytesReceived stays. |
1842 delta->Set(iter.key() + ".previous", iter.value().DeepCopy()); | 1842 delta->Set(iter.key() + ".previous", iter.value().CreateDeepCopy()); |
1843 changed = true; | 1843 changed = true; |
1844 } | 1844 } |
1845 } | 1845 } |
1846 | 1846 |
1847 // Update the OnChangedStat and dispatch the event if something significant | 1847 // Update the OnChangedStat and dispatch the event if something significant |
1848 // changed. Replace the stored json with the new json. | 1848 // changed. Replace the stored json with the new json. |
1849 data->OnItemUpdated(); | 1849 data->OnItemUpdated(); |
1850 if (changed) { | 1850 if (changed) { |
1851 DispatchEvent(events::DOWNLOADS_ON_CHANGED, | 1851 DispatchEvent(events::DOWNLOADS_ON_CHANGED, |
1852 downloads::OnChanged::kEventName, true, | 1852 downloads::OnChanged::kEventName, true, |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1920 return; | 1920 return; |
1921 base::Time now(base::Time::Now()); | 1921 base::Time now(base::Time::Now()); |
1922 int delta = now.ToTimeT() - last_checked_removal_.ToTimeT(); | 1922 int delta = now.ToTimeT() - last_checked_removal_.ToTimeT(); |
1923 if (delta <= kFileExistenceRateLimitSeconds) | 1923 if (delta <= kFileExistenceRateLimitSeconds) |
1924 return; | 1924 return; |
1925 last_checked_removal_ = now; | 1925 last_checked_removal_ = now; |
1926 manager->CheckForHistoryFilesRemoval(); | 1926 manager->CheckForHistoryFilesRemoval(); |
1927 } | 1927 } |
1928 | 1928 |
1929 } // namespace extensions | 1929 } // namespace extensions |
OLD | NEW |