| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/ui/webui/browsing_history_handler.h" | 5 #include "chrome/browser/ui/webui/browsing_history_handler.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 887 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 898 | 898 |
| 899 void BrowsingHistoryHandler::SetQueryTimeInMonths( | 899 void BrowsingHistoryHandler::SetQueryTimeInMonths( |
| 900 int offset, history::QueryOptions* options) { | 900 int offset, history::QueryOptions* options) { |
| 901 // Configure the begin point of the search to the start of the | 901 // Configure the begin point of the search to the start of the |
| 902 // current month. | 902 // current month. |
| 903 base::Time::Exploded exploded; | 903 base::Time::Exploded exploded; |
| 904 base::Time::Now().LocalMidnight().LocalExplode(&exploded); | 904 base::Time::Now().LocalMidnight().LocalExplode(&exploded); |
| 905 exploded.day_of_month = 1; | 905 exploded.day_of_month = 1; |
| 906 | 906 |
| 907 if (offset == 0) { | 907 if (offset == 0) { |
| 908 options->begin_time = base::Time::FromLocalExploded(exploded); | 908 if (!base::Time::FromLocalExploded(exploded, &options->begin_time)) { |
| 909 // TODO(maksims): implement errors handling here. |
| 910 NOTIMPLEMENTED(); |
| 911 } |
| 909 | 912 |
| 910 // Set the end time of this first search to null (which will | 913 // Set the end time of this first search to null (which will |
| 911 // show results from the future, should the user's clock have | 914 // show results from the future, should the user's clock have |
| 912 // been set incorrectly). | 915 // been set incorrectly). |
| 913 options->end_time = base::Time(); | 916 options->end_time = base::Time(); |
| 914 } else { | 917 } else { |
| 915 // Go back |offset| months in the past. The end time is not inclusive, so | 918 // Go back |offset| months in the past. The end time is not inclusive, so |
| 916 // use the first day of the |offset| - 1 and |offset| months (e.g. for | 919 // use the first day of the |offset| - 1 and |offset| months (e.g. for |
| 917 // the last month, |offset| = 1, use the first days of the last month and | 920 // the last month, |offset| = 1, use the first days of the last month and |
| 918 // the current month. | 921 // the current month. |
| 919 exploded.month -= offset - 1; | 922 exploded.month -= offset - 1; |
| 920 // Set the correct year. | 923 // Set the correct year. |
| 921 NormalizeMonths(&exploded); | 924 NormalizeMonths(&exploded); |
| 922 options->end_time = base::Time::FromLocalExploded(exploded); | 925 if (!base::Time::FromLocalExploded(exploded, &options->begin_time)) { |
| 926 // TODO(maksims): implement errors handling here. |
| 927 NOTIMPLEMENTED(); |
| 928 } |
| 923 | 929 |
| 924 exploded.month -= 1; | 930 exploded.month -= 1; |
| 925 // Set the correct year | 931 // Set the correct year |
| 926 NormalizeMonths(&exploded); | 932 NormalizeMonths(&exploded); |
| 927 options->begin_time = base::Time::FromLocalExploded(exploded); | 933 if (!base::Time::FromLocalExploded(exploded, &options->begin_time)) { |
| 934 // TODO(maksims): implement errors handling here. |
| 935 NOTIMPLEMENTED(); |
| 936 } |
| 928 } | 937 } |
| 929 } | 938 } |
| 930 | 939 |
| 931 // Helper function for Observe that determines if there are any differences | 940 // Helper function for Observe that determines if there are any differences |
| 932 // between the URLs noticed for deletion and the ones we are expecting. | 941 // between the URLs noticed for deletion and the ones we are expecting. |
| 933 static bool DeletionsDiffer(const history::URLRows& deleted_rows, | 942 static bool DeletionsDiffer(const history::URLRows& deleted_rows, |
| 934 const std::set<GURL>& urls_to_be_deleted) { | 943 const std::set<GURL>& urls_to_be_deleted) { |
| 935 if (deleted_rows.size() != urls_to_be_deleted.size()) | 944 if (deleted_rows.size() != urls_to_be_deleted.size()) |
| 936 return true; | 945 return true; |
| 937 for (const auto& i : deleted_rows) { | 946 for (const auto& i : deleted_rows) { |
| 938 if (urls_to_be_deleted.find(i.url()) == urls_to_be_deleted.end()) | 947 if (urls_to_be_deleted.find(i.url()) == urls_to_be_deleted.end()) |
| 939 return true; | 948 return true; |
| 940 } | 949 } |
| 941 return false; | 950 return false; |
| 942 } | 951 } |
| 943 | 952 |
| 944 void BrowsingHistoryHandler::OnURLsDeleted( | 953 void BrowsingHistoryHandler::OnURLsDeleted( |
| 945 history::HistoryService* history_service, | 954 history::HistoryService* history_service, |
| 946 bool all_history, | 955 bool all_history, |
| 947 bool expired, | 956 bool expired, |
| 948 const history::URLRows& deleted_rows, | 957 const history::URLRows& deleted_rows, |
| 949 const std::set<GURL>& favicon_urls) { | 958 const std::set<GURL>& favicon_urls) { |
| 950 if (all_history || DeletionsDiffer(deleted_rows, urls_to_be_deleted_)) | 959 if (all_history || DeletionsDiffer(deleted_rows, urls_to_be_deleted_)) |
| 951 web_ui()->CallJavascriptFunctionUnsafe("historyDeleted"); | 960 web_ui()->CallJavascriptFunctionUnsafe("historyDeleted"); |
| 952 } | 961 } |
| OLD | NEW |