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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
43 #include "components/favicon/core/fallback_url_util.h" | 43 #include "components/favicon/core/fallback_url_util.h" |
44 #include "components/favicon/core/large_icon_service.h" | 44 #include "components/favicon/core/large_icon_service.h" |
45 #include "components/history/core/browser/history_service.h" | 45 #include "components/history/core/browser/history_service.h" |
46 #include "components/history/core/browser/history_types.h" | 46 #include "components/history/core/browser/history_types.h" |
47 #include "components/history/core/browser/web_history_service.h" | 47 #include "components/history/core/browser/web_history_service.h" |
48 #include "components/keyed_service/core/service_access_type.h" | 48 #include "components/keyed_service/core/service_access_type.h" |
49 #include "components/prefs/pref_service.h" | 49 #include "components/prefs/pref_service.h" |
50 #include "components/query_parser/snippet.h" | 50 #include "components/query_parser/snippet.h" |
51 #include "components/sync/device_info/device_info.h" | 51 #include "components/sync/device_info/device_info.h" |
52 #include "components/sync/device_info/device_info_tracker.h" | 52 #include "components/sync/device_info/device_info_tracker.h" |
53 #include "components/sync/driver/sync_service_observer.h" | |
53 #include "components/sync/protocol/history_delete_directive_specifics.pb.h" | 54 #include "components/sync/protocol/history_delete_directive_specifics.pb.h" |
54 #include "components/sync/protocol/sync_enums.pb.h" | 55 #include "components/sync/protocol/sync_enums.pb.h" |
55 #include "components/url_formatter/url_formatter.h" | 56 #include "components/url_formatter/url_formatter.h" |
56 #include "content/public/browser/url_data_source.h" | 57 #include "content/public/browser/url_data_source.h" |
57 #include "content/public/browser/web_ui.h" | 58 #include "content/public/browser/web_ui.h" |
58 #include "grit/components_strings.h" | 59 #include "grit/components_strings.h" |
59 #include "ui/base/l10n/l10n_util.h" | 60 #include "ui/base/l10n/l10n_util.h" |
60 #include "ui/base/l10n/time_format.h" | 61 #include "ui/base/l10n/time_format.h" |
61 | 62 |
62 #if defined(ENABLE_EXTENSIONS) | 63 #if defined(ENABLE_EXTENSIONS) |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
309 | 310 |
310 bool BrowsingHistoryHandler::HistoryEntry::SortByTimeDescending( | 311 bool BrowsingHistoryHandler::HistoryEntry::SortByTimeDescending( |
311 const BrowsingHistoryHandler::HistoryEntry& entry1, | 312 const BrowsingHistoryHandler::HistoryEntry& entry1, |
312 const BrowsingHistoryHandler::HistoryEntry& entry2) { | 313 const BrowsingHistoryHandler::HistoryEntry& entry2) { |
313 return entry1.time > entry2.time; | 314 return entry1.time > entry2.time; |
314 } | 315 } |
315 | 316 |
316 BrowsingHistoryHandler::BrowsingHistoryHandler() | 317 BrowsingHistoryHandler::BrowsingHistoryHandler() |
317 : has_pending_delete_request_(false), | 318 : has_pending_delete_request_(false), |
318 history_service_observer_(this), | 319 history_service_observer_(this), |
320 web_history_service_observer_(this), | |
321 sync_service_observer_(this), | |
319 has_synced_results_(false), | 322 has_synced_results_(false), |
320 has_other_forms_of_browsing_history_(false), | 323 has_other_forms_of_browsing_history_(false), |
321 weak_factory_(this) { | 324 weak_factory_(this) {} |
322 } | |
323 | 325 |
324 BrowsingHistoryHandler::~BrowsingHistoryHandler() { | 326 BrowsingHistoryHandler::~BrowsingHistoryHandler() { |
325 query_task_tracker_.TryCancelAll(); | 327 query_task_tracker_.TryCancelAll(); |
326 web_history_request_.reset(); | 328 web_history_request_.reset(); |
327 } | 329 } |
328 | 330 |
329 void BrowsingHistoryHandler::RegisterMessages() { | 331 void BrowsingHistoryHandler::RegisterMessages() { |
330 // Create our favicon data source. | 332 // Create our favicon data source. |
331 Profile* profile = Profile::FromWebUI(web_ui()); | 333 Profile* profile = Profile::FromWebUI(web_ui()); |
332 | 334 |
333 #if defined(OS_ANDROID) | 335 #if defined(OS_ANDROID) |
334 favicon::FallbackIconService* fallback_icon_service = | 336 favicon::FallbackIconService* fallback_icon_service = |
335 FallbackIconServiceFactory::GetForBrowserContext(profile); | 337 FallbackIconServiceFactory::GetForBrowserContext(profile); |
336 favicon::LargeIconService* large_icon_service = | 338 favicon::LargeIconService* large_icon_service = |
337 LargeIconServiceFactory::GetForBrowserContext(profile); | 339 LargeIconServiceFactory::GetForBrowserContext(profile); |
338 content::URLDataSource::Add( | 340 content::URLDataSource::Add( |
339 profile, new LargeIconSource(fallback_icon_service, large_icon_service)); | 341 profile, new LargeIconSource(fallback_icon_service, large_icon_service)); |
340 #else | 342 #else |
341 content::URLDataSource::Add( | 343 content::URLDataSource::Add( |
342 profile, new FaviconSource(profile, FaviconSource::ANY)); | 344 profile, new FaviconSource(profile, FaviconSource::ANY)); |
343 #endif | 345 #endif |
344 | 346 |
345 // Get notifications when history is cleared. | 347 // Get notifications when history is cleared. |
346 history::HistoryService* hs = HistoryServiceFactory::GetForProfile( | 348 history::HistoryService* local_history = HistoryServiceFactory::GetForProfile( |
347 profile, ServiceAccessType::EXPLICIT_ACCESS); | 349 profile, ServiceAccessType::EXPLICIT_ACCESS); |
348 if (hs) | 350 if (local_history) |
349 history_service_observer_.Add(hs); | 351 history_service_observer_.Add(local_history); |
352 | |
353 // Get notifications when web history is deleted. | |
354 history::WebHistoryService* web_history = | |
355 WebHistoryServiceFactory::GetForProfile(profile); | |
356 if (web_history) { | |
357 web_history_service_observer_.Add(web_history); | |
358 } else { | |
359 // If |web_history| is not available, it means that the history sync is | |
360 // disabled. Observe |sync_service| so that we can attach the listener | |
361 // in case it gets enabled later. | |
362 ProfileSyncService* sync_service = | |
363 ProfileSyncServiceFactory::GetForProfile(profile); | |
364 if (sync_service) | |
365 sync_service_observer_.Add(sync_service); | |
366 } | |
350 | 367 |
351 web_ui()->RegisterMessageCallback("queryHistory", | 368 web_ui()->RegisterMessageCallback("queryHistory", |
352 base::Bind(&BrowsingHistoryHandler::HandleQueryHistory, | 369 base::Bind(&BrowsingHistoryHandler::HandleQueryHistory, |
353 base::Unretained(this))); | 370 base::Unretained(this))); |
354 web_ui()->RegisterMessageCallback("removeVisits", | 371 web_ui()->RegisterMessageCallback("removeVisits", |
355 base::Bind(&BrowsingHistoryHandler::HandleRemoveVisits, | 372 base::Bind(&BrowsingHistoryHandler::HandleRemoveVisits, |
356 base::Unretained(this))); | 373 base::Unretained(this))); |
357 web_ui()->RegisterMessageCallback("clearBrowsingData", | 374 web_ui()->RegisterMessageCallback("clearBrowsingData", |
358 base::Bind(&BrowsingHistoryHandler::HandleClearBrowsingData, | 375 base::Bind(&BrowsingHistoryHandler::HandleClearBrowsingData, |
359 base::Unretained(this))); | 376 base::Unretained(this))); |
360 web_ui()->RegisterMessageCallback("removeBookmark", | 377 web_ui()->RegisterMessageCallback("removeBookmark", |
361 base::Bind(&BrowsingHistoryHandler::HandleRemoveBookmark, | 378 base::Bind(&BrowsingHistoryHandler::HandleRemoveBookmark, |
362 base::Unretained(this))); | 379 base::Unretained(this))); |
363 } | 380 } |
364 | 381 |
365 bool BrowsingHistoryHandler::ExtractIntegerValueAtIndex( | 382 bool BrowsingHistoryHandler::ExtractIntegerValueAtIndex( |
366 const base::ListValue* value, | 383 const base::ListValue* value, |
367 int index, | 384 int index, |
368 int* out_int) { | 385 int* out_int) { |
369 double double_value; | 386 double double_value; |
370 if (value->GetDouble(index, &double_value)) { | 387 if (value->GetDouble(index, &double_value)) { |
371 *out_int = static_cast<int>(double_value); | 388 *out_int = static_cast<int>(double_value); |
372 return true; | 389 return true; |
373 } | 390 } |
374 NOTREACHED(); | 391 NOTREACHED(); |
375 return false; | 392 return false; |
376 } | 393 } |
377 | 394 |
395 void BrowsingHistoryHandler::OnStateChanged() { | |
396 // If the history sync was enabled, start observing WebHistoryService. | |
397 // This method should not be called after we already added the observer. | |
398 history::WebHistoryService* web_history = | |
399 WebHistoryServiceFactory::GetForProfile(Profile::FromWebUI(web_ui())); | |
400 if (web_history) { | |
401 DCHECK(!web_history_service_observer_.IsObserving(web_history)); | |
402 web_history_service_observer_.Add(web_history); | |
403 sync_service_observer_.RemoveAll(); | |
404 } | |
405 } | |
406 | |
378 void BrowsingHistoryHandler::WebHistoryTimeout() { | 407 void BrowsingHistoryHandler::WebHistoryTimeout() { |
379 // TODO(dubroy): Communicate the failure to the front end. | 408 // TODO(dubroy): Communicate the failure to the front end. |
380 if (!query_task_tracker_.HasTrackedTasks()) | 409 if (!query_task_tracker_.HasTrackedTasks()) |
381 ReturnResultsToFrontEnd(); | 410 ReturnResultsToFrontEnd(); |
382 | 411 |
383 UMA_HISTOGRAM_ENUMERATION( | 412 UMA_HISTOGRAM_ENUMERATION( |
384 "WebHistory.QueryCompletion", | 413 "WebHistory.QueryCompletion", |
385 WEB_HISTORY_QUERY_TIMED_OUT, NUM_WEB_HISTORY_QUERY_BUCKETS); | 414 WEB_HISTORY_QUERY_TIMED_OUT, NUM_WEB_HISTORY_QUERY_BUCKETS); |
386 } | 415 } |
387 | 416 |
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
953 | 982 |
954 void BrowsingHistoryHandler::OnURLsDeleted( | 983 void BrowsingHistoryHandler::OnURLsDeleted( |
955 history::HistoryService* history_service, | 984 history::HistoryService* history_service, |
956 bool all_history, | 985 bool all_history, |
957 bool expired, | 986 bool expired, |
958 const history::URLRows& deleted_rows, | 987 const history::URLRows& deleted_rows, |
959 const std::set<GURL>& favicon_urls) { | 988 const std::set<GURL>& favicon_urls) { |
960 if (all_history || DeletionsDiffer(deleted_rows, urls_to_be_deleted_)) | 989 if (all_history || DeletionsDiffer(deleted_rows, urls_to_be_deleted_)) |
961 web_ui()->CallJavascriptFunctionUnsafe("historyDeleted"); | 990 web_ui()->CallJavascriptFunctionUnsafe("historyDeleted"); |
962 } | 991 } |
992 | |
993 void BrowsingHistoryHandler::OnWebHistoryDeleted() { | |
994 web_ui()->CallJavascriptFunctionUnsafe("historyDeleted"); | |
Dan Beam
2016/08/25 19:20:10
note: if the page is in the middle of a reload whe
msramek
2016/08/25 20:21:34
Thanks for checking.
On the JS side, "historyDele
| |
995 } | |
OLD | NEW |