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

Side by Side Diff: chrome/browser/android/provider/chrome_browser_provider.cc

Issue 745463002: Revert of Revert of ChromeBrowserProvider shouldn't own the FaviconService (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2171
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « chrome/browser/android/provider/chrome_browser_provider.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/android/provider/chrome_browser_provider.h" 5 #include "chrome/browser/android/provider/chrome_browser_provider.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <list> 8 #include <list>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 private: 642 private:
643 Service* service_; 643 Service* service_;
644 base::CancelableTaskTracker* cancelable_tracker_; 644 base::CancelableTaskTracker* cancelable_tracker_;
645 645
646 DISALLOW_COPY_AND_ASSIGN(AsyncServiceRequest); 646 DISALLOW_COPY_AND_ASSIGN(AsyncServiceRequest);
647 }; 647 };
648 648
649 // Base class for all asynchronous blocking tasks that use the favicon service. 649 // Base class for all asynchronous blocking tasks that use the favicon service.
650 class FaviconServiceTask : public AsyncServiceRequest<FaviconService> { 650 class FaviconServiceTask : public AsyncServiceRequest<FaviconService> {
651 public: 651 public:
652 FaviconServiceTask(FaviconService* service, 652 FaviconServiceTask(base::CancelableTaskTracker* cancelable_tracker,
653 base::CancelableTaskTracker* cancelable_tracker,
654 Profile* profile) 653 Profile* profile)
655 : AsyncServiceRequest<FaviconService>(service, cancelable_tracker), 654 : AsyncServiceRequest<FaviconService>(
655 FaviconServiceFactory::GetForProfile(profile,
656 Profile::EXPLICIT_ACCESS),
657 cancelable_tracker),
656 profile_(profile) {} 658 profile_(profile) {}
657 659
658 Profile* profile() const { return profile_; } 660 Profile* profile() const { return profile_; }
659 661
660 private: 662 private:
661 Profile* profile_; 663 Profile* profile_;
662 664
663 DISALLOW_COPY_AND_ASSIGN(FaviconServiceTask); 665 DISALLOW_COPY_AND_ASSIGN(FaviconServiceTask);
664 }; 666 };
665 667
666 // Retrieves the favicon or touch icon for a URL from the FaviconService. 668 // Retrieves the favicon or touch icon for a URL from the FaviconService.
667 class BookmarkIconFetchTask : public FaviconServiceTask { 669 class BookmarkIconFetchTask : public FaviconServiceTask {
668 public: 670 public:
669 BookmarkIconFetchTask(FaviconService* favicon_service, 671 BookmarkIconFetchTask(base::CancelableTaskTracker* cancelable_tracker,
670 base::CancelableTaskTracker* cancelable_tracker,
671 Profile* profile) 672 Profile* profile)
672 : FaviconServiceTask(favicon_service, cancelable_tracker, profile) {} 673 : FaviconServiceTask(cancelable_tracker, profile) {}
673 674
674 favicon_base::FaviconRawBitmapResult Run(const GURL& url) { 675 favicon_base::FaviconRawBitmapResult Run(const GURL& url) {
675 float max_scale = ui::GetScaleForScaleFactor( 676 float max_scale = ui::GetScaleForScaleFactor(
676 ResourceBundle::GetSharedInstance().GetMaxScaleFactor()); 677 ResourceBundle::GetSharedInstance().GetMaxScaleFactor());
677 int desired_size_in_pixel = std::ceil(gfx::kFaviconSize * max_scale); 678 int desired_size_in_pixel = std::ceil(gfx::kFaviconSize * max_scale);
679
680 if (service() == NULL)
681 return favicon_base::FaviconRawBitmapResult();
682
678 RunAsyncRequestOnUIThreadBlocking( 683 RunAsyncRequestOnUIThreadBlocking(
679 base::Bind(&FaviconService::GetRawFaviconForPageURL, 684 base::Bind(&FaviconService::GetRawFaviconForPageURL,
680 base::Unretained(service()), 685 base::Unretained(service()),
681 url, 686 url,
682 favicon_base::FAVICON | favicon_base::TOUCH_ICON, 687 favicon_base::FAVICON | favicon_base::TOUCH_ICON,
683 desired_size_in_pixel, 688 desired_size_in_pixel,
684 base::Bind(&BookmarkIconFetchTask::OnFaviconRetrieved, 689 base::Bind(&BookmarkIconFetchTask::OnFaviconRetrieved,
685 base::Unretained(this)), 690 base::Unretained(this)),
686 cancelable_tracker())); 691 cancelable_tracker()));
687 return result_; 692 return result_;
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
1153 } 1158 }
1154 1159
1155 ChromeBrowserProvider::ChromeBrowserProvider(JNIEnv* env, jobject obj) 1160 ChromeBrowserProvider::ChromeBrowserProvider(JNIEnv* env, jobject obj)
1156 : weak_java_provider_(env, obj), 1161 : weak_java_provider_(env, obj),
1157 handling_extensive_changes_(false) { 1162 handling_extensive_changes_(false) {
1158 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1163 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1159 profile_ = g_browser_process->profile_manager()->GetLastUsedProfile(); 1164 profile_ = g_browser_process->profile_manager()->GetLastUsedProfile();
1160 bookmark_model_ = BookmarkModelFactory::GetForProfile(profile_); 1165 bookmark_model_ = BookmarkModelFactory::GetForProfile(profile_);
1161 top_sites_ = profile_->GetTopSites(); 1166 top_sites_ = profile_->GetTopSites();
1162 service_.reset(new AndroidHistoryProviderService(profile_)); 1167 service_.reset(new AndroidHistoryProviderService(profile_));
1163 favicon_service_.reset(FaviconServiceFactory::GetForProfile(profile_,
1164 Profile::EXPLICIT_ACCESS));
1165 1168
1166 // Registers the notifications we are interested. 1169 // Registers the notifications we are interested.
1167 bookmark_model_->AddObserver(this); 1170 bookmark_model_->AddObserver(this);
1168 notification_registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URL_VISITED, 1171 notification_registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URL_VISITED,
1169 content::NotificationService::AllSources()); 1172 content::NotificationService::AllSources());
1170 notification_registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, 1173 notification_registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED,
1171 content::NotificationService::AllSources()); 1174 content::NotificationService::AllSources());
1172 notification_registrar_.Add(this, 1175 notification_registrar_.Add(this,
1173 chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_UPDATED, 1176 chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_UPDATED,
1174 content::NotificationService::AllSources()); 1177 content::NotificationService::AllSources());
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
1541 IsInMobileBookmarksBranchTask task(bookmark_model_); 1544 IsInMobileBookmarksBranchTask task(bookmark_model_);
1542 return task.Run(id); 1545 return task.Run(id);
1543 } 1546 }
1544 1547
1545 ScopedJavaLocalRef<jbyteArray> ChromeBrowserProvider::GetFaviconOrTouchIcon( 1548 ScopedJavaLocalRef<jbyteArray> ChromeBrowserProvider::GetFaviconOrTouchIcon(
1546 JNIEnv* env, jobject obj, jstring jurl) { 1549 JNIEnv* env, jobject obj, jstring jurl) {
1547 if (!jurl) 1550 if (!jurl)
1548 return ScopedJavaLocalRef<jbyteArray>(); 1551 return ScopedJavaLocalRef<jbyteArray>();
1549 1552
1550 GURL url = GURL(ConvertJavaStringToUTF16(env, jurl)); 1553 GURL url = GURL(ConvertJavaStringToUTF16(env, jurl));
1551 BookmarkIconFetchTask favicon_task( 1554 BookmarkIconFetchTask favicon_task(&cancelable_task_tracker_, profile_);
1552 favicon_service_.get(), &cancelable_task_tracker_, profile_);
1553 favicon_base::FaviconRawBitmapResult bitmap_result = favicon_task.Run(url); 1555 favicon_base::FaviconRawBitmapResult bitmap_result = favicon_task.Run(url);
1554 1556
1555 if (!bitmap_result.is_valid() || !bitmap_result.bitmap_data.get()) 1557 if (!bitmap_result.is_valid() || !bitmap_result.bitmap_data.get())
1556 return ScopedJavaLocalRef<jbyteArray>(); 1558 return ScopedJavaLocalRef<jbyteArray>();
1557 1559
1558 return base::android::ToJavaByteArray(env, bitmap_result.bitmap_data->front(), 1560 return base::android::ToJavaByteArray(env, bitmap_result.bitmap_data->front(),
1559 bitmap_result.bitmap_data->size()); 1561 bitmap_result.bitmap_data->size());
1560 } 1562 }
1561 1563
1562 ScopedJavaLocalRef<jbyteArray> ChromeBrowserProvider::GetThumbnail( 1564 ScopedJavaLocalRef<jbyteArray> ChromeBrowserProvider::GetThumbnail(
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1616 Java_ChromeBrowserProvider_onHistoryChanged(env, obj.obj()); 1618 Java_ChromeBrowserProvider_onHistoryChanged(env, obj.obj());
1617 } else if (type == 1619 } else if (type ==
1618 chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_UPDATED) { 1620 chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_UPDATED) {
1619 JNIEnv* env = AttachCurrentThread(); 1621 JNIEnv* env = AttachCurrentThread();
1620 ScopedJavaLocalRef<jobject> obj = weak_java_provider_.get(env); 1622 ScopedJavaLocalRef<jobject> obj = weak_java_provider_.get(env);
1621 if (obj.is_null()) 1623 if (obj.is_null())
1622 return; 1624 return;
1623 Java_ChromeBrowserProvider_onSearchTermChanged(env, obj.obj()); 1625 Java_ChromeBrowserProvider_onSearchTermChanged(env, obj.obj());
1624 } 1626 }
1625 } 1627 }
OLDNEW
« no previous file with comments | « chrome/browser/android/provider/chrome_browser_provider.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698