| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "ios/chrome/browser/ui/webui/history/browsing_history_handler.h" | 5 #include "ios/chrome/browser/ui/webui/history/browsing_history_handler.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| (...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 794 void BrowsingHistoryHandler::SetQueryTimeInMonths( | 794 void BrowsingHistoryHandler::SetQueryTimeInMonths( |
| 795 int offset, | 795 int offset, |
| 796 history::QueryOptions* options) { | 796 history::QueryOptions* options) { |
| 797 // Configure the begin point of the search to the start of the | 797 // Configure the begin point of the search to the start of the |
| 798 // current month. | 798 // current month. |
| 799 base::Time::Exploded exploded; | 799 base::Time::Exploded exploded; |
| 800 base::Time::Now().LocalMidnight().LocalExplode(&exploded); | 800 base::Time::Now().LocalMidnight().LocalExplode(&exploded); |
| 801 exploded.day_of_month = 1; | 801 exploded.day_of_month = 1; |
| 802 | 802 |
| 803 if (offset == 0) { | 803 if (offset == 0) { |
| 804 options->begin_time = base::Time::FromLocalExploded(exploded); | 804 if (!base::Time::FromLocalExploded(exploded, &options->begin_time)) { |
| 805 // This file will be deprecated soon. No need to implement failure |
| 806 // handling here. |
| 807 NOTIMPLEMENTED(); |
| 808 } |
| 805 | 809 |
| 806 // Set the end time of this first search to null (which will | 810 // Set the end time of this first search to null (which will |
| 807 // show results from the future, should the user's clock have | 811 // show results from the future, should the user's clock have |
| 808 // been set incorrectly). | 812 // been set incorrectly). |
| 809 options->end_time = base::Time(); | 813 options->end_time = base::Time(); |
| 810 } else { | 814 } else { |
| 811 // Go back |offset| months in the past. The end time is not inclusive, so | 815 // Go back |offset| months in the past. The end time is not inclusive, so |
| 812 // use the first day of the |offset| - 1 and |offset| months (e.g. for | 816 // use the first day of the |offset| - 1 and |offset| months (e.g. for |
| 813 // the last month, |offset| = 1, use the first days of the last month and | 817 // the last month, |offset| = 1, use the first days of the last month and |
| 814 // the current month. | 818 // the current month. |
| 815 exploded.month -= offset - 1; | 819 exploded.month -= offset - 1; |
| 816 // Set the correct year. | 820 // Set the correct year. |
| 817 NormalizeMonths(&exploded); | 821 NormalizeMonths(&exploded); |
| 818 options->end_time = base::Time::FromLocalExploded(exploded); | 822 if (!base::Time::FromLocalExploded(exploded, &options->end_time)) { |
| 823 // This file will be deprecated soon. No need to implement failure |
| 824 // handling here. |
| 825 NOTIMPLEMENTED(); |
| 826 } |
| 819 | 827 |
| 820 exploded.month -= 1; | 828 exploded.month -= 1; |
| 821 // Set the correct year | 829 // Set the correct year |
| 822 NormalizeMonths(&exploded); | 830 NormalizeMonths(&exploded); |
| 823 options->begin_time = base::Time::FromLocalExploded(exploded); | 831 if (!base::Time::FromLocalExploded(exploded, &options->begin_time)) { |
| 832 // This file will be deprecated soon. No need to implement failure |
| 833 // handling here. |
| 834 NOTIMPLEMENTED(); |
| 835 } |
| 824 } | 836 } |
| 825 } | 837 } |
| 826 | 838 |
| 827 // Helper function for Observe that determines if there are any differences | 839 // Helper function for Observe that determines if there are any differences |
| 828 // between the URLs noticed for deletion and the ones we are expecting. | 840 // between the URLs noticed for deletion and the ones we are expecting. |
| 829 static bool DeletionsDiffer(const history::URLRows& deleted_rows, | 841 static bool DeletionsDiffer(const history::URLRows& deleted_rows, |
| 830 const std::set<GURL>& urls_to_be_deleted) { | 842 const std::set<GURL>& urls_to_be_deleted) { |
| 831 if (deleted_rows.size() != urls_to_be_deleted.size()) | 843 if (deleted_rows.size() != urls_to_be_deleted.size()) |
| 832 return true; | 844 return true; |
| 833 for (const auto& i : deleted_rows) { | 845 for (const auto& i : deleted_rows) { |
| 834 if (urls_to_be_deleted.find(i.url()) == urls_to_be_deleted.end()) | 846 if (urls_to_be_deleted.find(i.url()) == urls_to_be_deleted.end()) |
| 835 return true; | 847 return true; |
| 836 } | 848 } |
| 837 return false; | 849 return false; |
| 838 } | 850 } |
| 839 | 851 |
| 840 void BrowsingHistoryHandler::OnURLsDeleted( | 852 void BrowsingHistoryHandler::OnURLsDeleted( |
| 841 history::HistoryService* history_service, | 853 history::HistoryService* history_service, |
| 842 bool all_history, | 854 bool all_history, |
| 843 bool expired, | 855 bool expired, |
| 844 const history::URLRows& deleted_rows, | 856 const history::URLRows& deleted_rows, |
| 845 const std::set<GURL>& favicon_urls) { | 857 const std::set<GURL>& favicon_urls) { |
| 846 if (all_history || DeletionsDiffer(deleted_rows, urls_to_be_deleted_)) | 858 if (all_history || DeletionsDiffer(deleted_rows, urls_to_be_deleted_)) |
| 847 web_ui()->CallJavascriptFunction("historyDeleted"); | 859 web_ui()->CallJavascriptFunction("historyDeleted"); |
| 848 } | 860 } |
| OLD | NEW |