Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/android/ntp/most_visited_sites_bridge.h" | 5 #include "chrome/browser/android/ntp/most_visited_sites_bridge.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
| 11 #include "base/android/jni_string.h" | 11 #include "base/android/jni_string.h" |
| 12 #include "base/android/scoped_java_ref.h" | 12 #include "base/android/scoped_java_ref.h" |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "chrome/browser/android/ntp/popular_sites.h" | 15 #include "chrome/browser/android/ntp/popular_sites.h" |
| 16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/history/top_sites_factory.h" | 17 #include "chrome/browser/history/top_sites_factory.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/profiles/profile_android.h" | 19 #include "chrome/browser/profiles/profile_android.h" |
| 20 #include "chrome/browser/search/suggestions/suggestions_service_factory.h" | 20 #include "chrome/browser/search/suggestions/suggestions_service_factory.h" |
| 21 #include "chrome/browser/search_engines/template_url_service_factory.h" | 21 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 22 #include "chrome/browser/supervised_user/supervised_user_service.h" | |
| 23 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" | |
| 24 #include "chrome/browser/supervised_user/supervised_user_url_filter.h" | |
| 22 #include "chrome/browser/thumbnails/thumbnail_list_source.h" | 25 #include "chrome/browser/thumbnails/thumbnail_list_source.h" |
| 23 #include "components/history/core/browser/top_sites.h" | 26 #include "components/history/core/browser/top_sites.h" |
| 24 #include "content/public/browser/url_data_source.h" | 27 #include "content/public/browser/url_data_source.h" |
| 25 #include "jni/MostVisitedSites_jni.h" | 28 #include "jni/MostVisitedSites_jni.h" |
| 26 #include "ui/gfx/android/java_bitmap.h" | 29 #include "ui/gfx/android/java_bitmap.h" |
| 27 #include "url/gurl.h" | 30 #include "url/gurl.h" |
| 28 | 31 |
| 29 using base::android::AttachCurrentThread; | 32 using base::android::AttachCurrentThread; |
| 30 using base::android::ConvertJavaStringToUTF8; | 33 using base::android::ConvertJavaStringToUTF8; |
| 31 using base::android::ScopedJavaGlobalRef; | 34 using base::android::ScopedJavaGlobalRef; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 42 JNIEnv* env = AttachCurrentThread(); | 45 JNIEnv* env = AttachCurrentThread(); |
| 43 ScopedJavaLocalRef<jobject> j_bitmap; | 46 ScopedJavaLocalRef<jobject> j_bitmap; |
| 44 if (bitmap) | 47 if (bitmap) |
| 45 j_bitmap = gfx::ConvertToJavaBitmap(bitmap); | 48 j_bitmap = gfx::ConvertToJavaBitmap(bitmap); |
| 46 Java_ThumbnailCallback_onMostVisitedURLsThumbnailAvailable( | 49 Java_ThumbnailCallback_onMostVisitedURLsThumbnailAvailable( |
| 47 env, j_callback->obj(), j_bitmap.obj(), is_local_thumbnail); | 50 env, j_callback->obj(), j_bitmap.obj(), is_local_thumbnail); |
| 48 } | 51 } |
| 49 | 52 |
| 50 } // namespace | 53 } // namespace |
| 51 | 54 |
| 55 MostVisitedSitesBridge::SupervisorBridge::SupervisorBridge(Profile* profile) | |
| 56 : profile_(profile), | |
| 57 register_observer_(this) { | |
| 58 register_observer_.Add( | |
| 59 SupervisedUserServiceFactory::GetForProfile(profile_)); | |
| 60 } | |
| 61 | |
| 62 void | |
| 63 MostVisitedSitesBridge::SupervisorBridge::SetObserver(Observer* new_observer) { | |
|
Marc Treib
2016/05/09 08:22:48
Can this method move into MostVisitedSitesSupervis
sfiera
2016/05/09 09:33:35
A rough check of Chromium code suggests that of Ad
Marc Treib
2016/05/09 09:55:12
Okay, fair enough.
My rationale was that the metho
sfiera
2016/05/09 10:26:17
If I were to go further, I think that really The C
| |
| 64 if (new_observer) { | |
| 65 DCHECK(!observer_); | |
| 66 } else { | |
| 67 DCHECK(observer_); | |
| 68 } | |
| 69 observer_ = new_observer; | |
| 70 } | |
| 71 | |
| 72 bool MostVisitedSitesBridge::SupervisorBridge::IsBlocked(const GURL& url) { | |
| 73 SupervisedUserService* supervised_user_service = | |
| 74 SupervisedUserServiceFactory::GetForProfile(profile_); | |
|
Marc Treib
2016/05/09 08:22:48
wrong indent
sfiera
2016/05/09 09:33:35
Done.
| |
| 75 auto url_filter = supervised_user_service->GetURLFilterForUIThread(); | |
| 76 return url_filter->GetFilteringBehaviorForURL(url) == | |
| 77 SupervisedUserURLFilter::FilteringBehavior::BLOCK; | |
|
Marc Treib
2016/05/09 08:22:48
here too
sfiera
2016/05/09 09:33:35
Done.
| |
| 78 } | |
| 79 | |
| 80 std::vector<MostVisitedSitesSupervisor::Whitelist> | |
| 81 MostVisitedSitesBridge::SupervisorBridge::whitelists() { | |
| 82 std::vector<MostVisitedSitesSupervisor::Whitelist> results; | |
| 83 SupervisedUserService* supervised_user_service = | |
| 84 SupervisedUserServiceFactory::GetForProfile(profile_); | |
|
Marc Treib
2016/05/09 08:22:48
and here
sfiera
2016/05/09 09:33:35
Done.
| |
| 85 for (const auto& whitelist : supervised_user_service->whitelists()) { | |
| 86 results.emplace_back(Whitelist{ | |
|
Marc Treib
2016/05/09 08:22:48
I think when called like this, emplace_back will d
sfiera
2016/05/09 09:33:35
I tried without the explicit ctor, and you're righ
Marc Treib
2016/05/09 09:55:12
Eh, it's fine. I guess I'd slightly prefer push_ba
| |
| 87 whitelist->title(), | |
| 88 whitelist->entry_point(), | |
| 89 whitelist->large_icon_path(), | |
| 90 }); | |
| 91 } | |
| 92 return results; | |
| 93 } | |
| 94 | |
| 95 bool MostVisitedSitesBridge::SupervisorBridge::IsChildProfile() { | |
| 96 return profile_->IsChild(); | |
| 97 } | |
| 98 | |
| 99 void MostVisitedSitesBridge::SupervisorBridge::OnURLFilterChanged() { | |
| 100 if (observer_) { | |
|
Marc Treib
2016/05/09 08:22:48
nit: no braces
sfiera
2016/05/09 09:33:35
(OK, these were mine)
| |
| 101 observer_->OnBlockedSitesChanged(); | |
| 102 } | |
| 103 } | |
| 104 | |
| 52 class MostVisitedSitesBridge::Observer | 105 class MostVisitedSitesBridge::Observer |
| 53 : public MostVisitedSites::Observer { | 106 : public MostVisitedSites::Observer { |
| 54 public: | 107 public: |
| 55 Observer(JNIEnv* env, const JavaParamRef<jobject>& obj); | 108 Observer(JNIEnv* env, const JavaParamRef<jobject>& obj); |
| 56 | 109 |
| 57 void OnMostVisitedURLsAvailable( | 110 void OnMostVisitedURLsAvailable( |
| 58 const MostVisitedSites::SuggestionsVector& suggestions) override; | 111 const MostVisitedSites::SuggestionsVector& suggestions) override; |
| 59 | 112 |
| 60 void OnPopularURLsAvailable( | 113 void OnPopularURLsAvailable( |
| 61 const MostVisitedSites::PopularSitesVector& sites) override; | 114 const MostVisitedSites::PopularSitesVector& sites) override; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 favicon_urls.emplace_back(site.favicon_url.spec()); | 154 favicon_urls.emplace_back(site.favicon_url.spec()); |
| 102 large_icon_urls.emplace_back(site.large_icon_url.spec()); | 155 large_icon_urls.emplace_back(site.large_icon_url.spec()); |
| 103 } | 156 } |
| 104 Java_MostVisitedURLsObserver_onPopularURLsAvailable( | 157 Java_MostVisitedURLsObserver_onPopularURLsAvailable( |
| 105 env, observer_.obj(), ToJavaArrayOfStrings(env, urls).obj(), | 158 env, observer_.obj(), ToJavaArrayOfStrings(env, urls).obj(), |
| 106 ToJavaArrayOfStrings(env, favicon_urls).obj(), | 159 ToJavaArrayOfStrings(env, favicon_urls).obj(), |
| 107 ToJavaArrayOfStrings(env, large_icon_urls).obj()); | 160 ToJavaArrayOfStrings(env, large_icon_urls).obj()); |
| 108 } | 161 } |
| 109 | 162 |
| 110 MostVisitedSitesBridge::MostVisitedSitesBridge(Profile* profile) | 163 MostVisitedSitesBridge::MostVisitedSitesBridge(Profile* profile) |
| 111 : most_visited_(profile->GetPrefs(), | 164 : supervisor_(profile), |
| 165 most_visited_(profile->GetPrefs(), | |
| 112 TemplateURLServiceFactory::GetForProfile(profile), | 166 TemplateURLServiceFactory::GetForProfile(profile), |
| 113 g_browser_process->variations_service(), | 167 g_browser_process->variations_service(), |
| 114 profile->GetRequestContext(), | 168 profile->GetRequestContext(), |
| 115 TopSitesFactory::GetForProfile(profile), | 169 TopSitesFactory::GetForProfile(profile), |
| 116 SuggestionsServiceFactory::GetForProfile(profile), | 170 SuggestionsServiceFactory::GetForProfile(profile), |
| 117 profile->IsChild(), | 171 &supervisor_) { |
| 118 profile) { | |
| 119 // Register the thumbnails debugging page. | 172 // Register the thumbnails debugging page. |
| 120 // TODO(sfiera): find thumbnails a home. They don't belong here. | 173 // TODO(sfiera): find thumbnails a home. They don't belong here. |
| 121 content::URLDataSource::Add(profile, new ThumbnailListSource(profile)); | 174 content::URLDataSource::Add(profile, new ThumbnailListSource(profile)); |
| 122 } | 175 } |
| 123 | 176 |
| 124 MostVisitedSitesBridge::~MostVisitedSitesBridge() {} | 177 MostVisitedSitesBridge::~MostVisitedSitesBridge() {} |
| 125 | 178 |
| 126 void MostVisitedSitesBridge::Destroy( | 179 void MostVisitedSitesBridge::Destroy( |
| 127 JNIEnv* env, const JavaParamRef<jobject>& obj) { | 180 JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 128 delete this; | 181 delete this; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 181 } | 234 } |
| 182 | 235 |
| 183 static jlong Init(JNIEnv* env, | 236 static jlong Init(JNIEnv* env, |
| 184 const JavaParamRef<jobject>& obj, | 237 const JavaParamRef<jobject>& obj, |
| 185 const JavaParamRef<jobject>& jprofile) { | 238 const JavaParamRef<jobject>& jprofile) { |
| 186 MostVisitedSitesBridge* most_visited_sites = | 239 MostVisitedSitesBridge* most_visited_sites = |
| 187 new MostVisitedSitesBridge( | 240 new MostVisitedSitesBridge( |
| 188 ProfileAndroid::FromProfileAndroid(jprofile)); | 241 ProfileAndroid::FromProfileAndroid(jprofile)); |
| 189 return reinterpret_cast<intptr_t>(most_visited_sites); | 242 return reinterpret_cast<intptr_t>(most_visited_sites); |
| 190 } | 243 } |
| OLD | NEW |