diff options
-rw-r--r-- | base/base.gypi | 1 | ||||
-rw-r--r-- | base/ref_counted_memory.cc | 37 | ||||
-rw-r--r-- | base/ref_counted_memory.h | 27 | ||||
-rw-r--r-- | chrome/browser/dom_ui/chrome_url_data_manager.cc | 9 | ||||
-rw-r--r-- | chrome/browser/dom_ui/chrome_url_data_manager.h | 30 | ||||
-rw-r--r-- | chrome/browser/dom_ui/dom_ui_favicon_source.cc | 15 | ||||
-rw-r--r-- | chrome/browser/dom_ui/dom_ui_favicon_source.h | 10 | ||||
-rw-r--r-- | chrome/browser/dom_ui/dom_ui_theme_source.cc | 6 | ||||
-rw-r--r-- | chrome/browser/dom_ui/dom_ui_theme_source.h | 5 | ||||
-rw-r--r-- | chrome/browser/dom_ui/dom_ui_thumbnail_source.cc | 14 | ||||
-rw-r--r-- | chrome/browser/dom_ui/dom_ui_thumbnail_source.h | 16 | ||||
-rw-r--r-- | chrome/browser/dom_ui/most_visited_handler.cc | 32 | ||||
-rw-r--r-- | chrome/browser/dom_ui/most_visited_handler.h | 17 | ||||
-rw-r--r-- | chrome/browser/dom_ui/new_tab_ui.cc | 4 | ||||
-rw-r--r-- | chrome/browser/dom_ui/new_tab_ui.h | 6 |
15 files changed, 152 insertions, 77 deletions
diff --git a/base/base.gypi b/base/base.gypi index 2553ab5..cad0256 100644 --- a/base/base.gypi +++ b/base/base.gypi @@ -176,6 +176,7 @@ 'raw_scoped_refptr_mismatch_checker.h', 'ref_counted.cc', 'ref_counted.h', + 'ref_counted_memory.cc', 'ref_counted_memory.h', 'registry.cc', 'registry.h', diff --git a/base/ref_counted_memory.cc b/base/ref_counted_memory.cc new file mode 100644 index 0000000..04a2634 --- /dev/null +++ b/base/ref_counted_memory.cc @@ -0,0 +1,37 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/ref_counted_memory.h" + +const unsigned char* RefCountedStaticMemory::front() const { + return data_; +} + +size_t RefCountedStaticMemory::size() const { + return length_; +} + +RefCountedBytes* RefCountedBytes::TakeVector( + std::vector<unsigned char>* to_destroy) { + RefCountedBytes* bytes = new RefCountedBytes; + bytes->data.swap(*to_destroy); + return bytes; +} + +RefCountedBytes::RefCountedBytes() { +} + +RefCountedBytes::RefCountedBytes(const std::vector<unsigned char>& initializer) + : data(initializer) { +} + +const unsigned char* RefCountedBytes::front() const { + // STL will assert if we do front() on an empty vector, but calling code + // expects a NULL. + return size() ? &data.front() : NULL; +} + +size_t RefCountedBytes::size() const { + return data.size(); +} diff --git a/base/ref_counted_memory.h b/base/ref_counted_memory.h index a5323cd..9ff8335 100644 --- a/base/ref_counted_memory.h +++ b/base/ref_counted_memory.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -40,8 +40,8 @@ class RefCountedStaticMemory : public RefCountedMemory { RefCountedStaticMemory(const unsigned char* data, size_t length) : data_(data), length_(length) {} - virtual const unsigned char* front() const { return data_; } - virtual size_t size() const { return length_; } + virtual const unsigned char* front() const; + virtual size_t size() const; private: const unsigned char* data_; @@ -57,24 +57,15 @@ class RefCountedBytes : public RefCountedMemory { // Constructs a RefCountedBytes object by performing a swap. (To non // destructively build a RefCountedBytes, use the constructor that takes a // vector.) - static RefCountedBytes* TakeVector(std::vector<unsigned char>* to_destroy) { - RefCountedBytes* bytes = new RefCountedBytes; - bytes->data.swap(*to_destroy); - return bytes; - } + static RefCountedBytes* TakeVector(std::vector<unsigned char>* to_destroy); - RefCountedBytes() {} + RefCountedBytes(); // Constructs a RefCountedBytes object by _copying_ from |initializer|. - RefCountedBytes(const std::vector<unsigned char>& initializer) - : data(initializer) {} - - virtual const unsigned char* front() const { - // STL will assert if we do front() on an empty vector, but calling code - // expects a NULL. - return size() ? &data.front() : NULL; - } - virtual size_t size() const { return data.size(); } + RefCountedBytes(const std::vector<unsigned char>& initializer); + + virtual const unsigned char* front() const; + virtual size_t size() const; std::vector<unsigned char> data; diff --git a/chrome/browser/dom_ui/chrome_url_data_manager.cc b/chrome/browser/dom_ui/chrome_url_data_manager.cc index 3f50a11..ac4312e 100644 --- a/chrome/browser/dom_ui/chrome_url_data_manager.cc +++ b/chrome/browser/dom_ui/chrome_url_data_manager.cc @@ -9,6 +9,7 @@ #include "base/i18n/rtl.h" #include "base/message_loop.h" #include "base/path_service.h" +#include "base/ref_counted_memory.h" #include "base/singleton.h" #include "base/string_util.h" #include "base/thread.h" @@ -270,6 +271,14 @@ void ChromeURLDataManager::DataAvailable( } } +ChromeURLDataManager::DataSource::DataSource(const std::string& source_name, + MessageLoop* message_loop) + : source_name_(source_name), message_loop_(message_loop) { +} + +ChromeURLDataManager::DataSource::~DataSource() { +} + void ChromeURLDataManager::DataSource::SendResponse( RequestID request_id, RefCountedMemory* bytes) { diff --git a/chrome/browser/dom_ui/chrome_url_data_manager.h b/chrome/browser/dom_ui/chrome_url_data_manager.h index 48281f4..0e48ce4 100644 --- a/chrome/browser/dom_ui/chrome_url_data_manager.h +++ b/chrome/browser/dom_ui/chrome_url_data_manager.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -10,12 +10,14 @@ #include <string> #include "base/task.h" -#include "base/ref_counted_memory.h" +#include "base/ref_counted.h" +#include "chrome/browser/chrome_thread.h" class DictionaryValue; class FilePath; class GURL; class MessageLoop; +class RefCountedMemory; class URLRequest; class URLRequestChromeJob; class URLRequestJob; @@ -34,17 +36,21 @@ class ChromeURLDataManager { typedef int RequestID; // A DataSource is an object that can answer requests for data - // asynchronously. It should live on a thread that outlives the IO thread - // (in particular, the UI thread). - // An implementation of DataSource should handle calls to StartDataRequest() - // by starting its (implementation-specific) asynchronous request for - // the data, then call SendResponse() to notify - class DataSource : public base::RefCountedThreadSafe<DataSource> { + // asynchronously. DataSources are collectively owned with refcounting smart + // pointers and should never be deleted on the IO thread, since their calls + // are handled almost always on the UI thread and there's a possibility of a + // data race. + // + // An implementation of DataSource should handle calls to + // StartDataRequest() by starting its (implementation-specific) asynchronous + // request for the data, then call SendResponse() to notify + class DataSource + : public base::RefCountedThreadSafe<DataSource, + ChromeThread::DeleteOnUIThread> { public: // See source_name_ and message_loop_ below for docs on these parameters. DataSource(const std::string& source_name, - MessageLoop* message_loop) - : source_name_(source_name), message_loop_(message_loop) {} + MessageLoop* message_loop); // Sent by the DataManager to request data at |path|. The source should // call SendResponse() when the data is available or if the request could @@ -80,8 +86,10 @@ class ChromeURLDataManager { protected: friend class base::RefCountedThreadSafe<DataSource>; + friend struct ChromeThread::DeleteOnThread<ChromeThread::UI>; + friend class DeleteTask<DataSource>; - virtual ~DataSource() {} + virtual ~DataSource(); private: // The name of this source. diff --git a/chrome/browser/dom_ui/dom_ui_favicon_source.cc b/chrome/browser/dom_ui/dom_ui_favicon_source.cc index f80aa70..d658503 100644 --- a/chrome/browser/dom_ui/dom_ui_favicon_source.cc +++ b/chrome/browser/dom_ui/dom_ui_favicon_source.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -6,6 +6,7 @@ #include "app/resource_bundle.h" #include "base/callback.h" +#include "chrome/browser/chrome_thread.h" #include "chrome/browser/profile.h" #include "chrome/common/url_constants.h" #include "grit/app_resources.h" @@ -15,9 +16,14 @@ DOMUIFavIconSource::DOMUIFavIconSource(Profile* profile) profile_(profile) { } +DOMUIFavIconSource::~DOMUIFavIconSource() { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); +} + void DOMUIFavIconSource::StartDataRequest(const std::string& path, bool is_off_the_record, int request_id) { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); FaviconService* favicon_service = profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); if (favicon_service) { @@ -40,12 +46,19 @@ void DOMUIFavIconSource::StartDataRequest(const std::string& path, } } +std::string DOMUIFavIconSource::GetMimeType(const std::string&) const { + // We need to explicitly return a mime type, otherwise if the user tries to + // drag the image they get no extension. + return "image/png"; +} + void DOMUIFavIconSource::OnFavIconDataAvailable( FaviconService::Handle request_handle, bool know_favicon, scoped_refptr<RefCountedMemory> data, bool expired, GURL icon_url) { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); FaviconService* favicon_service = profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); int request_id = cancelable_consumer_.GetClientData(favicon_service, diff --git a/chrome/browser/dom_ui/dom_ui_favicon_source.h b/chrome/browser/dom_ui/dom_ui_favicon_source.h index 7419288..08cbddb 100644 --- a/chrome/browser/dom_ui/dom_ui_favicon_source.h +++ b/chrome/browser/dom_ui/dom_ui_favicon_source.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -28,11 +28,7 @@ class DOMUIFavIconSource : public ChromeURLDataManager::DataSource { bool is_off_the_record, int request_id); - virtual std::string GetMimeType(const std::string&) const { - // We need to explicitly return a mime type, otherwise if the user tries to - // drag the image they get no extension. - return "image/png"; - } + virtual std::string GetMimeType(const std::string&) const; // Called when favicon data is available from the history backend. void OnFavIconDataAvailable(FaviconService::Handle request_handle, @@ -42,7 +38,7 @@ class DOMUIFavIconSource : public ChromeURLDataManager::DataSource { GURL url); private: - virtual ~DOMUIFavIconSource() {} + virtual ~DOMUIFavIconSource(); Profile* profile_; CancelableRequestConsumerT<int, 0> cancelable_consumer_; diff --git a/chrome/browser/dom_ui/dom_ui_theme_source.cc b/chrome/browser/dom_ui/dom_ui_theme_source.cc index f34091e..e2ecbdf 100644 --- a/chrome/browser/dom_ui/dom_ui_theme_source.cc +++ b/chrome/browser/dom_ui/dom_ui_theme_source.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -7,6 +7,7 @@ #include "app/resource_bundle.h" #include "app/theme_provider.h" #include "base/message_loop.h" +#include "base/ref_counted_memory.h" #include "chrome/browser/browser_theme_provider.h" #include "chrome/browser/chrome_thread.h" #include "chrome/browser/dom_ui/ntp_resource_cache.h" @@ -35,6 +36,9 @@ DOMUIThemeSource::DOMUIThemeSource(Profile* profile) profile->IsOffTheRecord()); } +DOMUIThemeSource::~DOMUIThemeSource() { +} + void DOMUIThemeSource::StartDataRequest(const std::string& path, bool is_off_the_record, int request_id) { diff --git a/chrome/browser/dom_ui/dom_ui_theme_source.h b/chrome/browser/dom_ui/dom_ui_theme_source.h index 7512fbd..61f3abf 100644 --- a/chrome/browser/dom_ui/dom_ui_theme_source.h +++ b/chrome/browser/dom_ui/dom_ui_theme_source.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -11,6 +11,7 @@ #include "chrome/browser/dom_ui/chrome_url_data_manager.h" class Profile; +class RefCountedBytes; // ThumbnailSource is the gateway between network-level chrome: // requests for thumbnails and the history backend that serves these. @@ -29,7 +30,7 @@ class DOMUIThemeSource : public ChromeURLDataManager::DataSource { virtual MessageLoop* MessageLoopForRequestPath(const std::string& path) const; protected: - virtual ~DOMUIThemeSource() {} + virtual ~DOMUIThemeSource(); private: // Fetch and send the theme bitmap. diff --git a/chrome/browser/dom_ui/dom_ui_thumbnail_source.cc b/chrome/browser/dom_ui/dom_ui_thumbnail_source.cc index a89c92f..6e18bd4 100644 --- a/chrome/browser/dom_ui/dom_ui_thumbnail_source.cc +++ b/chrome/browser/dom_ui/dom_ui_thumbnail_source.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -22,9 +22,14 @@ DOMUIThumbnailSource::DOMUIThumbnailSource(Profile* profile) profile_(profile) { } +DOMUIThumbnailSource::~DOMUIThumbnailSource() { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); +} + void DOMUIThumbnailSource::StartDataRequest(const std::string& path, bool is_off_the_record, int request_id) { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTopSites)) { scoped_refptr<history::TopSites> top_sites = profile_->GetTopSites(); RefCountedBytes* data = NULL; @@ -51,6 +56,12 @@ void DOMUIThumbnailSource::StartDataRequest(const std::string& path, } } +std::string DOMUIThumbnailSource::GetMimeType(const std::string&) const { + // We need to explicitly return a mime type, otherwise if the user tries to + // drag the image they get no extension. + return "image/png"; +} + void DOMUIThumbnailSource::SendDefaultThumbnail(int request_id) { // Use placeholder thumbnail. if (!default_thumbnail_.get()) { @@ -64,6 +75,7 @@ void DOMUIThumbnailSource::SendDefaultThumbnail(int request_id) { void DOMUIThumbnailSource::OnThumbnailDataAvailable( HistoryService::Handle request_handle, scoped_refptr<RefCountedBytes> data) { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); int request_id = cancelable_consumer_.GetClientData(hs, request_handle); diff --git a/chrome/browser/dom_ui/dom_ui_thumbnail_source.h b/chrome/browser/dom_ui/dom_ui_thumbnail_source.h index cf4fd79..ce007f5 100644 --- a/chrome/browser/dom_ui/dom_ui_thumbnail_source.h +++ b/chrome/browser/dom_ui/dom_ui_thumbnail_source.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -7,8 +7,6 @@ #pragma once #include <string> -#include <utility> -#include <vector> #include "base/basictypes.h" #include "base/scoped_ptr.h" @@ -31,18 +29,14 @@ class DOMUIThumbnailSource : public ChromeURLDataManager::DataSource { bool is_off_the_record, int request_id); - virtual std::string GetMimeType(const std::string&) const { - // We need to explicitly return a mime type, otherwise if the user tries to - // drag the image they get no extension. - return "image/png"; - } + virtual std::string GetMimeType(const std::string&) const; // Called when thumbnail data is available from the history backend. void OnThumbnailDataAvailable(HistoryService::Handle request_handle, scoped_refptr<RefCountedBytes> data); private: - ~DOMUIThumbnailSource() {} + virtual ~DOMUIThumbnailSource(); // Send the default thumbnail when we are missing a real one. void SendDefaultThumbnail(int request_id); @@ -54,10 +48,6 @@ class DOMUIThumbnailSource : public ChromeURLDataManager::DataSource { // database doesn't have a thumbnail for a webpage. scoped_refptr<RefCountedMemory> default_thumbnail_; - // Store requests when the ThumbnailStore isn't ready. When a notification is - // received that it is ready, then serve these requests. - std::vector<std::pair<std::string, int> > pending_requests_; - // To register to be notified when the ThumbnailStore is ready. NotificationRegistrar registrar_; diff --git a/chrome/browser/dom_ui/most_visited_handler.cc b/chrome/browser/dom_ui/most_visited_handler.cc index 401827a..93c9d17 100644 --- a/chrome/browser/dom_ui/most_visited_handler.cc +++ b/chrome/browser/dom_ui/most_visited_handler.cc @@ -33,6 +33,7 @@ #include "chrome/common/notification_type.h" #include "chrome/common/notification_source.h" #include "chrome/common/pref_names.h" +#include "googleurl/src/gurl.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" #include "grit/locale_settings.h" @@ -45,18 +46,17 @@ const size_t kMostVisitedPages = 8; // The number of days of history we consider for most visited entries. const int kMostVisitedScope = 90; -// Adds the fields in the page to the dictionary. -void SetMostVisistedPage(DictionaryValue* dict, - const MostVisitedHandler::MostVisitedPage& page) { - NewTabUI::SetURLTitleAndDirection(dict, WideToUTF16(page.title), page.url); - if (!page.favicon_url.is_empty()) - dict->SetString(L"faviconUrl", page.favicon_url.spec()); - if (!page.thumbnail_url.is_empty()) - dict->SetString(L"thumbnailUrl", page.thumbnail_url.spec()); -} - } // namespace +// This struct is used when getting the pre-populated pages in case the user +// hasn't filled up his most visited pages. +struct MostVisitedHandler::MostVisitedPage { + std::wstring title; + GURL url; + GURL thumbnail_url; + GURL favicon_url; +}; + MostVisitedHandler::MostVisitedHandler() : url_blacklist_(NULL), pinned_urls_(NULL), @@ -541,6 +541,18 @@ bool MostVisitedHandler::IsFirstRun() { } // static +void MostVisitedHandler::SetMostVisistedPage( + DictionaryValue* dict, + const MostVisitedHandler::MostVisitedPage& page) { + NewTabUI::SetURLTitleAndDirection(dict, WideToUTF16(page.title), page.url); + if (!page.favicon_url.is_empty()) + dict->SetString(L"faviconUrl", page.favicon_url.spec()); + if (!page.thumbnail_url.is_empty()) + dict->SetString(L"thumbnailUrl", page.thumbnail_url.spec()); +} + + +// static const std::vector<MostVisitedHandler::MostVisitedPage>& MostVisitedHandler::GetPrePopulatedPages() { // TODO(arv): This needs to get the data from some configurable place. diff --git a/chrome/browser/dom_ui/most_visited_handler.h b/chrome/browser/dom_ui/most_visited_handler.h index 8f74e25..bc6ac80 100644 --- a/chrome/browser/dom_ui/most_visited_handler.h +++ b/chrome/browser/dom_ui/most_visited_handler.h @@ -14,9 +14,9 @@ #include "chrome/browser/history/history_types.h" #include "chrome/common/notification_observer.h" #include "chrome/common/notification_registrar.h" -#include "googleurl/src/gurl.h" class DictionaryValue; +class GURL; class ListValue; class PageUsageData; class PrefService; @@ -26,14 +26,6 @@ class Value; class MostVisitedHandler : public DOMMessageHandler, public NotificationObserver { public: - // This struct is used when getting the pre-populated pages in case the user - // hasn't filled up his most visited pages. - struct MostVisitedPage { - std::wstring title; - GURL url; - GURL thumbnail_url; - GURL favicon_url; - }; MostVisitedHandler(); virtual ~MostVisitedHandler() { } @@ -75,6 +67,8 @@ class MostVisitedHandler : public DOMMessageHandler, static GURL GetChromeStoreURLWithLocale(); private: + struct MostVisitedPage; + // Send a request to the HistoryService to get the most visited pages. void StartQueryForMostVisited(); @@ -111,6 +105,11 @@ class MostVisitedHandler : public DOMMessageHandler, // Returns true if we should treat this as the first run of the new tab page. bool IsFirstRun(); + // Adds the fields in the page to the dictionary. + static void SetMostVisistedPage( + DictionaryValue* dict, + const MostVisitedHandler::MostVisitedPage& page); + static const std::vector<MostVisitedPage>& GetPrePopulatedPages(); static MostVisitedPage GetChromeStorePage(); diff --git a/chrome/browser/dom_ui/new_tab_ui.cc b/chrome/browser/dom_ui/new_tab_ui.cc index 6d2bdde..4bb445d 100644 --- a/chrome/browser/dom_ui/new_tab_ui.cc +++ b/chrome/browser/dom_ui/new_tab_ui.cc @@ -656,3 +656,7 @@ void NewTabUI::NewTabHTMLSource::StartDataRequest(const std::string& path, SendResponse(request_id, html_bytes); } + +std::string NewTabUI::NewTabHTMLSource::GetMimeType(const std::string&) const { + return "text/html"; +} diff --git a/chrome/browser/dom_ui/new_tab_ui.h b/chrome/browser/dom_ui/new_tab_ui.h index b6358c4..0f798d0 100644 --- a/chrome/browser/dom_ui/new_tab_ui.h +++ b/chrome/browser/dom_ui/new_tab_ui.h @@ -60,16 +60,14 @@ class NewTabUI : public DOMUI, bool is_off_the_record, int request_id); - virtual std::string GetMimeType(const std::string&) const { - return "text/html"; - } + virtual std::string GetMimeType(const std::string&) const; // Setters and getters for first_run. static void set_first_run(bool first_run) { first_run_ = first_run; } static bool first_run() { return first_run_; } private: - ~NewTabHTMLSource() {} + virtual ~NewTabHTMLSource() {} // Whether this is the first run. static bool first_run_; |