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

Side by Side 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: Rebase 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/ui/webui/history_ui.h" 5 #include "chrome/browser/ui/webui/history_ui.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 source->AddString( 133 source->AddString(
134 "deletewarning", 134 "deletewarning",
135 l10n_util::GetStringFUTF16(IDS_HISTORY_DELETE_PRIOR_VISITS_WARNING, 135 l10n_util::GetStringFUTF16(IDS_HISTORY_DELETE_PRIOR_VISITS_WARNING,
136 UTF8ToUTF16(kIncognitoModeShortcut))); 136 UTF8ToUTF16(kIncognitoModeShortcut)));
137 source->AddLocalizedString("actionMenuDescription", 137 source->AddLocalizedString("actionMenuDescription",
138 IDS_HISTORY_ACTION_MENU_DESCRIPTION); 138 IDS_HISTORY_ACTION_MENU_DESCRIPTION);
139 source->AddLocalizedString("removeFromHistory", IDS_HISTORY_REMOVE_PAGE); 139 source->AddLocalizedString("removeFromHistory", IDS_HISTORY_REMOVE_PAGE);
140 source->AddLocalizedString("moreFromSite", IDS_HISTORY_MORE_FROM_SITE); 140 source->AddLocalizedString("moreFromSite", IDS_HISTORY_MORE_FROM_SITE);
141 source->AddLocalizedString("rangeweek", IDS_HISTORY_RANGE_WEEK); 141 source->AddLocalizedString("rangeweek", IDS_HISTORY_RANGE_WEEK);
142 source->AddLocalizedString("rangemonth", IDS_HISTORY_RANGE_MONTH); 142 source->AddLocalizedString("rangemonth", IDS_HISTORY_RANGE_MONTH);
143 source->AddLocalizedString("rangetoday", IDS_HISTORY_RANGE_TODAY);
143 source->AddLocalizedString("displayfiltersites", 144 source->AddLocalizedString("displayfiltersites",
144 IDS_HISTORY_DISPLAY_FILTER_SITES); 145 IDS_HISTORY_DISPLAY_FILTER_SITES);
145 source->AddLocalizedString("numbervisits", IDS_HISTORY_NUMBER_VISITS); 146 source->AddLocalizedString("numbervisits", IDS_HISTORY_NUMBER_VISITS);
146 source->set_json_path(kStringsJsFile); 147 source->set_json_path(kStringsJsFile);
147 source->add_resource_path(kHistoryJsFile, IDR_HISTORY_JS); 148 source->add_resource_path(kHistoryJsFile, IDR_HISTORY_JS);
148 source->set_default_resource(IDR_HISTORY_HTML); 149 source->set_default_resource(IDR_HISTORY_HTML);
149 source->set_use_json_js_format_v2(); 150 source->set_use_json_js_format_v2();
150 DictionaryValue localized_strings; 151 DictionaryValue localized_strings;
151 localized_strings.SetBoolean("historyGroupEnabled", 152 localized_strings.SetBoolean("historyGroupEnabled",
152 CommandLine::ForCurrentProcess()->HasSwitch( 153 CommandLine::ForCurrentProcess()->HasSwitch(
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 FROM_HERE, base::TimeDelta::FromSeconds(kWebHistoryTimeoutSeconds), 259 FROM_HERE, base::TimeDelta::FromSeconds(kWebHistoryTimeoutSeconds),
259 this, &BrowsingHistoryHandler::WebHistoryTimeout); 260 this, &BrowsingHistoryHandler::WebHistoryTimeout);
260 } 261 }
261 } 262 }
262 263
263 void BrowsingHistoryHandler::HandleQueryHistory(const ListValue* args) { 264 void BrowsingHistoryHandler::HandleQueryHistory(const ListValue* args) {
264 history::QueryOptions options; 265 history::QueryOptions options;
265 266
266 // Parse the arguments from JavaScript. There are six required arguments: 267 // Parse the arguments from JavaScript. There are six required arguments:
267 // - the text to search for (may be empty) 268 // - the text to search for (may be empty)
269 // - the offset from which the search should start in multiple of the range.
268 // - the range (number) of days to search for, used only for grouped 270 // - the range (number) of days to search for, used only for grouped
269 // searches. 271 // searches.
270 // - the end time of the range to search (see QueryOptions.end_time) 272 // - the end time of the range to search (see QueryOptions.end_time)
271 // - the search cursor, an opaque value from a previous query result, which 273 // - the search cursor, an opaque value from a previous query result, which
272 // allows this query to pick up where the previous one left off. May be 274 // allows this query to pick up where the previous one left off. May be
273 // null or undefined. 275 // null or undefined.
274 // - the maximum number of results to return (may be 0, meaning that there 276 // - the maximum number of results to return (may be 0, meaning that there
275 // is no maximum). 277 // is no maximum).
276 string16 search_text = ExtractStringValue(args); 278 string16 search_text = ExtractStringValue(args);
277 int range; 279 int offset;
278 if (!args->GetInteger(1, &range)) { 280 if (!args->GetInteger(1, &offset)) {
279 NOTREACHED() << "Failed to convert argument 1. "; 281 NOTREACHED() << "Failed to convert argument 1. ";
280 return; 282 return;
281 } 283 }
284 int range;
285 if (!args->GetInteger(2, &range)) {
286 NOTREACHED() << "Failed to convert argument 2. ";
287 return;
288 }
289
290 double end_time;
291 if (!args->GetDouble(3, &end_time)) {
292 NOTREACHED() << "Failed to convert argument 3. ";
293 return;
294 }
295 if (end_time)
296 options.end_time = base::Time::FromJsTime(end_time);
282 297
283 switch (range) { 298 switch (range) {
284 case BrowsingHistoryHandler::MONTH: 299 case BrowsingHistoryHandler::MONTH:
285 SetQueryTimeInMonths(&options); 300 SetQueryTimeInMonths(offset, &options);
286 break; 301 break;
287 case BrowsingHistoryHandler::WEEK: 302 case BrowsingHistoryHandler::WEEK:
288 SetQueryTimeInWeeks(&options); 303 SetQueryTimeInWeeks(offset, &options);
289 break; 304 break;
290 case BrowsingHistoryHandler::NOT_GROUPED: 305 case BrowsingHistoryHandler::NOT_GROUPED:
291 break; 306 break;
292 } 307 }
293 308
294 double end_time;
295 if (!args->GetDouble(2, &end_time)) {
296 NOTREACHED() << "Failed to convert argument 2. ";
297 return;
298 }
299 if (end_time)
300 options.end_time = base::Time::FromJsTime(end_time);
301
302 const Value* cursor_value; 309 const Value* cursor_value;
303 310
304 // Get the cursor. It must be either null, or a list. 311 // Get the cursor. It must be either null, or a list.
305 if (!args->Get(3, &cursor_value) || 312 if (!args->Get(4, &cursor_value) ||
306 (!cursor_value->IsType(Value::TYPE_NULL) && 313 (!cursor_value->IsType(Value::TYPE_NULL) &&
307 !history::QueryCursor::FromValue(cursor_value, &options.cursor))) { 314 !history::QueryCursor::FromValue(cursor_value, &options.cursor))) {
308 NOTREACHED() << "Failed to convert argument 3. "; 315 NOTREACHED() << "Failed to convert argument 4. ";
309 return; 316 return;
310 } 317 }
311 318
312 if (!ExtractIntegerValueAtIndex(args, 4, &options.max_count)) { 319 if (!ExtractIntegerValueAtIndex(args, 5, &options.max_count)) {
313 NOTREACHED() << "Failed to convert argument 4."; 320 NOTREACHED() << "Failed to convert argument 5.";
314 return; 321 return;
315 } 322 }
316 323
317 options.duplicate_policy = history::QueryOptions::REMOVE_DUPLICATES_PER_DAY; 324 options.duplicate_policy = history::QueryOptions::REMOVE_DUPLICATES_PER_DAY;
318 QueryHistory(search_text, options); 325 QueryHistory(search_text, options);
319 } 326 }
320 327
321 void BrowsingHistoryHandler::HandleRemoveURLsOnOneDay(const ListValue* args) { 328 void BrowsingHistoryHandler::HandleRemoveURLsOnOneDay(const ListValue* args) {
322 if (delete_task_tracker_.HasTrackedTasks()) { 329 if (delete_task_tracker_.HasTrackedTasks()) {
323 web_ui()->CallJavascriptFunction("deleteFailed"); 330 web_ui()->CallJavascriptFunction("deleteFailed");
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 } 533 }
527 534
528 void BrowsingHistoryHandler::RemoveComplete() { 535 void BrowsingHistoryHandler::RemoveComplete() {
529 urls_to_be_deleted_.clear(); 536 urls_to_be_deleted_.clear();
530 537
531 // Notify the page that the deletion request succeeded. 538 // Notify the page that the deletion request succeeded.
532 web_ui()->CallJavascriptFunction("deleteComplete"); 539 web_ui()->CallJavascriptFunction("deleteComplete");
533 } 540 }
534 541
535 void BrowsingHistoryHandler::SetQueryTimeInWeeks( 542 void BrowsingHistoryHandler::SetQueryTimeInWeeks(
536 history::QueryOptions* options) { 543 int offset, history::QueryOptions* options) {
537 // LocalMidnight returns the beginning of the current day so get the 544 // LocalMidnight returns the beginning of the current day so get the
538 // beginning of the next one. 545 // beginning of the next one.
539 base::Time midnight_today = base::Time::Now().LocalMidnight() + 546 base::Time midnight_today = base::Time::Now().LocalMidnight() +
540 base::TimeDelta::FromDays(1); 547 base::TimeDelta::FromDays(1);
541 options->end_time = midnight_today; 548 options->end_time = midnight_today -
542 options->begin_time = midnight_today - base::TimeDelta::FromDays(7); 549 base::TimeDelta::FromDays(7 * offset);
550 options->begin_time = midnight_today -
551 base::TimeDelta::FromDays(7 * (offset + 1));
543 } 552 }
544 553
545 void BrowsingHistoryHandler::SetQueryTimeInMonths( 554 void BrowsingHistoryHandler::SetQueryTimeInMonths(
546 history::QueryOptions* options) { 555 int offset, history::QueryOptions* options) {
547 // Configure the begin point of the search to the start of the 556 // Configure the begin point of the search to the start of the
548 // current month. 557 // current month.
549 base::Time::Exploded exploded; 558 base::Time::Exploded exploded;
550 base::Time::Now().LocalMidnight().LocalExplode(&exploded); 559 base::Time::Now().LocalMidnight().LocalExplode(&exploded);
551 exploded.day_of_month = 1; 560 exploded.day_of_month = 1;
552 options->begin_time = base::Time::FromLocalExploded(exploded);
553 561
554 // Set the end time of this first search to null (which will 562 if (offset == 0) {
555 // show results from the future, should the user's clock have 563 options->begin_time = base::Time::FromLocalExploded(exploded);
556 // been set incorrectly). 564
557 options->end_time = base::Time(); 565 // Set the end time of this first search to null (which will
566 // show results from the future, should the user's clock have
567 // been set incorrectly).
568 options->end_time = base::Time();
569 } else {
570 // Set the end-time of this search to the end of the month that is
571 // |offset| months before the search end point. The end time is not
572 // inclusive, so we should set it to midnight on the first day of the
573 // following month.
574 exploded.month -= offset - 1;
575 while (exploded.month < 1) {
576 exploded.month += 12;
577 exploded.year--;
578 }
579 options->end_time = base::Time::FromLocalExploded(exploded);
580
581 // Set the begin-time of the search to the start of the month
582 // that is |offset| months prior to search_start_.
583 if (exploded.month > 1) {
584 exploded.month--;
585 } else {
586 exploded.month = 12;
587 exploded.year--;
588 }
589 options->begin_time = base::Time::FromLocalExploded(exploded);
590 }
558 } 591 }
559 592
560 // Helper function for Observe that determines if there are any differences 593 // Helper function for Observe that determines if there are any differences
561 // between the URLs noticed for deletion and the ones we are expecting. 594 // between the URLs noticed for deletion and the ones we are expecting.
562 static bool DeletionsDiffer(const history::URLRows& deleted_rows, 595 static bool DeletionsDiffer(const history::URLRows& deleted_rows,
563 const std::set<GURL>& urls_to_be_deleted) { 596 const std::set<GURL>& urls_to_be_deleted) {
564 if (deleted_rows.size() != urls_to_be_deleted.size()) 597 if (deleted_rows.size() != urls_to_be_deleted.size())
565 return true; 598 return true;
566 for (history::URLRows::const_iterator i = deleted_rows.begin(); 599 for (history::URLRows::const_iterator i = deleted_rows.begin();
567 i != deleted_rows.end(); ++i) { 600 i != deleted_rows.end(); ++i) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 return GURL(std::string(chrome::kChromeUIHistoryURL) + "#q=" + 638 return GURL(std::string(chrome::kChromeUIHistoryURL) + "#q=" +
606 net::EscapeQueryParamValue(UTF16ToUTF8(text), true)); 639 net::EscapeQueryParamValue(UTF16ToUTF8(text), true));
607 } 640 }
608 641
609 // static 642 // static
610 base::RefCountedMemory* HistoryUI::GetFaviconResourceBytes( 643 base::RefCountedMemory* HistoryUI::GetFaviconResourceBytes(
611 ui::ScaleFactor scale_factor) { 644 ui::ScaleFactor scale_factor) {
612 return ResourceBundle::GetSharedInstance(). 645 return ResourceBundle::GetSharedInstance().
613 LoadDataResourceBytesForScale(IDR_HISTORY_FAVICON, scale_factor); 646 LoadDataResourceBytesForScale(IDR_HISTORY_FAVICON, scale_factor);
614 } 647 }
OLDNEW
« 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