| OLD | NEW |
| 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/ntp/suggestions_page_handler.h" | 5 #include "chrome/browser/ui/webui/ntp/suggestions_page_handler.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 12 #include "base/md5.h" | 12 #include "base/md5.h" |
| 13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
| 17 #include "base/values.h" | 17 #include "base/values.h" |
| 18 #include "chrome/browser/history/top_sites.h" | 18 #include "chrome/browser/history/top_sites.h" |
| 19 #include "chrome/browser/history/top_sites_factory.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/ui/webui/favicon_source.h" | 21 #include "chrome/browser/ui/webui/favicon_source.h" |
| 21 #include "chrome/browser/ui/webui/ntp/ntp_stats.h" | 22 #include "chrome/browser/ui/webui/ntp/ntp_stats.h" |
| 22 #include "chrome/browser/ui/webui/ntp/suggestions_combiner.h" | 23 #include "chrome/browser/ui/webui/ntp/suggestions_combiner.h" |
| 23 #include "chrome/browser/ui/webui/ntp/suggestions_source_top_sites.h" | 24 #include "chrome/browser/ui/webui/ntp/suggestions_source_top_sites.h" |
| 24 #include "chrome/browser/ui/webui/ntp/thumbnail_source.h" | 25 #include "chrome/browser/ui/webui/ntp/thumbnail_source.h" |
| 25 #include "chrome/common/url_constants.h" | 26 #include "chrome/common/url_constants.h" |
| 26 #include "components/history/core/browser/page_usage_data.h" | 27 #include "components/history/core/browser/page_usage_data.h" |
| 27 #include "components/pref_registry/pref_registry_syncable.h" | 28 #include "components/pref_registry/pref_registry_syncable.h" |
| 28 #include "content/public/browser/navigation_controller.h" | 29 #include "content/public/browser/navigation_controller.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 | 62 |
| 62 void SuggestionsHandler::RegisterMessages() { | 63 void SuggestionsHandler::RegisterMessages() { |
| 63 Profile* profile = Profile::FromWebUI(web_ui()); | 64 Profile* profile = Profile::FromWebUI(web_ui()); |
| 64 // Set up our sources for thumbnail and favicon data. | 65 // Set up our sources for thumbnail and favicon data. |
| 65 content::URLDataSource::Add(profile, new ThumbnailSource(profile, false)); | 66 content::URLDataSource::Add(profile, new ThumbnailSource(profile, false)); |
| 66 content::URLDataSource::Add( | 67 content::URLDataSource::Add( |
| 67 profile, new FaviconSource(profile, FaviconSource::FAVICON)); | 68 profile, new FaviconSource(profile, FaviconSource::FAVICON)); |
| 68 | 69 |
| 69 // TODO(georgey) change the source of the web-sites to provide our data. | 70 // TODO(georgey) change the source of the web-sites to provide our data. |
| 70 // Initial commit uses top sites as a data source. | 71 // Initial commit uses top sites as a data source. |
| 71 history::TopSites* top_sites = profile->GetTopSites(); | 72 scoped_refptr<history::TopSites> top_sites = |
| 73 TopSitesFactory::GetForProfile(profile); |
| 72 if (top_sites) { | 74 if (top_sites) { |
| 73 // TopSites updates itself after a delay. This is especially noticable when | 75 // TopSites updates itself after a delay. This is especially noticable when |
| 74 // your profile is empty. Ask TopSites to update itself when we're about to | 76 // your profile is empty. Ask TopSites to update itself when we're about to |
| 75 // show the new tab page. | 77 // show the new tab page. |
| 76 top_sites->SyncWithHistory(); | 78 top_sites->SyncWithHistory(); |
| 77 | 79 |
| 78 // Register as TopSitesObserver so that we can update ourselves when the | 80 // Register as TopSitesObserver so that we can update ourselves when the |
| 79 // TopSites changes. | 81 // TopSites changes. |
| 80 scoped_observer_.Add(top_sites); | 82 scoped_observer_.Add(top_sites.get()); |
| 81 } | 83 } |
| 82 | 84 |
| 83 // Setup the suggestions sources. | 85 // Setup the suggestions sources. |
| 84 SuggestionsCombiner* combiner = new SuggestionsCombiner(this, profile); | 86 SuggestionsCombiner* combiner = new SuggestionsCombiner(this, profile); |
| 85 combiner->AddSource(new SuggestionsSourceTopSites()); | 87 combiner->AddSource(new SuggestionsSourceTopSites()); |
| 86 suggestions_combiner_.reset(combiner); | 88 suggestions_combiner_.reset(combiner); |
| 87 | 89 |
| 88 // We pre-emptively make a fetch for suggestions so we have the results | 90 // We pre-emptively make a fetch for suggestions so we have the results |
| 89 // sooner. | 91 // sooner. |
| 90 suggestions_combiner_->FetchItems(profile); | 92 suggestions_combiner_->FetchItems(profile); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 | 189 |
| 188 std::string SuggestionsHandler::GetDictionaryKeyForURL(const std::string& url) { | 190 std::string SuggestionsHandler::GetDictionaryKeyForURL(const std::string& url) { |
| 189 return base::MD5String(url); | 191 return base::MD5String(url); |
| 190 } | 192 } |
| 191 | 193 |
| 192 // static | 194 // static |
| 193 void SuggestionsHandler::RegisterProfilePrefs( | 195 void SuggestionsHandler::RegisterProfilePrefs( |
| 194 user_prefs::PrefRegistrySyncable* registry) { | 196 user_prefs::PrefRegistrySyncable* registry) { |
| 195 // TODO(georgey) add user preferences (such as own blacklist) as needed. | 197 // TODO(georgey) add user preferences (such as own blacklist) as needed. |
| 196 } | 198 } |
| OLD | NEW |