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

Unified Diff: chrome/browser/ui/webui/history_ui.cc

Issue 11886104: History: Add range navigation control for grouped visits (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Replies to comments. Created 7 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/history_ui.cc
diff --git a/chrome/browser/ui/webui/history_ui.cc b/chrome/browser/ui/webui/history_ui.cc
index dff2bfd4de845584e6523284293e5705f1fc2dd2..af12d69699e07d1ac53cb931ad39a01242c5ba76 100644
--- a/chrome/browser/ui/webui/history_ui.cc
+++ b/chrome/browser/ui/webui/history_ui.cc
@@ -142,7 +142,7 @@ content::WebUIDataSource* CreateHistoryUIHTMLSource() {
source->AddLocalizedString("rangenone", IDS_HISTORY_RANGE_NONE);
source->AddLocalizedString("rangeweek", IDS_HISTORY_RANGE_WEEK);
source->AddLocalizedString("rangemonth", IDS_HISTORY_RANGE_MONTH);
- source->AddLocalizedString("displayfiltersites", IDS_GROUP_BY_DOMAIN_LABEL);
+ source->AddLocalizedString("rangetoday", IDS_HISTORY_RANGE_TODAY);
source->AddLocalizedString("numbervisits", IDS_HISTORY_NUMBER_VISITS);
source->AddBoolean("groupByDomain",
CommandLine::ForCurrentProcess()->HasSwitch(
@@ -172,6 +172,15 @@ string16 getRelativeDateLocalized(const base::Time& visit_time) {
return date_str;
}
+// Sets the correct year when substracting months from a date.
+void normalizeMonths(base::Time::Exploded* exploded) {
+ // Decrease a year at a time until we have a proper date.
+ while (exploded->month < 1) {
+ exploded->month += 12;
+ exploded->year--;
+ }
+}
+
} // namespace
////////////////////////////////////////////////////////////////////////////////
@@ -267,6 +276,7 @@ void BrowsingHistoryHandler::HandleQueryHistory(const ListValue* args) {
// Parse the arguments from JavaScript. There are four required arguments:
// - the text to search for (may be empty)
+ // - the offset from which the search should start in multiple of the range.
// - the range (number) of days to search for, used only for grouped
// searches.
// - the search cursor, an opaque value from a previous query result, which
@@ -275,18 +285,23 @@ void BrowsingHistoryHandler::HandleQueryHistory(const ListValue* args) {
// - the maximum number of results to return (may be 0, meaning that there
// is no maximum).
string16 search_text = ExtractStringValue(args);
- int range;
- if (!args->GetInteger(1, &range)) {
+ int offset;
+ if (!args->GetInteger(1, &offset)) {
NOTREACHED() << "Failed to convert argument 1. ";
return;
}
+ int range;
+ if (!args->GetInteger(2, &range)) {
+ NOTREACHED() << "Failed to convert argument 2. ";
+ return;
+ }
switch (range) {
case BrowsingHistoryHandler::MONTH:
- SetQueryTimeInMonths(&options);
+ SetQueryTimeInMonths(offset, &options);
break;
case BrowsingHistoryHandler::WEEK:
- SetQueryTimeInWeeks(&options);
+ SetQueryTimeInWeeks(offset, &options);
break;
case BrowsingHistoryHandler::NOT_GROUPED:
break;
@@ -295,15 +310,15 @@ void BrowsingHistoryHandler::HandleQueryHistory(const ListValue* args) {
const Value* cursor_value;
// Get the cursor. It must be either null, or a list.
- if (!args->Get(2, &cursor_value) ||
+ if (!args->Get(3, &cursor_value) ||
(!cursor_value->IsType(Value::TYPE_NULL) &&
!history::QueryCursor::FromValue(cursor_value, &options.cursor))) {
- NOTREACHED() << "Failed to convert argument 2. ";
+ NOTREACHED() << "Failed to convert argument 3. ";
return;
}
- if (!ExtractIntegerValueAtIndex(args, 3, &options.max_count)) {
- NOTREACHED() << "Failed to convert argument 3.";
+ if (!ExtractIntegerValueAtIndex(args, 4, &options.max_count)) {
+ NOTREACHED() << "Failed to convert argument 4.";
return;
}
@@ -541,28 +556,47 @@ void BrowsingHistoryHandler::RemoveWebHistoryComplete(
}
void BrowsingHistoryHandler::SetQueryTimeInWeeks(
- history::QueryOptions* options) {
+ int offset, history::QueryOptions* options) {
// LocalMidnight returns the beginning of the current day so get the
// beginning of the next one.
base::Time midnight = base::Time::Now().LocalMidnight() +
base::TimeDelta::FromDays(1);
- options->end_time = midnight;
- options->begin_time = midnight - base::TimeDelta::FromDays(7);
+ options->end_time = midnight -
+ base::TimeDelta::FromDays(7 * offset);
+ options->begin_time = midnight -
+ base::TimeDelta::FromDays(7 * (offset + 1));
}
void BrowsingHistoryHandler::SetQueryTimeInMonths(
- history::QueryOptions* options) {
+ int offset, history::QueryOptions* options) {
// Configure the begin point of the search to the start of the
// current month.
base::Time::Exploded exploded;
base::Time::Now().LocalMidnight().LocalExplode(&exploded);
exploded.day_of_month = 1;
- options->begin_time = base::Time::FromLocalExploded(exploded);
- // Set the end time of this first search to null (which will
- // show results from the future, should the user's clock have
- // been set incorrectly).
- options->end_time = base::Time();
+ if (offset == 0) {
+ options->begin_time = base::Time::FromLocalExploded(exploded);
+
+ // Set the end time of this first search to null (which will
+ // show results from the future, should the user's clock have
+ // been set incorrectly).
+ options->end_time = base::Time();
+ } else {
+ // Go back |offset| months in the past. The end time is not inclusive, so
+ // use the first day of the |offset| - 1 and |offset| months (e.g. for
+ // the last month, |offset| = 1, use the first days of the last month and
+ // the current month.
+ exploded.month -= offset - 1;
+ // Set the correct year.
+ normalizeMonths(&exploded);
+ options->end_time = base::Time::FromLocalExploded(exploded);
+
+ exploded.month -= 1;
+ // Set the correct year
+ normalizeMonths(&exploded);
+ options->begin_time = base::Time::FromLocalExploded(exploded);
+ }
}
// Helper function for Observe that determines if there are any differences
« chrome/browser/resources/history/history.js ('K') | « chrome/browser/ui/webui/history_ui.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698