Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/search/search_tab_helper.h" | 5 #include "chrome/browser/ui/search/search_tab_helper.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
| 14 #include "chrome/browser/history/most_visited_tiles_experiment.h" | 14 #include "chrome/browser/history/most_visited_tiles_experiment.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/search/instant_service.h" | 16 #include "chrome/browser/search/instant_service.h" |
| 17 #include "chrome/browser/search/instant_service_factory.h" | 17 #include "chrome/browser/search/instant_service_factory.h" |
| 18 #include "chrome/browser/search/search.h" | 18 #include "chrome/browser/search/search.h" |
| 19 #include "chrome/browser/signin/signin_manager_factory.h" | 19 #include "chrome/browser/signin/signin_manager_factory.h" |
| 20 #include "chrome/browser/sync/profile_sync_service.h" | |
| 21 #include "chrome/browser/sync/profile_sync_service_factory.h" | |
| 20 #include "chrome/browser/ui/app_list/app_list_util.h" | 22 #include "chrome/browser/ui/app_list/app_list_util.h" |
| 21 #include "chrome/browser/ui/browser_navigator.h" | 23 #include "chrome/browser/ui/browser_navigator.h" |
| 22 #include "chrome/browser/ui/browser_window.h" | 24 #include "chrome/browser/ui/browser_window.h" |
| 23 #include "chrome/browser/ui/omnibox/location_bar.h" | 25 #include "chrome/browser/ui/omnibox/location_bar.h" |
| 24 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" | 26 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" |
| 25 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" | 27 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" |
| 26 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 28 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
| 27 #include "chrome/browser/ui/search/search_ipc_router_policy_impl.h" | 29 #include "chrome/browser/ui/search/search_ipc_router_policy_impl.h" |
| 28 #include "chrome/browser/ui/search/search_tab_helper_delegate.h" | 30 #include "chrome/browser/ui/search/search_tab_helper_delegate.h" |
| 29 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" | 31 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents(contents); | 115 CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents(contents); |
| 114 if (core_tab_helper->new_tab_start_time().is_null()) | 116 if (core_tab_helper->new_tab_start_time().is_null()) |
| 115 return; | 117 return; |
| 116 | 118 |
| 117 base::TimeDelta duration = | 119 base::TimeDelta duration = |
| 118 base::TimeTicks::Now() - core_tab_helper->new_tab_start_time(); | 120 base::TimeTicks::Now() - core_tab_helper->new_tab_start_time(); |
| 119 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration); | 121 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration); |
| 120 core_tab_helper->set_new_tab_start_time(base::TimeTicks()); | 122 core_tab_helper->set_new_tab_start_time(base::TimeTicks()); |
| 121 } | 123 } |
| 122 | 124 |
| 125 // Returns true if the user is signed in and full history sync is enabled, | |
| 126 // and false otherwise. | |
| 127 bool IsHistorySyncEnabled(Profile* profile) { | |
| 128 ProfileSyncService* sync = | |
| 129 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); | |
| 130 return sync && | |
| 131 sync->sync_initialized() && | |
| 132 sync->GetActiveDataTypes().Has(syncer::HISTORY_DELETE_DIRECTIVES); | |
|
Jered
2014/06/17 22:38:19
I don't understand what HISTORY_DELETE_DIRECTIVES
beaudoin
2014/06/18 13:49:04
It's the one used by other pieces of the code that
| |
| 133 } | |
| 134 | |
| 123 } // namespace | 135 } // namespace |
| 124 | 136 |
| 125 SearchTabHelper::SearchTabHelper(content::WebContents* web_contents) | 137 SearchTabHelper::SearchTabHelper(content::WebContents* web_contents) |
| 126 : WebContentsObserver(web_contents), | 138 : WebContentsObserver(web_contents), |
| 127 is_search_enabled_(chrome::IsInstantExtendedAPIEnabled()), | 139 is_search_enabled_(chrome::IsInstantExtendedAPIEnabled()), |
| 128 web_contents_(web_contents), | 140 web_contents_(web_contents), |
| 129 ipc_router_(web_contents, this, | 141 ipc_router_(web_contents, this, |
| 130 make_scoped_ptr(new SearchIPCRouterPolicyImpl(web_contents)) | 142 make_scoped_ptr(new SearchIPCRouterPolicyImpl(web_contents)) |
| 131 .PassAs<SearchIPCRouter::Policy>()), | 143 .PassAs<SearchIPCRouter::Policy>()), |
| 132 instant_service_(NULL), | 144 instant_service_(NULL), |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 519 omnibox->SetUserText(text_to_paste); | 531 omnibox->SetUserText(text_to_paste); |
| 520 omnibox->OnAfterPossibleChange(); | 532 omnibox->OnAfterPossibleChange(); |
| 521 #endif | 533 #endif |
| 522 } | 534 } |
| 523 | 535 |
| 524 void SearchTabHelper::OnChromeIdentityCheck(const base::string16& identity) { | 536 void SearchTabHelper::OnChromeIdentityCheck(const base::string16& identity) { |
| 525 SigninManagerBase* manager = SigninManagerFactory::GetForProfile(profile()); | 537 SigninManagerBase* manager = SigninManagerFactory::GetForProfile(profile()); |
| 526 if (manager) { | 538 if (manager) { |
| 527 const base::string16 username = | 539 const base::string16 username = |
| 528 base::UTF8ToUTF16(manager->GetAuthenticatedUsername()); | 540 base::UTF8ToUTF16(manager->GetAuthenticatedUsername()); |
| 529 ipc_router_.SendChromeIdentityCheckResult(identity, | 541 // The identity check only passes if the user is syncing their history. |
| 530 identity == username); | 542 // TODO(beaudoin): Change this function name and related APIs now that it's |
| 543 // checking both the identity and the user's sync state. | |
| 544 bool matches = IsHistorySyncEnabled(profile()) && identity == username; | |
| 545 ipc_router_.SendChromeIdentityCheckResult(identity, matches); | |
| 531 } | 546 } |
| 532 } | 547 } |
| 533 | 548 |
| 534 void SearchTabHelper::UpdateMode(bool update_origin, bool is_preloaded_ntp) { | 549 void SearchTabHelper::UpdateMode(bool update_origin, bool is_preloaded_ntp) { |
| 535 SearchMode::Type type = SearchMode::MODE_DEFAULT; | 550 SearchMode::Type type = SearchMode::MODE_DEFAULT; |
| 536 SearchMode::Origin origin = SearchMode::ORIGIN_DEFAULT; | 551 SearchMode::Origin origin = SearchMode::ORIGIN_DEFAULT; |
| 537 if (IsNTP(web_contents_) || is_preloaded_ntp) { | 552 if (IsNTP(web_contents_) || is_preloaded_ntp) { |
| 538 type = SearchMode::MODE_NTP; | 553 type = SearchMode::MODE_NTP; |
| 539 origin = SearchMode::ORIGIN_NTP; | 554 origin = SearchMode::ORIGIN_NTP; |
| 540 } else if (IsSearchResults(web_contents_)) { | 555 } else if (IsSearchResults(web_contents_)) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 587 | 602 |
| 588 bool SearchTabHelper::IsInputInProgress() const { | 603 bool SearchTabHelper::IsInputInProgress() const { |
| 589 OmniboxView* omnibox = GetOmniboxView(); | 604 OmniboxView* omnibox = GetOmniboxView(); |
| 590 return !model_.mode().is_ntp() && omnibox && | 605 return !model_.mode().is_ntp() && omnibox && |
| 591 omnibox->model()->focus_state() == OMNIBOX_FOCUS_VISIBLE; | 606 omnibox->model()->focus_state() == OMNIBOX_FOCUS_VISIBLE; |
| 592 } | 607 } |
| 593 | 608 |
| 594 OmniboxView* SearchTabHelper::GetOmniboxView() const { | 609 OmniboxView* SearchTabHelper::GetOmniboxView() const { |
| 595 return delegate_ ? delegate_->GetOmniboxView() : NULL; | 610 return delegate_ ? delegate_->GetOmniboxView() : NULL; |
| 596 } | 611 } |
| OLD | NEW |