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

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 with the other commit and fix some things. Created 7 years, 10 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 UTF8ToUTF16(kIncognitoModeShortcut))); 135 UTF8ToUTF16(kIncognitoModeShortcut)));
136 source->AddLocalizedString("actionMenuDescription", 136 source->AddLocalizedString("actionMenuDescription",
137 IDS_HISTORY_ACTION_MENU_DESCRIPTION); 137 IDS_HISTORY_ACTION_MENU_DESCRIPTION);
138 source->AddLocalizedString("removeFromHistory", IDS_HISTORY_REMOVE_PAGE); 138 source->AddLocalizedString("removeFromHistory", IDS_HISTORY_REMOVE_PAGE);
139 source->AddLocalizedString("moreFromSite", IDS_HISTORY_MORE_FROM_SITE); 139 source->AddLocalizedString("moreFromSite", IDS_HISTORY_MORE_FROM_SITE);
140 source->AddLocalizedString("displayfiltersites", IDS_GROUP_BY_DOMAIN_LABEL); 140 source->AddLocalizedString("displayfiltersites", IDS_GROUP_BY_DOMAIN_LABEL);
141 source->AddLocalizedString("rangelabel", IDS_HISTORY_RANGE_LABEL); 141 source->AddLocalizedString("rangelabel", IDS_HISTORY_RANGE_LABEL);
142 source->AddLocalizedString("rangenone", IDS_HISTORY_RANGE_NONE); 142 source->AddLocalizedString("rangenone", IDS_HISTORY_RANGE_NONE);
143 source->AddLocalizedString("rangeweek", IDS_HISTORY_RANGE_WEEK); 143 source->AddLocalizedString("rangeweek", IDS_HISTORY_RANGE_WEEK);
144 source->AddLocalizedString("rangemonth", IDS_HISTORY_RANGE_MONTH); 144 source->AddLocalizedString("rangemonth", IDS_HISTORY_RANGE_MONTH);
145 source->AddLocalizedString("displayfiltersites", IDS_GROUP_BY_DOMAIN_LABEL); 145 source->AddLocalizedString("rangetoday", IDS_HISTORY_RANGE_TODAY);
146 source->AddLocalizedString("numbervisits", IDS_HISTORY_NUMBER_VISITS); 146 source->AddLocalizedString("numbervisits", IDS_HISTORY_NUMBER_VISITS);
147 source->AddBoolean("groupByDomain", 147 source->AddBoolean("groupByDomain",
148 CommandLine::ForCurrentProcess()->HasSwitch( 148 CommandLine::ForCurrentProcess()->HasSwitch(
149 switches::kHistoryEnableGroupByDomain)); 149 switches::kHistoryEnableGroupByDomain));
150 source->SetJsonPath(kStringsJsFile); 150 source->SetJsonPath(kStringsJsFile);
151 source->AddResourcePath(kHistoryJsFile, IDR_HISTORY_JS); 151 source->AddResourcePath(kHistoryJsFile, IDR_HISTORY_JS);
152 source->SetDefaultResource(IDR_HISTORY_HTML); 152 source->SetDefaultResource(IDR_HISTORY_HTML);
153 source->SetUseJsonJSFormatV2(); 153 source->SetUseJsonJSFormatV2();
154 source->DisableDenyXFrameOptions(); 154 source->DisableDenyXFrameOptions();
155 155
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 FROM_HERE, base::TimeDelta::FromSeconds(kWebHistoryTimeoutSeconds), 260 FROM_HERE, base::TimeDelta::FromSeconds(kWebHistoryTimeoutSeconds),
261 this, &BrowsingHistoryHandler::WebHistoryTimeout); 261 this, &BrowsingHistoryHandler::WebHistoryTimeout);
262 } 262 }
263 } 263 }
264 264
265 void BrowsingHistoryHandler::HandleQueryHistory(const ListValue* args) { 265 void BrowsingHistoryHandler::HandleQueryHistory(const ListValue* args) {
266 history::QueryOptions options; 266 history::QueryOptions options;
267 267
268 // Parse the arguments from JavaScript. There are four required arguments: 268 // Parse the arguments from JavaScript. There are four required arguments:
269 // - the text to search for (may be empty) 269 // - the text to search for (may be empty)
270 // - the offset from which the search should start in multiple of the range.
270 // - the range (number) of days to search for, used only for grouped 271 // - the range (number) of days to search for, used only for grouped
271 // searches. 272 // searches.
272 // - 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
273 // 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
274 // null or undefined. 275 // null or undefined.
275 // - 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
276 // is no maximum). 277 // is no maximum).
277 string16 search_text = ExtractStringValue(args); 278 string16 search_text = ExtractStringValue(args);
279 int offset;
280 if (!args->GetInteger(1, &offset)) {
281 NOTREACHED() << "Failed to convert argument 1. ";
282 return;
283 }
278 int range; 284 int range;
279 if (!args->GetInteger(1, &range)) { 285 if (!args->GetInteger(2, &range)) {
280 NOTREACHED() << "Failed to convert argument 1. "; 286 NOTREACHED() << "Failed to convert argument 2. ";
281 return; 287 return;
282 } 288 }
283 289
284 switch (range) { 290 switch (range) {
285 case BrowsingHistoryHandler::MONTH: 291 case BrowsingHistoryHandler::MONTH:
286 SetQueryTimeInMonths(&options); 292 SetQueryTimeInMonths(offset, &options);
287 break; 293 break;
288 case BrowsingHistoryHandler::WEEK: 294 case BrowsingHistoryHandler::WEEK:
289 SetQueryTimeInWeeks(&options); 295 SetQueryTimeInWeeks(offset, &options);
290 break; 296 break;
291 case BrowsingHistoryHandler::NOT_GROUPED: 297 case BrowsingHistoryHandler::NOT_GROUPED:
292 break; 298 break;
293 } 299 }
294 300
295 const Value* cursor_value; 301 const Value* cursor_value;
296 302
297 // Get the cursor. It must be either null, or a list. 303 // Get the cursor. It must be either null, or a list.
298 if (!args->Get(2, &cursor_value) || 304 if (!args->Get(3, &cursor_value) ||
299 (!cursor_value->IsType(Value::TYPE_NULL) && 305 (!cursor_value->IsType(Value::TYPE_NULL) &&
300 !history::QueryCursor::FromValue(cursor_value, &options.cursor))) { 306 !history::QueryCursor::FromValue(cursor_value, &options.cursor))) {
301 NOTREACHED() << "Failed to convert argument 2. "; 307 NOTREACHED() << "Failed to convert argument 3. ";
302 return; 308 return;
303 } 309 }
304 310
305 if (!ExtractIntegerValueAtIndex(args, 3, &options.max_count)) { 311 if (!ExtractIntegerValueAtIndex(args, 4, &options.max_count)) {
306 NOTREACHED() << "Failed to convert argument 3."; 312 NOTREACHED() << "Failed to convert argument 4.";
307 return; 313 return;
308 } 314 }
309 315
310 options.duplicate_policy = history::QueryOptions::REMOVE_DUPLICATES_PER_DAY; 316 options.duplicate_policy = history::QueryOptions::REMOVE_DUPLICATES_PER_DAY;
311 QueryHistory(search_text, options); 317 QueryHistory(search_text, options);
312 } 318 }
313 319
314 void BrowsingHistoryHandler::HandleRemoveURLsOnOneDay(const ListValue* args) { 320 void BrowsingHistoryHandler::HandleRemoveURLsOnOneDay(const ListValue* args) {
315 if (delete_task_tracker_.HasTrackedTasks()) { 321 if (delete_task_tracker_.HasTrackedTasks()) {
316 web_ui()->CallJavascriptFunction("deleteFailed"); 322 web_ui()->CallJavascriptFunction("deleteFailed");
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 } 540 }
535 541
536 void BrowsingHistoryHandler::RemoveWebHistoryComplete( 542 void BrowsingHistoryHandler::RemoveWebHistoryComplete(
537 history::WebHistoryService::Request* request, bool success) { 543 history::WebHistoryService::Request* request, bool success) {
538 // Notify the page that the deletion request is complete. 544 // Notify the page that the deletion request is complete.
539 base::FundamentalValue success_value(success); 545 base::FundamentalValue success_value(success);
540 web_ui()->CallJavascriptFunction("webHistoryDeleteComplete", success_value); 546 web_ui()->CallJavascriptFunction("webHistoryDeleteComplete", success_value);
541 } 547 }
542 548
543 void BrowsingHistoryHandler::SetQueryTimeInWeeks( 549 void BrowsingHistoryHandler::SetQueryTimeInWeeks(
544 history::QueryOptions* options) { 550 int offset, history::QueryOptions* options) {
545 // LocalMidnight returns the beginning of the current day so get the 551 // LocalMidnight returns the beginning of the current day so get the
546 // beginning of the next one. 552 // beginning of the next one.
547 base::Time midnight = base::Time::Now().LocalMidnight() + 553 base::Time midnight = base::Time::Now().LocalMidnight() +
548 base::TimeDelta::FromDays(1); 554 base::TimeDelta::FromDays(1);
549 options->end_time = midnight; 555 options->end_time = midnight -
550 options->begin_time = midnight - base::TimeDelta::FromDays(7); 556 base::TimeDelta::FromDays(7 * offset);
557 options->begin_time = midnight -
558 base::TimeDelta::FromDays(7 * (offset + 1));
551 } 559 }
552 560
553 void BrowsingHistoryHandler::SetQueryTimeInMonths( 561 void BrowsingHistoryHandler::SetQueryTimeInMonths(
554 history::QueryOptions* options) { 562 int offset, history::QueryOptions* options) {
555 // Configure the begin point of the search to the start of the 563 // Configure the begin point of the search to the start of the
556 // current month. 564 // current month.
557 base::Time::Exploded exploded; 565 base::Time::Exploded exploded;
558 base::Time::Now().LocalMidnight().LocalExplode(&exploded); 566 base::Time::Now().LocalMidnight().LocalExplode(&exploded);
559 exploded.day_of_month = 1; 567 exploded.day_of_month = 1;
560 options->begin_time = base::Time::FromLocalExploded(exploded);
561 568
562 // Set the end time of this first search to null (which will 569 if (offset == 0) {
563 // show results from the future, should the user's clock have 570 options->begin_time = base::Time::FromLocalExploded(exploded);
564 // been set incorrectly). 571
565 options->end_time = base::Time(); 572 // Set the end time of this first search to null (which will
573 // show results from the future, should the user's clock have
574 // been set incorrectly).
575 options->end_time = base::Time();
576 } else {
577 // Set the end-time of this search to the end of the month that is
578 // |offset| months before the search end point. The end time is not
579 // inclusive, so we should set it to midnight on the first day of the
580 // following month.
581 exploded.month -= offset - 1;
582 while (exploded.month < 1) {
583 exploded.month += 12;
584 exploded.year--;
585 }
586 options->end_time = base::Time::FromLocalExploded(exploded);
587
588 // Set the begin-time of the search to the start of the month
589 // that is |offset| months prior to search_start_.
590 if (exploded.month > 1) {
591 exploded.month--;
592 } else {
593 exploded.month = 12;
594 exploded.year--;
595 }
596 options->begin_time = base::Time::FromLocalExploded(exploded);
597 }
566 } 598 }
567 599
568 // Helper function for Observe that determines if there are any differences 600 // Helper function for Observe that determines if there are any differences
569 // between the URLs noticed for deletion and the ones we are expecting. 601 // between the URLs noticed for deletion and the ones we are expecting.
570 static bool DeletionsDiffer(const history::URLRows& deleted_rows, 602 static bool DeletionsDiffer(const history::URLRows& deleted_rows,
571 const std::set<GURL>& urls_to_be_deleted) { 603 const std::set<GURL>& urls_to_be_deleted) {
572 if (deleted_rows.size() != urls_to_be_deleted.size()) 604 if (deleted_rows.size() != urls_to_be_deleted.size())
573 return true; 605 return true;
574 for (history::URLRows::const_iterator i = deleted_rows.begin(); 606 for (history::URLRows::const_iterator i = deleted_rows.begin();
575 i != deleted_rows.end(); ++i) { 607 i != deleted_rows.end(); ++i) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 return GURL(std::string(chrome::kChromeUIHistoryURL) + "#q=" + 645 return GURL(std::string(chrome::kChromeUIHistoryURL) + "#q=" +
614 net::EscapeQueryParamValue(UTF16ToUTF8(text), true)); 646 net::EscapeQueryParamValue(UTF16ToUTF8(text), true));
615 } 647 }
616 648
617 // static 649 // static
618 base::RefCountedMemory* HistoryUI::GetFaviconResourceBytes( 650 base::RefCountedMemory* HistoryUI::GetFaviconResourceBytes(
619 ui::ScaleFactor scale_factor) { 651 ui::ScaleFactor scale_factor) {
620 return ResourceBundle::GetSharedInstance(). 652 return ResourceBundle::GetSharedInstance().
621 LoadDataResourceBytesForScale(IDR_HISTORY_FAVICON, scale_factor); 653 LoadDataResourceBytesForScale(IDR_HISTORY_FAVICON, scale_factor);
622 } 654 }
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