Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / history / history_backend_unittest.cc
index c010b3e..bc00726 100644 (file)
 #include "base/strings/string16.h"
 #include "base/strings/string_number_conversions.h"
 #include "base/strings/utf_string_conversions.h"
-#include "chrome/browser/bookmarks/bookmark_model.h"
-#include "chrome/browser/bookmarks/bookmark_model_factory.h"
-#include "chrome/browser/bookmarks/bookmark_test_helpers.h"
-#include "chrome/browser/bookmarks/bookmark_utils.h"
+#include "chrome/browser/chrome_notification_types.h"
 #include "chrome/browser/history/history_notifications.h"
 #include "chrome/browser/history/history_service.h"
 #include "chrome/browser/history/history_service_factory.h"
-#include "chrome/browser/history/in_memory_database.h"
 #include "chrome/browser/history/in_memory_history_backend.h"
 #include "chrome/browser/history/visit_filter.h"
 #include "chrome/common/chrome_constants.h"
 #include "chrome/common/chrome_paths.h"
 #include "chrome/common/importer/imported_favicon_usage.h"
 #include "chrome/test/base/testing_profile.h"
+#include "components/history/core/browser/in_memory_database.h"
+#include "components/history/core/browser/keyword_search_term.h"
+#include "components/history/core/test/history_client_fake_bookmarks.h"
 #include "content/public/browser/notification_details.h"
 #include "content/public/browser/notification_source.h"
 #include "content/public/test/test_browser_thread.h"
+#include "testing/gmock/include/gmock/gmock.h"
 #include "testing/gtest/include/gtest/gtest.h"
 #include "url/gurl.h"
 
@@ -49,9 +49,13 @@ using base::Time;
 
 namespace {
 
-static const gfx::Size kTinySize = gfx::Size(10, 10);
-static const gfx::Size kSmallSize = gfx::Size(16, 16);
-static const gfx::Size kLargeSize = gfx::Size(32, 32);
+const int kTinyEdgeSize = 10;
+const int kSmallEdgeSize = 16;
+const int kLargeEdgeSize = 32;
+
+const gfx::Size kTinySize = gfx::Size(kTinyEdgeSize, kTinyEdgeSize);
+const gfx::Size kSmallSize = gfx::Size(kSmallEdgeSize, kSmallEdgeSize);
+const gfx::Size kLargeSize = gfx::Size(kLargeEdgeSize, kLargeEdgeSize);
 
 // Comparison functions as to make it easier to check results of
 // GetFaviconBitmaps() and GetIconMappingsForPageURL().
@@ -65,17 +69,23 @@ bool FaviconBitmapLessThan(const history::FaviconBitmap& a,
   return a.pixel_size.GetArea() < b.pixel_size.GetArea();
 }
 
+class HistoryClientMock : public history::HistoryClientFakeBookmarks {
+ public:
+  MOCK_METHOD0(BlockUntilBookmarksLoaded, void());
+};
+
 }  // namespace
 
 namespace history {
 
-class HistoryBackendTest;
+class HistoryBackendTestBase;
 
 // This must be a separate object since HistoryBackend manages its lifetime.
 // This just forwards the messages we're interested in to the test object.
 class HistoryBackendTestDelegate : public HistoryBackend::Delegate {
  public:
-  explicit HistoryBackendTestDelegate(HistoryBackendTest* test) : test_(test) {}
+  explicit HistoryBackendTestDelegate(HistoryBackendTestBase* test)
+      : test_(test) {}
 
   virtual void NotifyProfileError(sql::InitStatus init_status) OVERRIDE {}
   virtual void SetInMemoryBackend(
@@ -89,65 +99,114 @@ class HistoryBackendTestDelegate : public HistoryBackend::Delegate {
 
  private:
   // Not owned by us.
-  HistoryBackendTest* test_;
+  HistoryBackendTestBase* test_;
 
   DISALLOW_COPY_AND_ASSIGN(HistoryBackendTestDelegate);
 };
 
-class HistoryBackendCancelableRequest
-    : public CancelableRequestProvider,
-      public CancelableRequestConsumerTSimple<int> {
+class HistoryBackendTestBase : public testing::Test {
  public:
-  HistoryBackendCancelableRequest() {}
+  typedef std::vector<std::pair<int, HistoryDetails*> > NotificationList;
 
-  template<class RequestType>
-  CancelableRequestProvider::Handle MockScheduleOfRequest(
-      RequestType* request) {
-    AddRequest(request, this);
-    return request->handle();
-  }
-};
+  HistoryBackendTestBase()
+      : loaded_(false),
+        ui_thread_(content::BrowserThread::UI, &message_loop_) {}
 
-class HistoryBackendTest : public testing::Test {
- public:
-  HistoryBackendTest()
-      : bookmark_model_(NULL),
-        loaded_(false),
-        num_broadcasted_notifications_(0),
-        ui_thread_(content::BrowserThread::UI, &message_loop_) {
+  virtual ~HistoryBackendTestBase() {
+    STLDeleteValues(&broadcasted_notifications_);
   }
 
-  virtual ~HistoryBackendTest() {
+ protected:
+  int num_broadcasted_notifications() const {
+    return broadcasted_notifications_.size();
   }
 
-  // Callback for QueryMostVisited.
-  void OnQueryMostVisited(CancelableRequestProvider::Handle handle,
-                          history::MostVisitedURLList data) {
-    most_visited_list_.swap(data);
+  const NotificationList& broadcasted_notifications() const {
+    return broadcasted_notifications_;
   }
 
-  // Callback for QueryFiltered.
-  void OnQueryFiltered(CancelableRequestProvider::Handle handle,
-                       const history::FilteredURLList& data) {
-    filtered_list_ = data;
+  void ClearBroadcastedNotifications() {
+    STLDeleteValues(&broadcasted_notifications_);
   }
 
-  const history::MostVisitedURLList& get_most_visited_list() const {
-    return most_visited_list_;
+  base::FilePath test_dir() {
+    return test_dir_;
   }
 
-  const history::FilteredURLList& get_filtered_list() const {
-    return filtered_list_;
-  }
+  void BroadcastNotifications(int type, scoped_ptr<HistoryDetails> details) {
+    // Send the notifications directly to the in-memory database.
+    content::Details<HistoryDetails> det(details.get());
+    mem_backend_->Observe(
+        type, content::Source<HistoryBackendTestBase>(NULL), det);
 
-  int num_broadcasted_notifications() const {
-    return num_broadcasted_notifications_;
+    // The backend passes ownership of the details pointer to us.
+    broadcasted_notifications_.push_back(
+        std::make_pair(type, details.release()));
   }
 
- protected:
+  history::HistoryClientFakeBookmarks history_client_;
   scoped_refptr<HistoryBackend> backend_;  // Will be NULL on init failure.
   scoped_ptr<InMemoryHistoryBackend> mem_backend_;
+  bool loaded_;
+
+ private:
+  friend class HistoryBackendTestDelegate;
+
+  // testing::Test
+  virtual void SetUp() {
+    if (!base::CreateNewTempDirectory(FILE_PATH_LITERAL("BackendTest"),
+                                      &test_dir_))
+      return;
+    backend_ = new HistoryBackend(
+        test_dir_, new HistoryBackendTestDelegate(this), &history_client_);
+    backend_->Init(std::string(), false);
+  }
 
+  virtual void TearDown() {
+    if (backend_.get())
+      backend_->Closing();
+    backend_ = NULL;
+    mem_backend_.reset();
+    base::DeleteFile(test_dir_, true);
+    base::RunLoop().RunUntilIdle();
+    history_client_.ClearAllBookmarks();
+  }
+
+  void SetInMemoryBackend(scoped_ptr<InMemoryHistoryBackend> backend) {
+    mem_backend_.swap(backend);
+  }
+
+  // The types and details of notifications which were broadcasted.
+  NotificationList broadcasted_notifications_;
+
+  base::MessageLoop message_loop_;
+  base::FilePath test_dir_;
+  content::TestBrowserThread ui_thread_;
+
+  DISALLOW_COPY_AND_ASSIGN(HistoryBackendTestBase);
+};
+
+void HistoryBackendTestDelegate::SetInMemoryBackend(
+    scoped_ptr<InMemoryHistoryBackend> backend) {
+  test_->SetInMemoryBackend(backend.Pass());
+}
+
+void HistoryBackendTestDelegate::BroadcastNotifications(
+    int type,
+    scoped_ptr<HistoryDetails> details) {
+  test_->BroadcastNotifications(type, details.Pass());
+}
+
+void HistoryBackendTestDelegate::DBLoaded() {
+  test_->loaded_ = true;
+}
+
+class HistoryBackendTest : public HistoryBackendTestBase {
+ public:
+  HistoryBackendTest() {}
+  virtual ~HistoryBackendTest() {}
+
+ protected:
   void AddRedirectChain(const char* sequence[], int page_id) {
     AddRedirectChainWithTransitionAndTime(sequence, page_id,
                                           content::PAGE_TRANSITION_LINK,
@@ -163,11 +222,9 @@ class HistoryBackendTest : public testing::Test {
     for (int i = 0; sequence[i] != NULL; ++i)
       redirects.push_back(GURL(sequence[i]));
 
-    int int_scope = 1;
-    void* scope = 0;
-    memcpy(&scope, &int_scope, sizeof(int_scope));
+    ContextID context_id = reinterpret_cast<ContextID>(1);
     history::HistoryAddPageArgs request(
-        redirects.back(), time, scope, page_id, GURL(),
+        redirects.back(), time, context_id, page_id, GURL(),
         redirects, transition, history::SOURCE_BROWSED,
         true);
     backend_->AddPage(request);
@@ -183,23 +240,23 @@ class HistoryBackendTest : public testing::Test {
   void AddClientRedirect(const GURL& url1, const GURL& url2, bool did_replace,
                          base::Time time,
                          int* transition1, int* transition2) {
-    void* const dummy_scope = reinterpret_cast<void*>(0x87654321);
+    ContextID dummy_context_id = reinterpret_cast<ContextID>(0x87654321);
     history::RedirectList redirects;
     if (url1.is_valid())
       redirects.push_back(url1);
     if (url2.is_valid())
       redirects.push_back(url2);
     HistoryAddPageArgs request(
-        url2, time, dummy_scope, 0, url1,
+        url2, time, dummy_context_id, 0, url1,
         redirects, content::PAGE_TRANSITION_CLIENT_REDIRECT,
         history::SOURCE_BROWSED, did_replace);
     backend_->AddPage(request);
 
-    *transition1 = getTransition(url1);
-    *transition2 = getTransition(url2);
+    *transition1 = GetTransition(url1);
+    *transition2 = GetTransition(url2);
   }
 
-  int getTransition(const GURL& url) {
+  int GetTransition(const GURL& url) {
     if (!url.is_valid())
       return 0;
     URLRow row;
@@ -209,52 +266,40 @@ class HistoryBackendTest : public testing::Test {
     return visits[0].transition;
   }
 
-  base::FilePath getTestDir() {
-    return test_dir_;
-  }
-
-  // Returns a gfx::Size vector with small size.
-  const std::vector<gfx::Size> GetSizesSmall() {
-    std::vector<gfx::Size> sizes_small;
-    sizes_small.push_back(kSmallSize);
+  // Returns a vector with the small edge size.
+  const std::vector<int> GetEdgeSizesSmall() {
+    std::vector<int> sizes_small;
+    sizes_small.push_back(kSmallEdgeSize);
     return sizes_small;
   }
 
-  // Returns a gfx::Size vector with large size.
-  const std::vector<gfx::Size> GetSizesLarge() {
-    std::vector<gfx::Size> sizes_large;
-    sizes_large.push_back(kLargeSize);
+  // Returns a vector with the large edge size.
+  const std::vector<int> GetEdgeSizesLarge() {
+    std::vector<int> sizes_large;
+    sizes_large.push_back(kLargeEdgeSize);
     return sizes_large;
   }
 
-  // Returns a gfx::Size vector with small and large sizes.
-  const std::vector<gfx::Size> GetSizesSmallAndLarge() {
-    std::vector<gfx::Size> sizes_small_and_large;
-    sizes_small_and_large.push_back(kSmallSize);
-    sizes_small_and_large.push_back(kLargeSize);
+  // Returns a vector with the small and large edge sizes.
+  const std::vector<int> GetEdgeSizesSmallAndLarge() {
+    std::vector<int> sizes_small_and_large;
+    sizes_small_and_large.push_back(kSmallEdgeSize);
+    sizes_small_and_large.push_back(kLargeEdgeSize);
     return sizes_small_and_large;
   }
 
-  // Returns a gfx::Size vector with tiny, small and large sizes.
-  const std::vector<gfx::Size> GetSizesTinySmallAndLarge() {
-    std::vector<gfx::Size> sizes_tiny_small_and_large;
-    sizes_tiny_small_and_large.push_back(kTinySize);
-    sizes_tiny_small_and_large.push_back(kSmallSize);
-    sizes_tiny_small_and_large.push_back(kLargeSize);
+  // Returns a vector with the tiny, small, and large edge sizes.
+  const std::vector<int> GetEdgeSizesTinySmallAndLarge() {
+    std::vector<int> sizes_tiny_small_and_large;
+    sizes_tiny_small_and_large.push_back(kTinyEdgeSize);
+    sizes_tiny_small_and_large.push_back(kSmallEdgeSize);
+    sizes_tiny_small_and_large.push_back(kLargeEdgeSize);
     return sizes_tiny_small_and_large;
   }
 
-  // Returns 1x and 2x scale factors.
-  const std::vector<ui::ScaleFactor> GetScaleFactors1x2x() {
-    std::vector<ui::ScaleFactor> scale_factors_1x_2x;
-    scale_factors_1x_2x.push_back(ui::SCALE_FACTOR_100P);
-    scale_factors_1x_2x.push_back(ui::SCALE_FACTOR_200P);
-    return scale_factors_1x_2x;
-  }
-
   // Returns the number of icon mappings of |icon_type| to |page_url|.
   size_t NumIconMappingsForPageURL(const GURL& page_url,
-                                   chrome::IconType icon_type) {
+                                   favicon_base::IconType icon_type) {
     std::vector<IconMapping> icon_mappings;
     backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, icon_type,
                                                        &icon_mappings);
@@ -278,7 +323,7 @@ class HistoryBackendTest : public testing::Test {
 
   // Returns the favicon bitmaps for |icon_id| sorted by pixel size in
   // ascending order. Returns true if there is at least one favicon bitmap.
-  bool GetSortedFaviconBitmaps(chrome::FaviconID icon_id,
+  bool GetSortedFaviconBitmaps(favicon_base::FaviconID icon_id,
                                std::vector<FaviconBitmap>* favicon_bitmaps) {
     if (!backend_->thumbnail_db_->GetFaviconBitmaps(icon_id, favicon_bitmaps))
       return false;
@@ -289,7 +334,7 @@ class HistoryBackendTest : public testing::Test {
 
   // Returns true if there is exactly one favicon bitmap associated to
   // |favicon_id|. If true, returns favicon bitmap in output parameter.
-  bool GetOnlyFaviconBitmap(const chrome::FaviconID icon_id,
+  bool GetOnlyFaviconBitmap(const favicon_base::FaviconID icon_id,
                             FaviconBitmap* favicon_bitmap) {
     std::vector<FaviconBitmap> favicon_bitmaps;
     if (!backend_->thumbnail_db_->GetFaviconBitmaps(icon_id, &favicon_bitmaps))
@@ -305,28 +350,29 @@ class HistoryBackendTest : public testing::Test {
   // alphabet starting at 'a' for the entry at index 0.
   void GenerateFaviconBitmapData(
       const GURL& icon_url1,
-      const std::vector<gfx::Size>& icon_url1_sizes,
-      std::vector<chrome::FaviconBitmapData>* favicon_bitmap_data) {
+      const std::vector<int>& icon_url1_sizes,
+      std::vector<favicon_base::FaviconRawBitmapData>* favicon_bitmap_data) {
     GenerateFaviconBitmapData(icon_url1, icon_url1_sizes, GURL(),
-                              std::vector<gfx::Size>(), favicon_bitmap_data);
+                              std::vector<int>(), favicon_bitmap_data);
   }
 
   void GenerateFaviconBitmapData(
       const GURL& icon_url1,
-      const std::vector<gfx::Size>& icon_url1_sizes,
+      const std::vector<int>& icon_url1_sizes,
       const GURL& icon_url2,
-      const std::vector<gfx::Size>& icon_url2_sizes,
-      std::vector<chrome::FaviconBitmapData>* favicon_bitmap_data) {
+      const std::vector<int>& icon_url2_sizes,
+      std::vector<favicon_base::FaviconRawBitmapData>* favicon_bitmap_data) {
     favicon_bitmap_data->clear();
 
     char bitmap_char = 'a';
     for (size_t i = 0; i < icon_url1_sizes.size(); ++i) {
       std::vector<unsigned char> data;
       data.push_back(bitmap_char);
-      chrome::FaviconBitmapData bitmap_data_element;
+      favicon_base::FaviconRawBitmapData bitmap_data_element;
       bitmap_data_element.bitmap_data =
           base::RefCountedBytes::TakeVector(&data);
-      bitmap_data_element.pixel_size = icon_url1_sizes[i];
+      bitmap_data_element.pixel_size =
+          gfx::Size(icon_url1_sizes[i], icon_url1_sizes[i]);
       bitmap_data_element.icon_url = icon_url1;
       favicon_bitmap_data->push_back(bitmap_data_element);
 
@@ -336,10 +382,11 @@ class HistoryBackendTest : public testing::Test {
     for (size_t i = 0; i < icon_url2_sizes.size(); ++i) {
       std::vector<unsigned char> data;
       data.push_back(bitmap_char);
-      chrome::FaviconBitmapData bitmap_data_element;
+      favicon_base::FaviconRawBitmapData bitmap_data_element;
       bitmap_data_element.bitmap_data =
           base::RefCountedBytes::TakeVector(&data);
-      bitmap_data_element.pixel_size = icon_url2_sizes[i];
+      bitmap_data_element.pixel_size =
+          gfx::Size(icon_url2_sizes[i], icon_url2_sizes[i]);
       bitmap_data_element.icon_url = icon_url2;
       favicon_bitmap_data->push_back(bitmap_data_element);
 
@@ -355,70 +402,99 @@ class HistoryBackendTest : public testing::Test {
            *bitmap_data->front() == expected_data;
   }
 
-  BookmarkModel bookmark_model_;
-
- protected:
-  bool loaded_;
-
  private:
-  friend class HistoryBackendTestDelegate;
+  DISALLOW_COPY_AND_ASSIGN(HistoryBackendTest);
+};
 
-  // testing::Test
-  virtual void SetUp() {
-    if (!base::CreateNewTempDirectory(FILE_PATH_LITERAL("BackendTest"),
-                                      &test_dir_))
-      return;
-    backend_ = new HistoryBackend(test_dir_,
-                                  new HistoryBackendTestDelegate(this),
-                                  &bookmark_model_);
-    backend_->Init(std::string(), false);
+class InMemoryHistoryBackendTest : public HistoryBackendTestBase {
+ public:
+  InMemoryHistoryBackendTest() {}
+  virtual ~InMemoryHistoryBackendTest() {}
+
+ protected:
+  void SimulateNotification(int type,
+                            const URLRow* row1,
+                            const URLRow* row2 = NULL,
+                            const URLRow* row3 = NULL) {
+    URLRows rows;
+    rows.push_back(*row1);
+    if (row2) rows.push_back(*row2);
+    if (row3) rows.push_back(*row3);
+
+    if (type == chrome::NOTIFICATION_HISTORY_URLS_MODIFIED) {
+      scoped_ptr<URLsModifiedDetails> details(new URLsModifiedDetails());
+      details->changed_urls.swap(rows);
+      BroadcastNotifications(type, details.PassAs<HistoryDetails>());
+    } else if (type == chrome::NOTIFICATION_HISTORY_URL_VISITED) {
+      for (URLRows::const_iterator it = rows.begin(); it != rows.end(); ++it) {
+        scoped_ptr<URLVisitedDetails> details(new URLVisitedDetails());
+        details->row = *it;
+        BroadcastNotifications(type, details.PassAs<HistoryDetails>());
+      }
+    } else if (type == chrome::NOTIFICATION_HISTORY_URLS_DELETED) {
+      scoped_ptr<URLsDeletedDetails> details(new URLsDeletedDetails());
+      details->rows = rows;
+      BroadcastNotifications(type, details.PassAs<HistoryDetails>());
+    } else {
+      NOTREACHED();
+    }
   }
 
-  virtual void TearDown() {
-    if (backend_.get())
-      backend_->Closing();
-    backend_ = NULL;
-    mem_backend_.reset();
-    base::DeleteFile(test_dir_, true);
-    base::RunLoop().RunUntilIdle();
+  size_t GetNumberOfMatchingSearchTerms(const int keyword_id,
+                                        const base::string16& prefix) {
+    std::vector<KeywordSearchTermVisit> matching_terms;
+    mem_backend_->db()->GetMostRecentKeywordSearchTerms(
+        keyword_id, prefix, 1, &matching_terms);
+    return matching_terms.size();
   }
 
-  void SetInMemoryBackend(scoped_ptr<InMemoryHistoryBackend> backend) {
-    mem_backend_.swap(backend);
+  static URLRow CreateTestTypedURL() {
+    URLRow url_row(GURL("https://www.google.com/"));
+    url_row.set_id(10);
+    url_row.set_title(base::UTF8ToUTF16("Google Search"));
+    url_row.set_typed_count(1);
+    url_row.set_visit_count(1);
+    url_row.set_last_visit(Time::Now() - base::TimeDelta::FromHours(1));
+    return url_row;
   }
 
-  void BroadcastNotifications(int type, scoped_ptr<HistoryDetails> details) {
-    ++num_broadcasted_notifications_;
+  static URLRow CreateAnotherTestTypedURL() {
+    URLRow url_row(GURL("https://maps.google.com/"));
+    url_row.set_id(20);
+    url_row.set_title(base::UTF8ToUTF16("Google Maps"));
+    url_row.set_typed_count(2);
+    url_row.set_visit_count(3);
+    url_row.set_last_visit(Time::Now() - base::TimeDelta::FromHours(2));
+    return url_row;
+  }
 
-    // Send the notifications directly to the in-memory database.
-    content::Details<HistoryDetails> det(details.get());
-    mem_backend_->Observe(type, content::Source<HistoryBackendTest>(NULL), det);
+  static URLRow CreateTestNonTypedURL() {
+    URLRow url_row(GURL("https://news.google.com/"));
+    url_row.set_id(30);
+    url_row.set_title(base::UTF8ToUTF16("Google News"));
+    url_row.set_visit_count(5);
+    url_row.set_last_visit(Time::Now() - base::TimeDelta::FromHours(3));
+    return url_row;
   }
 
-  // The number of notifications which were broadcasted.
-  int num_broadcasted_notifications_;
+  void PopulateTestURLsAndSearchTerms(URLRow* row1,
+                                      URLRow* row2,
+                                      const base::string16& term1,
+                                      const base::string16& term2);
 
-  base::MessageLoop message_loop_;
-  base::FilePath test_dir_;
-  history::MostVisitedURLList most_visited_list_;
-  history::FilteredURLList filtered_list_;
-  content::TestBrowserThread ui_thread_;
-};
+  void TestAddingAndChangingURLRows(int notification_type);
 
-void HistoryBackendTestDelegate::SetInMemoryBackend(
-    scoped_ptr<InMemoryHistoryBackend> backend) {
-  test_->SetInMemoryBackend(backend.Pass());
-}
+  static const KeywordID kTestKeywordId;
+  static const char kTestSearchTerm1[];
+  static const char kTestSearchTerm2[];
 
-void HistoryBackendTestDelegate::BroadcastNotifications(
-    int type,
-    scoped_ptr<HistoryDetails> details) {
-  test_->BroadcastNotifications(type, details.Pass());
-}
+ private:
+  DISALLOW_COPY_AND_ASSIGN(InMemoryHistoryBackendTest);
+};
 
-void HistoryBackendTestDelegate::DBLoaded() {
-  test_->loaded_ = true;
-}
+const KeywordID InMemoryHistoryBackendTest::kTestKeywordId = 42;
+const char InMemoryHistoryBackendTest::kTestSearchTerm1[] = "banana";
+const char InMemoryHistoryBackendTest::kTestSearchTerm2[] = "orange";
 
 // http://crbug.com/114287
 #if defined(OS_WIN)
@@ -440,10 +516,10 @@ TEST_F(HistoryBackendTest, DeleteAll) {
   // we can test that updating works properly.
   GURL favicon_url1("http://www.google.com/favicon.ico");
   GURL favicon_url2("http://news.google.com/favicon.ico");
-  chrome::FaviconID favicon2 = backend_->thumbnail_db_->AddFavicon(favicon_url2,
-      chrome::FAVICON);
-  chrome::FaviconID favicon1 = backend_->thumbnail_db_->AddFavicon(favicon_url1,
-      chrome::FAVICON);
+  favicon_base::FaviconID favicon2 =
+      backend_->thumbnail_db_->AddFavicon(favicon_url2, favicon_base::FAVICON);
+  favicon_base::FaviconID favicon1 =
+      backend_->thumbnail_db_->AddFavicon(favicon_url1, favicon_base::FAVICON);
 
   std::vector<unsigned char> data;
   data.push_back('a');
@@ -496,10 +572,10 @@ TEST_F(HistoryBackendTest, DeleteAll) {
   EXPECT_TRUE(mem_backend_->db_->GetRowForURL(row1.url(), NULL));
 
   // Star row1.
-  bookmark_model_.AddURL(
-      bookmark_model_.bookmark_bar_node(), 0, base::string16(), row1.url());
+  history_client_.AddBookmark(row1.url());
 
   // Now finally clear all history.
+  ClearBroadcastedNotifications();
   backend_->DeleteAllHistory();
 
   // The first URL should be preserved but the time should be cleared.
@@ -520,8 +596,9 @@ TEST_F(HistoryBackendTest, DeleteAll) {
 
   // We should have a favicon and favicon bitmaps for the first URL only. We
   // look them up by favicon URL since the IDs may have changed.
-  chrome::FaviconID out_favicon1 = backend_->thumbnail_db_->
-      GetFaviconIDForFaviconURL(favicon_url1, chrome::FAVICON, NULL);
+  favicon_base::FaviconID out_favicon1 =
+      backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
+          favicon_url1, favicon_base::FAVICON, NULL);
   EXPECT_TRUE(out_favicon1);
 
   std::vector<FaviconBitmap> favicon_bitmaps;
@@ -545,20 +622,30 @@ TEST_F(HistoryBackendTest, DeleteAll) {
   EXPECT_TRUE(BitmapDataEqual('b', favicon_bitmap2.bitmap_data));
   EXPECT_EQ(kLargeSize, favicon_bitmap2.pixel_size);
 
-  chrome::FaviconID out_favicon2 = backend_->thumbnail_db_->
-      GetFaviconIDForFaviconURL(favicon_url2, chrome::FAVICON, NULL);
+  favicon_base::FaviconID out_favicon2 =
+      backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
+          favicon_url2, favicon_base::FAVICON, NULL);
   EXPECT_FALSE(out_favicon2) << "Favicon not deleted";
 
   // The remaining URL should still reference the same favicon, even if its
   // ID has changed.
   std::vector<IconMapping> mappings;
   EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(
-      outrow1.url(), chrome::FAVICON, &mappings));
+      outrow1.url(), favicon_base::FAVICON, &mappings));
   EXPECT_EQ(1u, mappings.size());
   EXPECT_EQ(out_favicon1, mappings[0].icon_id);
 
   // The first URL should still be bookmarked.
-  EXPECT_TRUE(bookmark_model_.IsBookmarked(row1.url()));
+  EXPECT_TRUE(history_client_.IsBookmarked(row1.url()));
+
+  // Check that we fire the notification about all history having been deleted.
+  ASSERT_EQ(1u, broadcasted_notifications().size());
+  ASSERT_EQ(chrome::NOTIFICATION_HISTORY_URLS_DELETED,
+            broadcasted_notifications()[0].first);
+  const URLsDeletedDetails* details = static_cast<const URLsDeletedDetails*>(
+      broadcasted_notifications()[0].second);
+  EXPECT_TRUE(details->all_history);
+  EXPECT_FALSE(details->expired);
 }
 
 // Checks that adding a visit, then calling DeleteAll, and then trying to add
@@ -611,20 +698,20 @@ TEST_F(HistoryBackendTest, URLsNoLongerBookmarked) {
 
   std::vector<unsigned char> data;
   data.push_back('1');
-  chrome::FaviconID favicon1 = backend_->thumbnail_db_->AddFavicon(
-      favicon_url1,
-      chrome::FAVICON,
-      new base::RefCountedBytes(data),
-      Time::Now(),
-      gfx::Size());
+  favicon_base::FaviconID favicon1 =
+      backend_->thumbnail_db_->AddFavicon(favicon_url1,
+                                          favicon_base::FAVICON,
+                                          new base::RefCountedBytes(data),
+                                          Time::Now(),
+                                          gfx::Size());
 
   data[0] = '2';
-  chrome::FaviconID favicon2 = backend_->thumbnail_db_->AddFavicon(
-      favicon_url2,
-      chrome::FAVICON,
-      new base::RefCountedBytes(data),
-      Time::Now(),
-      gfx::Size());
+  favicon_base::FaviconID favicon2 =
+      backend_->thumbnail_db_->AddFavicon(favicon_url2,
+                                          favicon_base::FAVICON,
+                                          new base::RefCountedBytes(data),
+                                          Time::Now(),
+                                          gfx::Size());
 
   // First visit two URLs.
   URLRow row1(GURL("http://www.google.com/"));
@@ -647,10 +734,8 @@ TEST_F(HistoryBackendTest, URLsNoLongerBookmarked) {
   URLID row2_id = backend_->db_->GetRowForURL(row2.url(), NULL);
 
   // Star the two URLs.
-  bookmark_utils::AddIfNotBookmarked(&bookmark_model_, row1.url(),
-                                     base::string16());
-  bookmark_utils::AddIfNotBookmarked(&bookmark_model_, row2.url(),
-                                     base::string16());
+  history_client_.AddBookmark(row1.url());
+  history_client_.AddBookmark(row2.url());
 
   // Delete url 2. Because url 2 is starred this won't delete the URL, only
   // the visits.
@@ -664,12 +749,11 @@ TEST_F(HistoryBackendTest, URLsNoLongerBookmarked) {
   EXPECT_EQ(0U, visits.size());
   // The favicon should still be valid.
   EXPECT_EQ(favicon2,
-      backend_->thumbnail_db_->GetFaviconIDForFaviconURL(favicon_url2,
-                                                         chrome::FAVICON,
-                                                         NULL));
+            backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
+                favicon_url2, favicon_base::FAVICON, NULL));
 
   // Unstar row2.
-  bookmark_utils::RemoveAllBookmarks(&bookmark_model_, row2.url());
+  history_client_.DelBookmark(row2.url());
 
   // Tell the backend it was unstarred. We have to explicitly do this as
   // BookmarkModel isn't wired up to the backend during testing.
@@ -681,12 +765,12 @@ TEST_F(HistoryBackendTest, URLsNoLongerBookmarked) {
   EXPECT_FALSE(backend_->db_->GetRowForURL(row2.url(), &tmp_url_row));
   // And the favicon should be deleted.
   EXPECT_EQ(0,
-      backend_->thumbnail_db_->GetFaviconIDForFaviconURL(favicon_url2,
-                                                         chrome::FAVICON,
-                                                         NULL));
+            backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
+                favicon_url2, favicon_base::FAVICON, NULL));
 
   // Unstar row 1.
-  bookmark_utils::RemoveAllBookmarks(&bookmark_model_, row1.url());
+  history_client_.DelBookmark(row1.url());
+
   // Tell the backend it was unstarred. We have to explicitly do this as
   // BookmarkModel isn't wired up to the backend during testing.
   unstarred_urls.clear();
@@ -703,9 +787,8 @@ TEST_F(HistoryBackendTest, URLsNoLongerBookmarked) {
 
   // The favicon should still be valid.
   EXPECT_EQ(favicon1,
-      backend_->thumbnail_db_->GetFaviconIDForFaviconURL(favicon_url1,
-                                                         chrome::FAVICON,
-                                                         NULL));
+            backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
+                favicon_url1, favicon_base::FAVICON, NULL));
 }
 
 // Tests a handful of assertions for a navigation with a type of
@@ -787,15 +870,193 @@ TEST_F(HistoryBackendTest, ClientRedirect) {
   EXPECT_TRUE(transition2 & content::PAGE_TRANSITION_CHAIN_END);
 }
 
+TEST_F(HistoryBackendTest, AddPagesWithDetails) {
+  ASSERT_TRUE(backend_.get());
+
+  // Import one non-typed URL, and two recent and one expired typed URLs.
+  URLRow row1(GURL("https://news.google.com/"));
+  row1.set_visit_count(1);
+  row1.set_last_visit(Time::Now());
+  URLRow row2(GURL("https://www.google.com/"));
+  row2.set_typed_count(1);
+  row2.set_last_visit(Time::Now());
+  URLRow row3(GURL("https://mail.google.com/"));
+  row3.set_visit_count(1);
+  row3.set_typed_count(1);
+  row3.set_last_visit(Time::Now() - base::TimeDelta::FromDays(7 - 1));
+  URLRow row4(GURL("https://maps.google.com/"));
+  row4.set_visit_count(1);
+  row4.set_typed_count(1);
+  row4.set_last_visit(Time::Now() - base::TimeDelta::FromDays(365 + 2));
+
+  URLRows rows;
+  rows.push_back(row1);
+  rows.push_back(row2);
+  rows.push_back(row3);
+  rows.push_back(row4);
+  backend_->AddPagesWithDetails(rows, history::SOURCE_BROWSED);
+
+  // Verify that recent URLs have ended up in the main |db_|, while the already
+  // expired URL has been ignored.
+  URLRow stored_row1, stored_row2, stored_row3, stored_row4;
+  EXPECT_NE(0, backend_->db_->GetRowForURL(row1.url(), &stored_row1));
+  EXPECT_NE(0, backend_->db_->GetRowForURL(row2.url(), &stored_row2));
+  EXPECT_NE(0, backend_->db_->GetRowForURL(row3.url(), &stored_row3));
+  EXPECT_EQ(0, backend_->db_->GetRowForURL(row4.url(), &stored_row4));
+
+  // Ensure that a notification was fired for both typed and non-typed URLs.
+  // Further verify that the IDs in the notification are set to those that are
+  // in effect in the main database. The InMemoryHistoryBackend relies on this
+  // for caching.
+  ASSERT_EQ(1u, broadcasted_notifications().size());
+  ASSERT_EQ(chrome::NOTIFICATION_HISTORY_URLS_MODIFIED,
+            broadcasted_notifications()[0].first);
+  const URLsModifiedDetails* details = static_cast<const URLsModifiedDetails*>(
+      broadcasted_notifications()[0].second);
+  EXPECT_EQ(3u, details->changed_urls.size());
+
+  URLRows::const_iterator it_row1 = std::find_if(
+      details->changed_urls.begin(),
+      details->changed_urls.end(),
+      history::URLRow::URLRowHasURL(row1.url()));
+  ASSERT_NE(details->changed_urls.end(), it_row1);
+  EXPECT_EQ(stored_row1.id(), it_row1->id());
+
+  URLRows::const_iterator it_row2 = std::find_if(
+        details->changed_urls.begin(),
+        details->changed_urls.end(),
+        history::URLRow::URLRowHasURL(row2.url()));
+  ASSERT_NE(details->changed_urls.end(), it_row2);
+  EXPECT_EQ(stored_row2.id(), it_row2->id());
+
+  URLRows::const_iterator it_row3 = std::find_if(
+        details->changed_urls.begin(),
+        details->changed_urls.end(),
+        history::URLRow::URLRowHasURL(row3.url()));
+  ASSERT_NE(details->changed_urls.end(), it_row3);
+  EXPECT_EQ(stored_row3.id(), it_row3->id());
+}
+
+TEST_F(HistoryBackendTest, UpdateURLs) {
+  ASSERT_TRUE(backend_.get());
+
+  // Add three pages directly to the database.
+  URLRow row1(GURL("https://news.google.com/"));
+  row1.set_visit_count(1);
+  row1.set_last_visit(Time::Now());
+  URLRow row2(GURL("https://maps.google.com/"));
+  row2.set_visit_count(2);
+  row2.set_last_visit(Time::Now());
+  URLRow row3(GURL("https://www.google.com/"));
+  row3.set_visit_count(3);
+  row3.set_last_visit(Time::Now());
+
+  backend_->db_->AddURL(row1);
+  backend_->db_->AddURL(row2);
+  backend_->db_->AddURL(row3);
+
+  // Now create changed versions of all URLRows by incrementing their visit
+  // counts, and in the meantime, also delete the second row from the database.
+  URLRow altered_row1, altered_row2, altered_row3;
+  backend_->db_->GetRowForURL(row1.url(), &altered_row1);
+  altered_row1.set_visit_count(42);
+  backend_->db_->GetRowForURL(row2.url(), &altered_row2);
+  altered_row2.set_visit_count(43);
+  backend_->db_->GetRowForURL(row3.url(), &altered_row3);
+  altered_row3.set_visit_count(44);
+
+  backend_->db_->DeleteURLRow(altered_row2.id());
+
+  // Now try to update all three rows at once. The change to the second URLRow
+  // should be ignored, as it is no longer present in the DB.
+  URLRows rows;
+  rows.push_back(altered_row1);
+  rows.push_back(altered_row2);
+  rows.push_back(altered_row3);
+  EXPECT_EQ(2u, backend_->UpdateURLs(rows));
+
+  URLRow stored_row1, stored_row3;
+  EXPECT_NE(0, backend_->db_->GetRowForURL(row1.url(), &stored_row1));
+  EXPECT_NE(0, backend_->db_->GetRowForURL(row3.url(), &stored_row3));
+  EXPECT_EQ(altered_row1.visit_count(), stored_row1.visit_count());
+  EXPECT_EQ(altered_row3.visit_count(), stored_row3.visit_count());
+
+  // Ensure that a notification was fired, and further verify that the IDs in
+  // the notification are set to those that are in effect in the main database.
+  // The InMemoryHistoryBackend relies on this for caching.
+  ASSERT_EQ(1u, broadcasted_notifications().size());
+  ASSERT_EQ(chrome::NOTIFICATION_HISTORY_URLS_MODIFIED,
+            broadcasted_notifications()[0].first);
+  const URLsModifiedDetails* details = static_cast<const URLsModifiedDetails*>(
+      broadcasted_notifications()[0].second);
+  EXPECT_EQ(2u, details->changed_urls.size());
+
+  URLRows::const_iterator it_row1 =
+      std::find_if(details->changed_urls.begin(),
+                   details->changed_urls.end(),
+                   history::URLRow::URLRowHasURL(row1.url()));
+  ASSERT_NE(details->changed_urls.end(), it_row1);
+  EXPECT_EQ(altered_row1.id(), it_row1->id());
+  EXPECT_EQ(altered_row1.visit_count(), it_row1->visit_count());
+
+  URLRows::const_iterator it_row3 =
+      std::find_if(details->changed_urls.begin(),
+                   details->changed_urls.end(),
+                   history::URLRow::URLRowHasURL(row3.url()));
+  ASSERT_NE(details->changed_urls.end(), it_row3);
+  EXPECT_EQ(altered_row3.id(), it_row3->id());
+  EXPECT_EQ(altered_row3.visit_count(), it_row3->visit_count());
+}
+
+// This verifies that a notification is fired. In-depth testing of logic should
+// be done in HistoryTest.SetTitle.
+TEST_F(HistoryBackendTest, SetPageTitleFiresNotificationWithCorrectDetails) {
+  const char kTestUrlTitle[] = "Google Search";
+
+  ASSERT_TRUE(backend_.get());
+
+  // Add two pages, then change the title of the second one.
+  URLRow row1(GURL("https://news.google.com/"));
+  row1.set_typed_count(1);
+  row1.set_last_visit(Time::Now());
+  URLRow row2(GURL("https://www.google.com/"));
+  row2.set_visit_count(2);
+  row2.set_last_visit(Time::Now());
+
+  URLRows rows;
+  rows.push_back(row1);
+  rows.push_back(row2);
+  backend_->AddPagesWithDetails(rows, history::SOURCE_BROWSED);
+
+  ClearBroadcastedNotifications();
+  backend_->SetPageTitle(row2.url(), base::UTF8ToUTF16(kTestUrlTitle));
+
+  // Ensure that a notification was fired, and further verify that the IDs in
+  // the notification are set to those that are in effect in the main database.
+  // The InMemoryHistoryBackend relies on this for caching.
+  URLRow stored_row2;
+  EXPECT_TRUE(backend_->GetURL(row2.url(), &stored_row2));
+  ASSERT_EQ(1u, broadcasted_notifications().size());
+  ASSERT_EQ(chrome::NOTIFICATION_HISTORY_URLS_MODIFIED,
+            broadcasted_notifications()[0].first);
+  const URLsModifiedDetails* details = static_cast<const URLsModifiedDetails*>(
+      broadcasted_notifications()[0].second);
+  ASSERT_EQ(1u, details->changed_urls.size());
+  EXPECT_EQ(base::UTF8ToUTF16(kTestUrlTitle), details->changed_urls[0].title());
+  EXPECT_EQ(stored_row2.id(), details->changed_urls[0].id());
+}
+
+// There's no importer on Android.
+#if !defined(OS_ANDROID)
 TEST_F(HistoryBackendTest, ImportedFaviconsTest) {
   // Setup test data - two Urls in the history, one with favicon assigned and
   // one without.
   GURL favicon_url1("http://www.google.com/favicon.ico");
   std::vector<unsigned char> data;
   data.push_back('1');
-  chrome::FaviconID favicon1 = backend_->thumbnail_db_->AddFavicon(
+  favicon_base::FaviconID favicon1 = backend_->thumbnail_db_->AddFavicon(
       favicon_url1,
-      chrome::FAVICON,
+      favicon_base::FAVICON,
       base::RefCountedBytes::TakeVector(&data),
       Time::Now(),
       gfx::Size());
@@ -814,8 +1075,8 @@ TEST_F(HistoryBackendTest, ImportedFaviconsTest) {
   URLRow url_row1, url_row2;
   EXPECT_FALSE(backend_->db_->GetRowForURL(row1.url(), &url_row1) == 0);
   EXPECT_FALSE(backend_->db_->GetRowForURL(row2.url(), &url_row2) == 0);
-  EXPECT_EQ(1u, NumIconMappingsForPageURL(row1.url(), chrome::FAVICON));
-  EXPECT_EQ(0u, NumIconMappingsForPageURL(row2.url(), chrome::FAVICON));
+  EXPECT_EQ(1u, NumIconMappingsForPageURL(row1.url(), favicon_base::FAVICON));
+  EXPECT_EQ(0u, NumIconMappingsForPageURL(row2.url(), favicon_base::FAVICON));
 
   // Now provide one imported favicon for both URLs already in the registry.
   // The new favicon should only be used with the URL that doesn't already have
@@ -833,14 +1094,14 @@ TEST_F(HistoryBackendTest, ImportedFaviconsTest) {
 
   std::vector<IconMapping> mappings;
   EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(
-      row1.url(), chrome::FAVICON, &mappings));
+      row1.url(), favicon_base::FAVICON, &mappings));
   EXPECT_EQ(1u, mappings.size());
   EXPECT_EQ(favicon1, mappings[0].icon_id);
   EXPECT_EQ(favicon_url1, mappings[0].icon_url);
 
   mappings.clear();
   EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(
-    row2.url(), chrome::FAVICON, &mappings));
+      row2.url(), favicon_base::FAVICON, &mappings));
   EXPECT_EQ(1u, mappings.size());
   EXPECT_EQ(favicon.favicon_url, mappings[0].icon_url);
 
@@ -857,12 +1118,12 @@ TEST_F(HistoryBackendTest, ImportedFaviconsTest) {
   EXPECT_TRUE(backend_->db_->GetRowForURL(url3, &url_row3) == 0);
 
   // If the URL is bookmarked, it should get added to history with 0 visits.
-  bookmark_model_.AddURL(bookmark_model_.bookmark_bar_node(), 0,
-                         base::string16(), url3);
+  history_client_.AddBookmark(url3);
   backend_->SetImportedFavicons(favicons);
   EXPECT_FALSE(backend_->db_->GetRowForURL(url3, &url_row3) == 0);
   EXPECT_TRUE(url_row3.visit_count() == 0);
 }
+#endif  // !defined(OS_ANDROID)
 
 TEST_F(HistoryBackendTest, StripUsernamePasswordTest) {
   ASSERT_TRUE(backend_.get());
@@ -975,6 +1236,56 @@ TEST_F(HistoryBackendTest, AddPageVisitNotLastVisit) {
   ASSERT_EQ(recent_time, row.last_visit());
 }
 
+TEST_F(HistoryBackendTest, AddPageVisitFiresNotificationWithCorrectDetails) {
+  ASSERT_TRUE(backend_.get());
+
+  GURL url1("http://www.google.com");
+  GURL url2("http://maps.google.com");
+
+  // Clear all history.
+  backend_->DeleteAllHistory();
+  ClearBroadcastedNotifications();
+
+  // Visit two distinct URLs, the second one twice.
+  backend_->AddPageVisit(url1, base::Time::Now(), 0,
+                         content::PAGE_TRANSITION_LINK,
+                         history::SOURCE_BROWSED);
+  for (int i = 0; i < 2; ++i) {
+    backend_->AddPageVisit(url2, base::Time::Now(), 0,
+                           content::PAGE_TRANSITION_TYPED,
+                           history::SOURCE_BROWSED);
+  }
+
+  URLRow stored_row1, stored_row2;
+  EXPECT_NE(0, backend_->db_->GetRowForURL(url1, &stored_row1));
+  EXPECT_NE(0, backend_->db_->GetRowForURL(url2, &stored_row2));
+
+  // Expect that NOTIFICATION_HISTORY_URLS_VISITED has been fired 3x, and that
+  // each time, the URLRows have the correct URLs and IDs set.
+  ASSERT_EQ(3, num_broadcasted_notifications());
+  ASSERT_EQ(chrome::NOTIFICATION_HISTORY_URL_VISITED,
+            broadcasted_notifications()[0].first);
+  const URLVisitedDetails* details = static_cast<const URLVisitedDetails*>(
+      broadcasted_notifications()[0].second);
+  EXPECT_EQ(content::PAGE_TRANSITION_LINK,
+            content::PageTransitionStripQualifier(details->transition));
+  EXPECT_EQ(stored_row1.id(), details->row.id());
+  EXPECT_EQ(stored_row1.url(), details->row.url());
+
+  // No further checking, this case analogous to the first one.
+  ASSERT_EQ(chrome::NOTIFICATION_HISTORY_URL_VISITED,
+            broadcasted_notifications()[1].first);
+
+  ASSERT_EQ(chrome::NOTIFICATION_HISTORY_URL_VISITED,
+            broadcasted_notifications()[2].first);
+  details = static_cast<const URLVisitedDetails*>(
+      broadcasted_notifications()[2].second);
+  EXPECT_EQ(content::PAGE_TRANSITION_TYPED,
+            content::PageTransitionStripQualifier(details->transition));
+  EXPECT_EQ(stored_row2.id(), details->row.id());
+  EXPECT_EQ(stored_row2.url(), details->row.url());
+}
+
 TEST_F(HistoryBackendTest, AddPageArgsSource) {
   ASSERT_TRUE(backend_.get());
 
@@ -1201,16 +1512,15 @@ TEST_F(HistoryBackendTest, MigrationVisitSource) {
 
   // Copy history database file to current directory so that it will be deleted
   // in Teardown.
-  base::FilePath new_history_path(getTestDir());
+  base::FilePath new_history_path(test_dir());
   base::DeleteFile(new_history_path, true);
   base::CreateDirectory(new_history_path);
   base::FilePath new_history_file =
       new_history_path.Append(chrome::kHistoryFilename);
   ASSERT_TRUE(base::CopyFile(old_history_path, new_history_file));
 
-  backend_ = new HistoryBackend(new_history_path,
-                                new HistoryBackendTestDelegate(this),
-                                &bookmark_model_);
+  backend_ = new HistoryBackend(
+      new_history_path, new HistoryBackendTestDelegate(this), &history_client_);
   backend_->Init(std::string(), false);
   backend_->Closing();
   backend_ = NULL;
@@ -1263,55 +1573,60 @@ TEST_F(HistoryBackendTest, SetFaviconMappingsForPageAndRedirects) {
   const GURL icon_url2("http://www.google.com/icon2");
 
   // Generate bitmap data for a page with two favicons.
-  std::vector<chrome::FaviconBitmapData> two_favicon_bitmap_data;
-  GenerateFaviconBitmapData(icon_url1, GetSizesSmallAndLarge(),
-      icon_url2, GetSizesSmallAndLarge(), &two_favicon_bitmap_data);
+  std::vector<favicon_base::FaviconRawBitmapData> two_favicon_bitmap_data;
+  GenerateFaviconBitmapData(icon_url1, GetEdgeSizesSmallAndLarge(),
+      icon_url2, GetEdgeSizesSmallAndLarge(), &two_favicon_bitmap_data);
 
   // Generate bitmap data for a page with a single favicon.
-  std::vector<chrome::FaviconBitmapData> one_favicon_bitmap_data;
-  GenerateFaviconBitmapData(icon_url1, GetSizesSmallAndLarge(),
+  std::vector<favicon_base::FaviconRawBitmapData> one_favicon_bitmap_data;
+  GenerateFaviconBitmapData(icon_url1, GetEdgeSizesSmallAndLarge(),
                             &one_favicon_bitmap_data);
 
   // Add two favicons
-  backend_->SetFavicons(url1, chrome::FAVICON, two_favicon_bitmap_data);
-  EXPECT_EQ(2u, NumIconMappingsForPageURL(url1, chrome::FAVICON));
-  EXPECT_EQ(2u, NumIconMappingsForPageURL(url2, chrome::FAVICON));
+  backend_->SetFavicons(url1, favicon_base::FAVICON, two_favicon_bitmap_data);
+  EXPECT_EQ(2u, NumIconMappingsForPageURL(url1, favicon_base::FAVICON));
+  EXPECT_EQ(2u, NumIconMappingsForPageURL(url2, favicon_base::FAVICON));
 
   // Add one touch_icon
-  backend_->SetFavicons(url1, chrome::TOUCH_ICON, one_favicon_bitmap_data);
-  EXPECT_EQ(1u, NumIconMappingsForPageURL(url1, chrome::TOUCH_ICON));
-  EXPECT_EQ(1u, NumIconMappingsForPageURL(url2, chrome::TOUCH_ICON));
-  EXPECT_EQ(2u, NumIconMappingsForPageURL(url1, chrome::FAVICON));
+  backend_->SetFavicons(
+      url1, favicon_base::TOUCH_ICON, one_favicon_bitmap_data);
+  EXPECT_EQ(1u, NumIconMappingsForPageURL(url1, favicon_base::TOUCH_ICON));
+  EXPECT_EQ(1u, NumIconMappingsForPageURL(url2, favicon_base::TOUCH_ICON));
+  EXPECT_EQ(2u, NumIconMappingsForPageURL(url1, favicon_base::FAVICON));
 
   // Add one TOUCH_PRECOMPOSED_ICON
   backend_->SetFavicons(
-      url1, chrome::TOUCH_PRECOMPOSED_ICON, one_favicon_bitmap_data);
+      url1, favicon_base::TOUCH_PRECOMPOSED_ICON, one_favicon_bitmap_data);
   // The touch_icon was replaced.
-  EXPECT_EQ(0u, NumIconMappingsForPageURL(url1, chrome::TOUCH_ICON));
-  EXPECT_EQ(2u, NumIconMappingsForPageURL(url1, chrome::FAVICON));
-  EXPECT_EQ(1u,
-            NumIconMappingsForPageURL(url1, chrome::TOUCH_PRECOMPOSED_ICON));
-  EXPECT_EQ(1u,
-            NumIconMappingsForPageURL(url2, chrome::TOUCH_PRECOMPOSED_ICON));
+  EXPECT_EQ(0u, NumIconMappingsForPageURL(url1, favicon_base::TOUCH_ICON));
+  EXPECT_EQ(2u, NumIconMappingsForPageURL(url1, favicon_base::FAVICON));
+  EXPECT_EQ(
+      1u,
+      NumIconMappingsForPageURL(url1, favicon_base::TOUCH_PRECOMPOSED_ICON));
+  EXPECT_EQ(
+      1u,
+      NumIconMappingsForPageURL(url2, favicon_base::TOUCH_PRECOMPOSED_ICON));
 
   // Add a touch_icon.
-  backend_->SetFavicons(url1, chrome::TOUCH_ICON, one_favicon_bitmap_data);
-  EXPECT_EQ(1u, NumIconMappingsForPageURL(url1, chrome::TOUCH_ICON));
-  EXPECT_EQ(2u, NumIconMappingsForPageURL(url1, chrome::FAVICON));
+  backend_->SetFavicons(
+      url1, favicon_base::TOUCH_ICON, one_favicon_bitmap_data);
+  EXPECT_EQ(1u, NumIconMappingsForPageURL(url1, favicon_base::TOUCH_ICON));
+  EXPECT_EQ(2u, NumIconMappingsForPageURL(url1, favicon_base::FAVICON));
   // The TOUCH_PRECOMPOSED_ICON was replaced.
-  EXPECT_EQ(0u,
-            NumIconMappingsForPageURL(url1, chrome::TOUCH_PRECOMPOSED_ICON));
+  EXPECT_EQ(
+      0u,
+      NumIconMappingsForPageURL(url1, favicon_base::TOUCH_PRECOMPOSED_ICON));
 
   // Add a single favicon.
-  backend_->SetFavicons(url1, chrome::FAVICON, one_favicon_bitmap_data);
-  EXPECT_EQ(1u, NumIconMappingsForPageURL(url1, chrome::TOUCH_ICON));
-  EXPECT_EQ(1u, NumIconMappingsForPageURL(url1, chrome::FAVICON));
-  EXPECT_EQ(1u, NumIconMappingsForPageURL(url2, chrome::FAVICON));
+  backend_->SetFavicons(url1, favicon_base::FAVICON, one_favicon_bitmap_data);
+  EXPECT_EQ(1u, NumIconMappingsForPageURL(url1, favicon_base::TOUCH_ICON));
+  EXPECT_EQ(1u, NumIconMappingsForPageURL(url1, favicon_base::FAVICON));
+  EXPECT_EQ(1u, NumIconMappingsForPageURL(url2, favicon_base::FAVICON));
 
   // Add two favicons.
-  backend_->SetFavicons(url1, chrome::FAVICON, two_favicon_bitmap_data);
-  EXPECT_EQ(1u, NumIconMappingsForPageURL(url1, chrome::TOUCH_ICON));
-  EXPECT_EQ(2u, NumIconMappingsForPageURL(url1, chrome::FAVICON));
+  backend_->SetFavicons(url1, favicon_base::FAVICON, two_favicon_bitmap_data);
+  EXPECT_EQ(1u, NumIconMappingsForPageURL(url1, favicon_base::TOUCH_ICON));
+  EXPECT_EQ(2u, NumIconMappingsForPageURL(url1, favicon_base::FAVICON));
 }
 
 // Test that there is no churn in icon mappings from calling
@@ -1320,23 +1635,23 @@ TEST_F(HistoryBackendTest, SetFaviconMappingsForPageDuplicates) {
   const GURL url("http://www.google.com/");
   const GURL icon_url("http://www.google.com/icon");
 
-  std::vector<chrome::FaviconBitmapData> favicon_bitmap_data;
-  GenerateFaviconBitmapData(icon_url, GetSizesSmallAndLarge(),
+  std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
+  GenerateFaviconBitmapData(icon_url, GetEdgeSizesSmallAndLarge(),
                             &favicon_bitmap_data);
 
-  backend_->SetFavicons(url, chrome::FAVICON, favicon_bitmap_data);
+  backend_->SetFavicons(url, favicon_base::FAVICON, favicon_bitmap_data);
 
   std::vector<IconMapping> icon_mappings;
   EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(
-      url, chrome::FAVICON, &icon_mappings));
+      url, favicon_base::FAVICON, &icon_mappings));
   EXPECT_EQ(1u, icon_mappings.size());
   IconMappingID mapping_id = icon_mappings[0].mapping_id;
 
-  backend_->SetFavicons(url, chrome::FAVICON, favicon_bitmap_data);
+  backend_->SetFavicons(url, favicon_base::FAVICON, favicon_bitmap_data);
 
   icon_mappings.clear();
   EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(
-      url, chrome::FAVICON, &icon_mappings));
+      url, favicon_base::FAVICON, &icon_mappings));
   EXPECT_EQ(1u, icon_mappings.size());
 
   // The same row in the icon_mapping table should be used for the mapping as
@@ -1351,18 +1666,18 @@ TEST_F(HistoryBackendTest, SetFaviconsDeleteBitmaps) {
   const GURL page_url("http://www.google.com/");
   const GURL icon_url("http://www.google.com/icon");
 
-  std::vector<chrome::FaviconBitmapData> favicon_bitmap_data;
-  GenerateFaviconBitmapData(icon_url, GetSizesSmallAndLarge(),
+  std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
+  GenerateFaviconBitmapData(icon_url, GetEdgeSizesSmallAndLarge(),
                             &favicon_bitmap_data);
-  backend_->SetFavicons(page_url, chrome::FAVICON, favicon_bitmap_data);
+  backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data);
 
   // Test initial state.
   std::vector<IconMapping> icon_mappings;
   EXPECT_TRUE(GetSortedIconMappingsForPageURL(page_url, &icon_mappings));
   EXPECT_EQ(1u, icon_mappings.size());
   EXPECT_EQ(icon_url, icon_mappings[0].icon_url);
-  EXPECT_EQ(chrome::FAVICON, icon_mappings[0].icon_type);
-  chrome::FaviconID favicon_id = icon_mappings[0].icon_id;
+  EXPECT_EQ(favicon_base::FAVICON, icon_mappings[0].icon_type);
+  favicon_base::FaviconID favicon_id = icon_mappings[0].icon_id;
 
   std::vector<FaviconBitmap> favicon_bitmaps;
   EXPECT_TRUE(GetSortedFaviconBitmaps(favicon_id, &favicon_bitmaps));
@@ -1378,8 +1693,9 @@ TEST_F(HistoryBackendTest, SetFaviconsDeleteBitmaps) {
 
   // Call SetFavicons() with bitmap data for only the large bitmap. Check that
   // the small bitmap is in fact deleted.
-  GenerateFaviconBitmapData(icon_url, GetSizesLarge(), &favicon_bitmap_data);
-  backend_->SetFavicons(page_url, chrome::FAVICON, favicon_bitmap_data);
+  GenerateFaviconBitmapData(icon_url, GetEdgeSizesLarge(),
+      &favicon_bitmap_data);
+  backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data);
 
   scoped_refptr<base::RefCountedMemory> bitmap_data_out;
   gfx::Size pixel_size_out;
@@ -1399,7 +1715,7 @@ TEST_F(HistoryBackendTest, SetFaviconsDeleteBitmaps) {
   // Call SetFavicons() with no bitmap data. Check that the bitmaps and icon
   // mappings are deleted.
   favicon_bitmap_data.clear();
-  backend_->SetFavicons(page_url, chrome::FAVICON, favicon_bitmap_data);
+  backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data);
 
   EXPECT_FALSE(backend_->thumbnail_db_->GetFaviconBitmap(large_bitmap_id, NULL,
       NULL, NULL));
@@ -1419,20 +1735,20 @@ TEST_F(HistoryBackendTest, SetFaviconsReplaceBitmapData) {
   std::vector<unsigned char> data_initial;
   data_initial.push_back('a');
 
-  chrome::FaviconBitmapData bitmap_data_element;
+  favicon_base::FaviconRawBitmapData bitmap_data_element;
   bitmap_data_element.bitmap_data =
       base::RefCountedBytes::TakeVector(&data_initial);
   bitmap_data_element.pixel_size = kSmallSize;
   bitmap_data_element.icon_url = icon_url;
-  std::vector<chrome::FaviconBitmapData> favicon_bitmap_data;
+  std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
   favicon_bitmap_data.push_back(bitmap_data_element);
 
   // Add bitmap to the database.
-  backend_->SetFavicons(page_url, chrome::FAVICON, favicon_bitmap_data);
+  backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data);
 
-  chrome::FaviconID original_favicon_id =
+  favicon_base::FaviconID original_favicon_id =
       backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
-          icon_url, chrome::FAVICON, NULL);
+          icon_url, favicon_base::FAVICON, NULL);
   EXPECT_NE(0, original_favicon_id);
   FaviconBitmap original_favicon_bitmap;
   EXPECT_TRUE(
@@ -1445,11 +1761,11 @@ TEST_F(HistoryBackendTest, SetFaviconsReplaceBitmapData) {
   std::vector<unsigned char> updated_data;
   updated_data.push_back('a');
   favicon_bitmap_data[0].bitmap_data = new base::RefCountedBytes(updated_data);
-  backend_->SetFavicons(page_url, chrome::FAVICON, favicon_bitmap_data);
+  backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data);
 
-  chrome::FaviconID updated_favicon_id =
+  favicon_base::FaviconID updated_favicon_id =
       backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
-          icon_url, chrome::FAVICON, NULL);
+          icon_url, favicon_base::FAVICON, NULL);
   EXPECT_NE(0, updated_favicon_id);
   FaviconBitmap updated_favicon_bitmap;
   EXPECT_TRUE(
@@ -1463,11 +1779,10 @@ TEST_F(HistoryBackendTest, SetFaviconsReplaceBitmapData) {
   // Call SetFavicons() with identical data but a different bitmap.
   updated_data[0] = 'b';
   favicon_bitmap_data[0].bitmap_data = new base::RefCountedBytes(updated_data);
-  backend_->SetFavicons(page_url, chrome::FAVICON, favicon_bitmap_data);
+  backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data);
 
-  updated_favicon_id =
-      backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
-          icon_url, chrome::FAVICON, NULL);
+  updated_favicon_id = backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
+      icon_url, favicon_base::FAVICON, NULL);
   EXPECT_NE(0, updated_favicon_id);
   EXPECT_TRUE(
       GetOnlyFaviconBitmap(updated_favicon_id, &updated_favicon_bitmap));
@@ -1492,26 +1807,28 @@ TEST_F(HistoryBackendTest, SetFaviconsSameFaviconURLForTwoPages) {
   GURL page_url1("http://www.google.com");
   GURL page_url2("http://www.google.ca");
 
-  std::vector<chrome::FaviconBitmapData> favicon_bitmap_data;
-  GenerateFaviconBitmapData(icon_url, GetSizesSmallAndLarge(),
+  std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
+  GenerateFaviconBitmapData(icon_url, GetEdgeSizesSmallAndLarge(),
                             &favicon_bitmap_data);
 
-  backend_->SetFavicons(page_url1, chrome::FAVICON, favicon_bitmap_data);
+  backend_->SetFavicons(page_url1, favicon_base::FAVICON, favicon_bitmap_data);
 
   std::vector<GURL> icon_urls;
   icon_urls.push_back(icon_url);
 
-  std::vector<chrome::FaviconBitmapResult> bitmap_results;
-  backend_->UpdateFaviconMappingsAndFetch(
-      page_url2, icon_urls, chrome::FAVICON, kSmallSize.width(),
-      GetScaleFactors1x2x(), &bitmap_results);
+  std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results;
+  backend_->UpdateFaviconMappingsAndFetch(page_url2,
+                                          icon_urls,
+                                          favicon_base::FAVICON,
+                                          GetEdgeSizesSmallAndLarge(),
+                                          &bitmap_results);
 
   // Check that the same FaviconID is mapped to both page URLs.
   std::vector<IconMapping> icon_mappings;
   EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(
       page_url1, &icon_mappings));
   EXPECT_EQ(1u, icon_mappings.size());
-  chrome::FaviconID favicon_id = icon_mappings[0].icon_id;
+  favicon_base::FaviconID favicon_id = icon_mappings[0].icon_id;
   EXPECT_NE(0, favicon_id);
 
   icon_mappings.clear();
@@ -1521,9 +1838,9 @@ TEST_F(HistoryBackendTest, SetFaviconsSameFaviconURLForTwoPages) {
   EXPECT_EQ(favicon_id, icon_mappings[0].icon_id);
 
   // Change the icon URL that |page_url1| is mapped to.
-  GenerateFaviconBitmapData(icon_url_new, GetSizesSmall(),
+  GenerateFaviconBitmapData(icon_url_new, GetEdgeSizesSmall(),
                             &favicon_bitmap_data);
-  backend_->SetFavicons(page_url1, chrome::FAVICON, favicon_bitmap_data);
+  backend_->SetFavicons(page_url1, favicon_base::FAVICON, favicon_bitmap_data);
 
   // |page_url1| should map to a new FaviconID and have valid bitmap data.
   icon_mappings.clear();
@@ -1562,27 +1879,31 @@ TEST_F(HistoryBackendTest, SetFaviconsSameFaviconURLForTwoPages) {
 TEST_F(HistoryBackendTest, UpdateFaviconMappingsAndFetchNoChange) {
   GURL page_url("http://www.google.com");
   GURL icon_url("http://www.google.com/favicon.ico");
-  std::vector<chrome::FaviconBitmapData> favicon_bitmap_data;
-  GenerateFaviconBitmapData(icon_url, GetSizesSmall(), &favicon_bitmap_data);
+  std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
+  GenerateFaviconBitmapData(icon_url, GetEdgeSizesSmall(),
+      &favicon_bitmap_data);
 
-  backend_->SetFavicons(page_url, chrome::FAVICON, favicon_bitmap_data);
+  backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data);
 
-  chrome::FaviconID icon_id =
-    backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
-        icon_url, chrome::FAVICON, NULL);
+  favicon_base::FaviconID icon_id =
+      backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
+          icon_url, favicon_base::FAVICON, NULL);
   EXPECT_NE(0, icon_id);
   EXPECT_EQ(1, num_broadcasted_notifications());
 
   std::vector<GURL> icon_urls;
   icon_urls.push_back(icon_url);
 
-  std::vector<chrome::FaviconBitmapResult> bitmap_results;
-  backend_->UpdateFaviconMappingsAndFetch(
-      page_url, icon_urls, chrome::FAVICON, kSmallSize.width(),
-      GetScaleFactors1x2x(), &bitmap_results);
+  std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results;
+  backend_->UpdateFaviconMappingsAndFetch(page_url,
+                                          icon_urls,
+                                          favicon_base::FAVICON,
+                                          GetEdgeSizesSmallAndLarge(),
+                                          &bitmap_results);
 
-  EXPECT_EQ(icon_id, backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
-      icon_url, chrome::FAVICON, NULL));
+  EXPECT_EQ(icon_id,
+            backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
+                icon_url, favicon_base::FAVICON, NULL));
 
   // No notification should have been broadcast as no icon mapping, favicon,
   // or favicon bitmap was updated, added or removed.
@@ -1601,7 +1922,7 @@ TEST_F(HistoryBackendTest, MergeFaviconPageURLNotInDB) {
       new base::RefCountedBytes(data));
 
   backend_->MergeFavicon(
-      page_url, icon_url, chrome::FAVICON, bitmap_data, kSmallSize);
+      page_url, icon_url, favicon_base::FAVICON, bitmap_data, kSmallSize);
 
   // |page_url| should now be mapped to |icon_url| and the favicon bitmap should
   // not be expired.
@@ -1620,7 +1941,7 @@ TEST_F(HistoryBackendTest, MergeFaviconPageURLNotInDB) {
   data[0] = 'b';
   bitmap_data = new base::RefCountedBytes(data);
   backend_->MergeFavicon(
-      page_url, icon_url, chrome::FAVICON, bitmap_data, kSmallSize);
+      page_url, icon_url, favicon_base::FAVICON, bitmap_data, kSmallSize);
 
   // |page_url| should still have a single favicon bitmap. The bitmap data
   // should be updated.
@@ -1642,11 +1963,11 @@ TEST_F(HistoryBackendTest, MergeFaviconPageURLInDB) {
   GURL icon_url1("http:/www.google.com/favicon.ico");
   GURL icon_url2("http://www.google.com/favicon2.ico");
 
-  std::vector<chrome::FaviconBitmapData> favicon_bitmap_data;
-  GenerateFaviconBitmapData(icon_url1, GetSizesSmall(),
+  std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
+  GenerateFaviconBitmapData(icon_url1, GetEdgeSizesSmall(),
                             &favicon_bitmap_data);
 
-  backend_->SetFavicons(page_url, chrome::FAVICON, favicon_bitmap_data);
+  backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data);
 
   // Test initial state.
   std::vector<IconMapping> icon_mappings;
@@ -1669,7 +1990,7 @@ TEST_F(HistoryBackendTest, MergeFaviconPageURLInDB) {
   scoped_refptr<base::RefCountedBytes> bitmap_data(
       new base::RefCountedBytes(data));
   backend_->MergeFavicon(
-      page_url, icon_url1, chrome::FAVICON, bitmap_data, kSmallSize);
+      page_url, icon_url1, favicon_base::FAVICON, bitmap_data, kSmallSize);
 
   // All the data should stay the same and no notifications should have been
   // sent.
@@ -1690,7 +2011,7 @@ TEST_F(HistoryBackendTest, MergeFaviconPageURLInDB) {
   data[0] = 'b';
   bitmap_data = new base::RefCountedBytes(data);
   backend_->MergeFavicon(
-      page_url, icon_url1, chrome::FAVICON, bitmap_data, kSmallSize);
+      page_url, icon_url1, favicon_base::FAVICON, bitmap_data, kSmallSize);
 
   // The small favicon bitmap at |icon_url1| should be overwritten.
   icon_mappings.clear();
@@ -1709,7 +2030,7 @@ TEST_F(HistoryBackendTest, MergeFaviconPageURLInDB) {
   data[0] = 'c';
   bitmap_data = new base::RefCountedBytes(data);
   backend_->MergeFavicon(
-      page_url, icon_url1, chrome::FAVICON, bitmap_data, kTinySize);
+      page_url, icon_url1, favicon_base::FAVICON, bitmap_data, kTinySize);
 
   // A new favicon bitmap should be created and the preexisting favicon bitmap
   // ('b') should be expired.
@@ -1734,7 +2055,7 @@ TEST_F(HistoryBackendTest, MergeFaviconPageURLInDB) {
   data[0] = 'd';
   bitmap_data = new base::RefCountedBytes(data);
   backend_->MergeFavicon(
-      page_url, icon_url2, chrome::FAVICON, bitmap_data, kSmallSize);
+      page_url, icon_url2, favicon_base::FAVICON, bitmap_data, kSmallSize);
 
   // The existing favicon bitmaps should be copied over to the newly created
   // favicon at |icon_url2|. |page_url| should solely be mapped to |icon_url2|.
@@ -1769,11 +2090,11 @@ TEST_F(HistoryBackendTest, MergeFaviconIconURLMappedToDifferentPageURL) {
   GURL page_url3("http://maps.google.com");
   GURL icon_url("http:/www.google.com/favicon.ico");
 
-  std::vector<chrome::FaviconBitmapData> favicon_bitmap_data;
-  GenerateFaviconBitmapData(icon_url, GetSizesSmall(),
+  std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
+  GenerateFaviconBitmapData(icon_url, GetEdgeSizesSmall(),
                             &favicon_bitmap_data);
 
-  backend_->SetFavicons(page_url1, chrome::FAVICON, favicon_bitmap_data);
+  backend_->SetFavicons(page_url1, favicon_base::FAVICON, favicon_bitmap_data);
 
   // Test initial state.
   std::vector<IconMapping> icon_mappings;
@@ -1795,11 +2116,11 @@ TEST_F(HistoryBackendTest, MergeFaviconIconURLMappedToDifferentPageURL) {
       new base::RefCountedBytes(data));
 
   backend_->MergeFavicon(
-      page_url2, icon_url, chrome::FAVICON, bitmap_data, kSmallSize);
+      page_url2, icon_url, favicon_base::FAVICON, bitmap_data, kSmallSize);
 
-  chrome::FaviconID favicon_id =
-    backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
-        icon_url, chrome::FAVICON, NULL);
+  favicon_base::FaviconID favicon_id =
+      backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
+          icon_url, favicon_base::FAVICON, NULL);
   EXPECT_NE(0, favicon_id);
 
   EXPECT_TRUE(GetOnlyFaviconBitmap(favicon_id, &favicon_bitmap));
@@ -1811,10 +2132,10 @@ TEST_F(HistoryBackendTest, MergeFaviconIconURLMappedToDifferentPageURL) {
   // URL should overwrite the small favicon bitmap at |icon_url|.
   bitmap_data->data()[0] = 'b';
   backend_->MergeFavicon(
-      page_url3, icon_url, chrome::FAVICON, bitmap_data, kSmallSize);
+      page_url3, icon_url, favicon_base::FAVICON, bitmap_data, kSmallSize);
 
   favicon_id = backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
-      icon_url, chrome::FAVICON, NULL);
+      icon_url, favicon_base::FAVICON, NULL);
   EXPECT_NE(0, favicon_id);
 
   EXPECT_TRUE(GetOnlyFaviconBitmap(favicon_id, &favicon_bitmap));
@@ -1863,7 +2184,10 @@ TEST_F(HistoryBackendTest, MergeFaviconMaxFaviconBitmapsPerIconURL) {
     icon_url_string[replace_index] = '0' + i;
     GURL icon_url(icon_url_string);
 
-    backend_->MergeFavicon(page_url, icon_url, chrome::FAVICON, bitmap_data,
+    backend_->MergeFavicon(page_url,
+                           icon_url,
+                           favicon_base::FAVICON,
+                           bitmap_data,
                            gfx::Size(pixel_size, pixel_size));
     ++pixel_size;
   }
@@ -1887,30 +2211,35 @@ TEST_F(HistoryBackendTest, MergeFaviconShowsUpInGetFaviconsForURLResult) {
   GURL icon_url("http://www.google.com/favicon.ico");
   GURL merged_icon_url("http://wwww.google.com/favicon2.ico");
 
-  std::vector<chrome::FaviconBitmapData> favicon_bitmap_data;
-  GenerateFaviconBitmapData(icon_url, GetSizesSmallAndLarge(),
+  std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
+  GenerateFaviconBitmapData(icon_url, GetEdgeSizesSmallAndLarge(),
                             &favicon_bitmap_data);
 
   // Set some preexisting favicons for |page_url|.
-  backend_->SetFavicons(page_url, chrome::FAVICON, favicon_bitmap_data);
+  backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data);
 
   // Merge small favicon.
   std::vector<unsigned char> data;
   data.push_back('c');
   scoped_refptr<base::RefCountedBytes> bitmap_data(
       new base::RefCountedBytes(data));
-  backend_->MergeFavicon(
-      page_url, merged_icon_url, chrome::FAVICON, bitmap_data, kSmallSize);
+  backend_->MergeFavicon(page_url,
+                         merged_icon_url,
+                         favicon_base::FAVICON,
+                         bitmap_data,
+                         kSmallSize);
 
   // Request favicon bitmaps for both 1x and 2x to simulate request done by
   // BookmarkModel::GetFavicon().
-  std::vector<chrome::FaviconBitmapResult> bitmap_results;
-  backend_->GetFaviconsForURL(page_url, chrome::FAVICON, kSmallSize.width(),
-                              GetScaleFactors1x2x(), &bitmap_results);
+  std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results;
+  backend_->GetFaviconsForURL(page_url,
+                              favicon_base::FAVICON,
+                              GetEdgeSizesSmallAndLarge(),
+                              &bitmap_results);
 
   EXPECT_EQ(2u, bitmap_results.size());
-  const chrome::FaviconBitmapResult& first_result = bitmap_results[0];
-  const chrome::FaviconBitmapResult& result =
+  const favicon_base::FaviconRawBitmapResult& first_result = bitmap_results[0];
+  const favicon_base::FaviconRawBitmapResult& result =
       (first_result.pixel_size == kSmallSize) ? first_result
                                               : bitmap_results[1];
   EXPECT_TRUE(BitmapDataEqual('c', result.bitmap_data));
@@ -1922,38 +2251,39 @@ TEST_F(HistoryBackendTest, TestGetFaviconsForURLWithIconTypesPriority) {
   GURL icon_url("http://www.google.com/favicon.ico");
   GURL touch_icon_url("http://wwww.google.com/touch_icon.ico");
 
-  std::vector<chrome::FaviconBitmapData> favicon_bitmap_data;
-  std::vector<gfx::Size> favicon_size;
-  favicon_size.push_back(gfx::Size(16, 16));
-  favicon_size.push_back(gfx::Size(32, 32));
+  std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
+  std::vector<int> favicon_size;
+  favicon_size.push_back(16);
+  favicon_size.push_back(32);
   GenerateFaviconBitmapData(icon_url, favicon_size, &favicon_bitmap_data);
   ASSERT_EQ(2u, favicon_bitmap_data.size());
 
-  std::vector<chrome::FaviconBitmapData> touch_icon_bitmap_data;
-  std::vector<gfx::Size> touch_icon_size;
-  touch_icon_size.push_back(gfx::Size(64, 64));
+  std::vector<favicon_base::FaviconRawBitmapData> touch_icon_bitmap_data;
+  std::vector<int> touch_icon_size;
+  touch_icon_size.push_back(64);
   GenerateFaviconBitmapData(icon_url, touch_icon_size, &touch_icon_bitmap_data);
   ASSERT_EQ(1u, touch_icon_bitmap_data.size());
 
   // Set some preexisting favicons for |page_url|.
-  backend_->SetFavicons(page_url, chrome::FAVICON, favicon_bitmap_data);
-  backend_->SetFavicons(page_url, chrome::TOUCH_ICON, touch_icon_bitmap_data);
+  backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data);
+  backend_->SetFavicons(
+      page_url, favicon_base::TOUCH_ICON, touch_icon_bitmap_data);
 
-  chrome::FaviconBitmapResult result;
+  favicon_base::FaviconRawBitmapResult result;
   std::vector<int> icon_types;
-  icon_types.push_back(chrome::FAVICON);
-  icon_types.push_back(chrome::TOUCH_ICON);
+  icon_types.push_back(favicon_base::FAVICON);
+  icon_types.push_back(favicon_base::TOUCH_ICON);
 
   backend_->GetLargestFaviconForURL(page_url, icon_types, 16, &result);
 
   // Verify the result icon is 32x32 favicon.
   EXPECT_EQ(gfx::Size(32, 32), result.pixel_size);
-  EXPECT_EQ(chrome::FAVICON, result.icon_type);
+  EXPECT_EQ(favicon_base::FAVICON, result.icon_type);
 
   // Change Minimal size to 32x32 and verify the 64x64 touch icon returned.
   backend_->GetLargestFaviconForURL(page_url, icon_types, 32, &result);
   EXPECT_EQ(gfx::Size(64, 64), result.pixel_size);
-  EXPECT_EQ(chrome::TOUCH_ICON, result.icon_type);
+  EXPECT_EQ(favicon_base::TOUCH_ICON, result.icon_type);
 }
 
 // Test the the first types of icon is returned if its size equal to the
@@ -1963,39 +2293,40 @@ TEST_F(HistoryBackendTest, TestGetFaviconsForURLReturnFavicon) {
   GURL icon_url("http://www.google.com/favicon.ico");
   GURL touch_icon_url("http://wwww.google.com/touch_icon.ico");
 
-  std::vector<chrome::FaviconBitmapData> favicon_bitmap_data;
-  std::vector<gfx::Size> favicon_size;
-  favicon_size.push_back(gfx::Size(16, 16));
-  favicon_size.push_back(gfx::Size(32, 32));
+  std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
+  std::vector<int> favicon_size;
+  favicon_size.push_back(16);
+  favicon_size.push_back(32);
   GenerateFaviconBitmapData(icon_url, favicon_size, &favicon_bitmap_data);
   ASSERT_EQ(2u, favicon_bitmap_data.size());
 
-  std::vector<chrome::FaviconBitmapData> touch_icon_bitmap_data;
-  std::vector<gfx::Size> touch_icon_size;
-  touch_icon_size.push_back(gfx::Size(32, 32));
+  std::vector<favicon_base::FaviconRawBitmapData> touch_icon_bitmap_data;
+  std::vector<int> touch_icon_size;
+  touch_icon_size.push_back(32);
   GenerateFaviconBitmapData(icon_url, touch_icon_size, &touch_icon_bitmap_data);
   ASSERT_EQ(1u, touch_icon_bitmap_data.size());
 
   // Set some preexisting favicons for |page_url|.
-  backend_->SetFavicons(page_url, chrome::FAVICON, favicon_bitmap_data);
-  backend_->SetFavicons(page_url, chrome::TOUCH_ICON, touch_icon_bitmap_data);
+  backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data);
+  backend_->SetFavicons(
+      page_url, favicon_base::TOUCH_ICON, touch_icon_bitmap_data);
 
-  chrome::FaviconBitmapResult result;
+  favicon_base::FaviconRawBitmapResult result;
   std::vector<int> icon_types;
-  icon_types.push_back(chrome::FAVICON);
-  icon_types.push_back(chrome::TOUCH_ICON);
+  icon_types.push_back(favicon_base::FAVICON);
+  icon_types.push_back(favicon_base::TOUCH_ICON);
 
   backend_->GetLargestFaviconForURL(page_url, icon_types, 16, &result);
 
   // Verify the result icon is 32x32 favicon.
   EXPECT_EQ(gfx::Size(32, 32), result.pixel_size);
-  EXPECT_EQ(chrome::FAVICON, result.icon_type);
+  EXPECT_EQ(favicon_base::FAVICON, result.icon_type);
 
   // Change minimal size to 32x32 and verify the 32x32 favicon returned.
-  chrome::FaviconBitmapResult result1;
+  favicon_base::FaviconRawBitmapResult result1;
   backend_->GetLargestFaviconForURL(page_url, icon_types, 32, &result1);
   EXPECT_EQ(gfx::Size(32, 32), result1.pixel_size);
-  EXPECT_EQ(chrome::FAVICON, result1.icon_type);
+  EXPECT_EQ(favicon_base::FAVICON, result1.icon_type);
 }
 
 // Test the favicon is returned if its size is smaller than minimal size,
@@ -2004,25 +2335,25 @@ TEST_F(HistoryBackendTest, TestGetFaviconsForURLReturnFaviconEvenItSmaller) {
   GURL page_url("http://www.google.com");
   GURL icon_url("http://www.google.com/favicon.ico");
 
-  std::vector<chrome::FaviconBitmapData> favicon_bitmap_data;
-  std::vector<gfx::Size> favicon_size;
-  favicon_size.push_back(gfx::Size(16, 16));
+  std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
+  std::vector<int> favicon_size;
+  favicon_size.push_back(16);
   GenerateFaviconBitmapData(icon_url, favicon_size, &favicon_bitmap_data);
   ASSERT_EQ(1u, favicon_bitmap_data.size());
 
   // Set preexisting favicons for |page_url|.
-  backend_->SetFavicons(page_url, chrome::FAVICON, favicon_bitmap_data);
+  backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data);
 
-  chrome::FaviconBitmapResult result;
+  favicon_base::FaviconRawBitmapResult result;
   std::vector<int> icon_types;
-  icon_types.push_back(chrome::FAVICON);
-  icon_types.push_back(chrome::TOUCH_ICON);
+  icon_types.push_back(favicon_base::FAVICON);
+  icon_types.push_back(favicon_base::TOUCH_ICON);
 
   backend_->GetLargestFaviconForURL(page_url, icon_types, 32, &result);
 
   // Verify 16x16 icon is returned, even it small than minimal_size.
   EXPECT_EQ(gfx::Size(16, 16), result.pixel_size);
-  EXPECT_EQ(chrome::FAVICON, result.icon_type);
+  EXPECT_EQ(favicon_base::FAVICON, result.icon_type);
 }
 
 // Test UpdateFaviconMapingsAndFetch() when multiple icon types are passed in.
@@ -2035,29 +2366,30 @@ TEST_F(HistoryBackendTest, UpdateFaviconMappingsAndFetchMultipleIconTypes) {
   GURL icon_urlc("http://www.google.com/favicon3.ico");
 
   // |page_url1| is mapped to |icon_urla| which if of type TOUCH_ICON.
-  std::vector<chrome::FaviconBitmapData> favicon_bitmap_data;
-  GenerateFaviconBitmapData(icon_urla, GetSizesSmall(), &favicon_bitmap_data);
-  backend_->SetFavicons(page_url1, chrome::TOUCH_ICON, favicon_bitmap_data);
+  std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
+  GenerateFaviconBitmapData(icon_urla, GetEdgeSizesSmall(),
+      &favicon_bitmap_data);
+  backend_->SetFavicons(
+      page_url1, favicon_base::TOUCH_ICON, favicon_bitmap_data);
 
   // |page_url2| is mapped to |icon_urlb| and |icon_urlc| which are of type
   // TOUCH_PRECOMPOSED_ICON.
-  GenerateFaviconBitmapData(icon_urlb, GetSizesSmall(), icon_urlc,
-                            GetSizesSmall(), &favicon_bitmap_data);
+  GenerateFaviconBitmapData(icon_urlb, GetEdgeSizesSmall(), icon_urlc,
+                            GetEdgeSizesSmall(), &favicon_bitmap_data);
   backend_->SetFavicons(
-      page_url2, chrome::TOUCH_PRECOMPOSED_ICON, favicon_bitmap_data);
+      page_url2, favicon_base::TOUCH_PRECOMPOSED_ICON, favicon_bitmap_data);
 
   std::vector<GURL> icon_urls;
   icon_urls.push_back(icon_urla);
   icon_urls.push_back(icon_urlb);
   icon_urls.push_back(icon_urlc);
 
-  std::vector<chrome::FaviconBitmapResult> bitmap_results;
+  std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results;
   backend_->UpdateFaviconMappingsAndFetch(
       page_url3,
       icon_urls,
-      (chrome::TOUCH_ICON | chrome::TOUCH_PRECOMPOSED_ICON),
-      kSmallSize.width(),
-      GetScaleFactors1x2x(),
+      (favicon_base::TOUCH_ICON | favicon_base::TOUCH_PRECOMPOSED_ICON),
+      GetEdgeSizesSmallAndLarge(),
       &bitmap_results);
 
   // |page_url1| and |page_url2| should still be mapped to the same icon URLs.
@@ -2066,15 +2398,15 @@ TEST_F(HistoryBackendTest, UpdateFaviconMappingsAndFetchMultipleIconTypes) {
       &icon_mappings));
   EXPECT_EQ(1u, icon_mappings.size());
   EXPECT_EQ(icon_urla, icon_mappings[0].icon_url);
-  EXPECT_EQ(chrome::TOUCH_ICON, icon_mappings[0].icon_type);
+  EXPECT_EQ(favicon_base::TOUCH_ICON, icon_mappings[0].icon_type);
 
   icon_mappings.clear();
   EXPECT_TRUE(GetSortedIconMappingsForPageURL(page_url2, &icon_mappings));
   EXPECT_EQ(2u, icon_mappings.size());
   EXPECT_EQ(icon_urlb, icon_mappings[0].icon_url);
-  EXPECT_EQ(chrome::TOUCH_PRECOMPOSED_ICON, icon_mappings[0].icon_type);
+  EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON, icon_mappings[0].icon_type);
   EXPECT_EQ(icon_urlc, icon_mappings[1].icon_url);
-  EXPECT_EQ(chrome::TOUCH_PRECOMPOSED_ICON, icon_mappings[1].icon_type);
+  EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON, icon_mappings[1].icon_type);
 
   // |page_url3| should be mapped only to |icon_urlb| and |icon_urlc| as
   // TOUCH_PRECOMPOSED_ICON is the largest IconType.
@@ -2082,9 +2414,9 @@ TEST_F(HistoryBackendTest, UpdateFaviconMappingsAndFetchMultipleIconTypes) {
   EXPECT_TRUE(GetSortedIconMappingsForPageURL(page_url3, &icon_mappings));
   EXPECT_EQ(2u, icon_mappings.size());
   EXPECT_EQ(icon_urlb, icon_mappings[0].icon_url);
-  EXPECT_EQ(chrome::TOUCH_PRECOMPOSED_ICON, icon_mappings[0].icon_type);
+  EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON, icon_mappings[0].icon_type);
   EXPECT_EQ(icon_urlc, icon_mappings[1].icon_url);
-  EXPECT_EQ(chrome::TOUCH_PRECOMPOSED_ICON, icon_mappings[1].icon_type);
+  EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON, icon_mappings[1].icon_type);
 }
 
 // Test the results of GetFaviconsFromDB() when there are no found
@@ -2092,9 +2424,11 @@ TEST_F(HistoryBackendTest, UpdateFaviconMappingsAndFetchMultipleIconTypes) {
 TEST_F(HistoryBackendTest, GetFaviconsFromDBEmpty) {
   const GURL page_url("http://www.google.com/");
 
-  std::vector<chrome::FaviconBitmapResult> bitmap_results;
-  EXPECT_FALSE(backend_->GetFaviconsFromDB(page_url, chrome::FAVICON,
-      kSmallSize.width(), GetScaleFactors1x2x(), &bitmap_results));
+  std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results;
+  EXPECT_FALSE(backend_->GetFaviconsFromDB(page_url,
+                                           favicon_base::FAVICON,
+                                           GetEdgeSizesSmallAndLarge(),
+                                           &bitmap_results));
   EXPECT_TRUE(bitmap_results.empty());
 }
 
@@ -2104,34 +2438,35 @@ TEST_F(HistoryBackendTest, GetFaviconsFromDBNoFaviconBitmaps) {
   const GURL page_url("http://www.google.com/");
   const GURL icon_url("http://www.google.com/icon1");
 
-  chrome::FaviconID icon_id = backend_->thumbnail_db_->AddFavicon(
-      icon_url, chrome::FAVICON);
+  favicon_base::FaviconID icon_id =
+      backend_->thumbnail_db_->AddFavicon(icon_url, favicon_base::FAVICON);
   EXPECT_NE(0, icon_id);
   EXPECT_NE(0, backend_->thumbnail_db_->AddIconMapping(page_url, icon_id));
 
-  std::vector<chrome::FaviconBitmapResult> bitmap_results_out;
-  EXPECT_FALSE(backend_->GetFaviconsFromDB(page_url, chrome::FAVICON,
-      kSmallSize.width(), GetScaleFactors1x2x(), &bitmap_results_out));
+  std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results_out;
+  EXPECT_FALSE(backend_->GetFaviconsFromDB(page_url,
+                                           favicon_base::FAVICON,
+                                           GetEdgeSizesSmallAndLarge(),
+                                           &bitmap_results_out));
   EXPECT_TRUE(bitmap_results_out.empty());
 }
 
 // Test that GetFaviconsFromDB() returns results for the bitmaps which most
-// closely match the passed in desired size and scale factors.
+// closely match the passed in the desired pixel sizes.
 TEST_F(HistoryBackendTest, GetFaviconsFromDBSelectClosestMatch) {
   const GURL page_url("http://www.google.com/");
   const GURL icon_url("http://www.google.com/icon1");
 
-  std::vector<chrome::FaviconBitmapData> favicon_bitmap_data;
-  GenerateFaviconBitmapData(icon_url, GetSizesTinySmallAndLarge(),
+  std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
+  GenerateFaviconBitmapData(icon_url, GetEdgeSizesTinySmallAndLarge(),
                             &favicon_bitmap_data);
 
-  backend_->SetFavicons(page_url, chrome::FAVICON, favicon_bitmap_data);
+  backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data);
 
-  std::vector<chrome::FaviconBitmapResult> bitmap_results_out;
+  std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results_out;
   EXPECT_TRUE(backend_->GetFaviconsFromDB(page_url,
-                                          chrome::FAVICON,
-                                          kSmallSize.width(),
-                                          GetScaleFactors1x2x(),
+                                          favicon_base::FAVICON,
+                                          GetEdgeSizesSmallAndLarge(),
                                           &bitmap_results_out));
 
   // The bitmap data for the small and large bitmaps should be returned as their
@@ -2139,7 +2474,7 @@ TEST_F(HistoryBackendTest, GetFaviconsFromDBSelectClosestMatch) {
   EXPECT_EQ(2u, bitmap_results_out.size());
   // No required order for results.
   if (bitmap_results_out[0].pixel_size == kLargeSize) {
-    chrome::FaviconBitmapResult tmp_result = bitmap_results_out[0];
+    favicon_base::FaviconRawBitmapResult tmp_result = bitmap_results_out[0];
     bitmap_results_out[0] = bitmap_results_out[1];
     bitmap_results_out[1] = tmp_result;
   }
@@ -2148,34 +2483,33 @@ TEST_F(HistoryBackendTest, GetFaviconsFromDBSelectClosestMatch) {
   EXPECT_TRUE(BitmapDataEqual('b', bitmap_results_out[0].bitmap_data));
   EXPECT_EQ(kSmallSize, bitmap_results_out[0].pixel_size);
   EXPECT_EQ(icon_url, bitmap_results_out[0].icon_url);
-  EXPECT_EQ(chrome::FAVICON, bitmap_results_out[0].icon_type);
+  EXPECT_EQ(favicon_base::FAVICON, bitmap_results_out[0].icon_type);
 
   EXPECT_FALSE(bitmap_results_out[1].expired);
   EXPECT_TRUE(BitmapDataEqual('c', bitmap_results_out[1].bitmap_data));
   EXPECT_EQ(kLargeSize, bitmap_results_out[1].pixel_size);
   EXPECT_EQ(icon_url, bitmap_results_out[1].icon_url);
-  EXPECT_EQ(chrome::FAVICON, bitmap_results_out[1].icon_type);
+  EXPECT_EQ(favicon_base::FAVICON, bitmap_results_out[1].icon_type);
 }
 
 // Test that GetFaviconsFromDB() returns results from the icon URL whose
-// bitmaps most closely match the passed in desired size and scale factors.
+// bitmaps most closely match the passed in desired sizes.
 TEST_F(HistoryBackendTest, GetFaviconsFromDBSingleIconURL) {
   const GURL page_url("http://www.google.com/");
 
   const GURL icon_url1("http://www.google.com/icon1");
   const GURL icon_url2("http://www.google.com/icon2");
 
-  std::vector<chrome::FaviconBitmapData> favicon_bitmap_data;
-  GenerateFaviconBitmapData(icon_url1, GetSizesSmall(), icon_url2,
-                            GetSizesLarge(), &favicon_bitmap_data);
+  std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
+  GenerateFaviconBitmapData(icon_url1, GetEdgeSizesSmall(), icon_url2,
+                            GetEdgeSizesLarge(), &favicon_bitmap_data);
 
-  backend_->SetFavicons(page_url, chrome::FAVICON, favicon_bitmap_data);
+  backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data);
 
-  std::vector<chrome::FaviconBitmapResult> bitmap_results_out;
+  std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results_out;
   EXPECT_TRUE(backend_->GetFaviconsFromDB(page_url,
-                                          chrome::FAVICON,
-                                          kSmallSize.width(),
-                                          GetScaleFactors1x2x(),
+                                          favicon_base::FAVICON,
+                                          GetEdgeSizesSmallAndLarge(),
                                           &bitmap_results_out));
 
   // The results should have results for the icon URL with the large bitmap as
@@ -2192,27 +2526,34 @@ TEST_F(HistoryBackendTest, GetFaviconsFromDBIconType) {
   const GURL icon_url1("http://www.google.com/icon1.png");
   const GURL icon_url2("http://www.google.com/icon2.png");
 
-  std::vector<chrome::FaviconBitmapData> favicon_bitmap_data;
-  GenerateFaviconBitmapData(icon_url1, GetSizesSmall(),  &favicon_bitmap_data);
-  backend_->SetFavicons(page_url, chrome::FAVICON, favicon_bitmap_data);
+  std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
+  GenerateFaviconBitmapData(icon_url1, GetEdgeSizesSmall(),
+      &favicon_bitmap_data);
+  backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data);
 
-  GenerateFaviconBitmapData(icon_url2, GetSizesSmall(), &favicon_bitmap_data);
-  backend_->SetFavicons(page_url, chrome::TOUCH_ICON, favicon_bitmap_data);
+  GenerateFaviconBitmapData(
+      icon_url2, GetEdgeSizesSmall(), &favicon_bitmap_data);
+  backend_->SetFavicons(
+      page_url, favicon_base::TOUCH_ICON, favicon_bitmap_data);
 
-  std::vector<chrome::FaviconBitmapResult> bitmap_results_out;
-  EXPECT_TRUE(backend_->GetFaviconsFromDB(page_url, chrome::FAVICON,
-      kSmallSize.width(), GetScaleFactors1x2x(), &bitmap_results_out));
+  std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results_out;
+  EXPECT_TRUE(backend_->GetFaviconsFromDB(page_url,
+                                          favicon_base::FAVICON,
+                                          GetEdgeSizesSmallAndLarge(),
+                                          &bitmap_results_out));
 
   EXPECT_EQ(1u, bitmap_results_out.size());
-  EXPECT_EQ(chrome::FAVICON, bitmap_results_out[0].icon_type);
+  EXPECT_EQ(favicon_base::FAVICON, bitmap_results_out[0].icon_type);
   EXPECT_EQ(icon_url1, bitmap_results_out[0].icon_url);
 
   bitmap_results_out.clear();
-  EXPECT_TRUE(backend_->GetFaviconsFromDB(page_url, chrome::TOUCH_ICON,
-      kSmallSize.width(), GetScaleFactors1x2x(), &bitmap_results_out));
+  EXPECT_TRUE(backend_->GetFaviconsFromDB(page_url,
+                                          favicon_base::TOUCH_ICON,
+                                          GetEdgeSizesSmallAndLarge(),
+                                          &bitmap_results_out));
 
   EXPECT_EQ(1u, bitmap_results_out.size());
-  EXPECT_EQ(chrome::TOUCH_ICON, bitmap_results_out[0].icon_type);
+  EXPECT_EQ(favicon_base::TOUCH_ICON, bitmap_results_out[0].icon_type);
   EXPECT_EQ(icon_url2, bitmap_results_out[0].icon_url);
 }
 
@@ -2227,18 +2568,16 @@ TEST_F(HistoryBackendTest, GetFaviconsFromDBExpired) {
   scoped_refptr<base::RefCountedBytes> bitmap_data(
       base::RefCountedBytes::TakeVector(&data));
   base::Time last_updated = base::Time::FromTimeT(0);
-  chrome::FaviconID icon_id =
-      backend_->thumbnail_db_->AddFavicon(icon_url,
-                                          chrome::FAVICON,
-                                          bitmap_data,
-                                          last_updated,
-                                          kSmallSize);
+  favicon_base::FaviconID icon_id = backend_->thumbnail_db_->AddFavicon(
+      icon_url, favicon_base::FAVICON, bitmap_data, last_updated, kSmallSize);
   EXPECT_NE(0, icon_id);
   EXPECT_NE(0, backend_->thumbnail_db_->AddIconMapping(page_url, icon_id));
 
-  std::vector<chrome::FaviconBitmapResult> bitmap_results_out;
-  EXPECT_TRUE(backend_->GetFaviconsFromDB(page_url, chrome::FAVICON,
-      kSmallSize.width(), GetScaleFactors1x2x(), &bitmap_results_out));
+  std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results_out;
+  EXPECT_TRUE(backend_->GetFaviconsFromDB(page_url,
+                                          favicon_base::FAVICON,
+                                          GetEdgeSizesSmallAndLarge(),
+                                          &bitmap_results_out));
 
   EXPECT_EQ(1u, bitmap_results_out.size());
   EXPECT_TRUE(bitmap_results_out[0].expired);
@@ -2250,11 +2589,13 @@ TEST_F(HistoryBackendTest, UpdateFaviconMappingsAndFetchNoDB) {
   // Make the thumbnail database invalid.
   backend_->thumbnail_db_.reset();
 
-  std::vector<chrome::FaviconBitmapResult> bitmap_results;
+  std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results;
 
-  backend_->UpdateFaviconMappingsAndFetch(
-      GURL(), std::vector<GURL>(), chrome::FAVICON, kSmallSize.width(),
-      GetScaleFactors1x2x(), &bitmap_results);
+  backend_->UpdateFaviconMappingsAndFetch(GURL(),
+                                          std::vector<GURL>(),
+                                          favicon_base::FAVICON,
+                                          GetEdgeSizesSmallAndLarge(),
+                                          &bitmap_results);
 
   EXPECT_TRUE(bitmap_results.empty());
 }
@@ -2266,30 +2607,41 @@ TEST_F(HistoryBackendTest, CloneFaviconIsRestrictedToSameDomain) {
   const GURL icon_url("http://www.google.com/icon.png");
 
   // Add a favicon
-  std::vector<chrome::FaviconBitmapData> favicon_bitmap_data;
-  GenerateFaviconBitmapData(icon_url, GetSizesSmall(),  &favicon_bitmap_data);
-  backend_->SetFavicons(url, chrome::FAVICON, favicon_bitmap_data);
+  std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
+  GenerateFaviconBitmapData(icon_url, GetEdgeSizesSmall(),
+      &favicon_bitmap_data);
+  backend_->SetFavicons(url, favicon_base::FAVICON, favicon_bitmap_data);
   EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(
-      url, chrome::FAVICON, NULL));
+      url, favicon_base::FAVICON, NULL));
 
   // Validate starting state.
-  std::vector<chrome::FaviconBitmapResult> bitmap_results_out;
-  EXPECT_TRUE(backend_->GetFaviconsFromDB(url, chrome::FAVICON,
-      kSmallSize.width(), GetScaleFactors1x2x(), &bitmap_results_out));
-  EXPECT_FALSE(backend_->GetFaviconsFromDB(same_domain_url, chrome::FAVICON,
-      kSmallSize.width(), GetScaleFactors1x2x(), &bitmap_results_out));
-  EXPECT_FALSE(backend_->GetFaviconsFromDB(foreign_domain_url, chrome::FAVICON,
-      kSmallSize.width(), GetScaleFactors1x2x(), &bitmap_results_out));
+  std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results_out;
+  EXPECT_TRUE(backend_->GetFaviconsFromDB(url,
+                                          favicon_base::FAVICON,
+                                          GetEdgeSizesSmallAndLarge(),
+                                          &bitmap_results_out));
+  EXPECT_FALSE(backend_->GetFaviconsFromDB(same_domain_url,
+                                           favicon_base::FAVICON,
+                                           GetEdgeSizesSmallAndLarge(),
+                                           &bitmap_results_out));
+  EXPECT_FALSE(backend_->GetFaviconsFromDB(foreign_domain_url,
+                                           favicon_base::FAVICON,
+                                           GetEdgeSizesSmallAndLarge(),
+                                           &bitmap_results_out));
 
   // Same-domain cloning should work.
   backend_->CloneFavicons(url, same_domain_url);
-  EXPECT_TRUE(backend_->GetFaviconsFromDB(same_domain_url, chrome::FAVICON,
-      kSmallSize.width(), GetScaleFactors1x2x(), &bitmap_results_out));
+  EXPECT_TRUE(backend_->GetFaviconsFromDB(same_domain_url,
+                                          favicon_base::FAVICON,
+                                          GetEdgeSizesSmallAndLarge(),
+                                          &bitmap_results_out));
 
   // Foreign-domain cloning is forbidden.
   backend_->CloneFavicons(url, foreign_domain_url);
-  EXPECT_FALSE(backend_->GetFaviconsFromDB(foreign_domain_url, chrome::FAVICON,
-      kSmallSize.width(), GetScaleFactors1x2x(), &bitmap_results_out));
+  EXPECT_FALSE(backend_->GetFaviconsFromDB(foreign_domain_url,
+                                           favicon_base::FAVICON,
+                                           GetEdgeSizesSmallAndLarge(),
+                                           &bitmap_results_out));
 }
 
 TEST_F(HistoryBackendTest, QueryFilteredURLs) {
@@ -2373,117 +2725,74 @@ TEST_F(HistoryBackendTest, QueryFilteredURLs) {
                                         tested_time - half_an_hour);
   backend_->Commit();
 
-  scoped_refptr<QueryFilteredURLsRequest> request1 =
-      new history::QueryFilteredURLsRequest(
-          base::Bind(&HistoryBackendTest::OnQueryFiltered,
-                     base::Unretained(static_cast<HistoryBackendTest*>(this))));
-  HistoryBackendCancelableRequest cancellable_request;
-  cancellable_request.MockScheduleOfRequest<QueryFilteredURLsRequest>(
-      request1.get());
-
   VisitFilter filter;
+  FilteredURLList filtered_list;
   // Time limit is |tested_time| +/- 45 min.
   base::TimeDelta three_quarters_of_an_hour = base::TimeDelta::FromMinutes(45);
   filter.SetFilterTime(tested_time);
   filter.SetFilterWidth(three_quarters_of_an_hour);
-  backend_->QueryFilteredURLs(request1, 100, filter, false);
+  backend_->QueryFilteredURLs(100, filter, false, &filtered_list);
 
-  ASSERT_EQ(4U, get_filtered_list().size());
-  EXPECT_EQ(std::string(google), get_filtered_list()[0].url.spec());
-  EXPECT_EQ(std::string(yahoo_sports_soccer),
-            get_filtered_list()[1].url.spec());
-  EXPECT_EQ(std::string(yahoo), get_filtered_list()[2].url.spec());
-  EXPECT_EQ(std::string(yahoo_sports),
-            get_filtered_list()[3].url.spec());
+  ASSERT_EQ(4U, filtered_list.size());
+  EXPECT_EQ(std::string(google), filtered_list[0].url.spec());
+  EXPECT_EQ(std::string(yahoo_sports_soccer), filtered_list[1].url.spec());
+  EXPECT_EQ(std::string(yahoo), filtered_list[2].url.spec());
+  EXPECT_EQ(std::string(yahoo_sports), filtered_list[3].url.spec());
 
   // Time limit is between |tested_time| and |tested_time| + 2 hours.
-  scoped_refptr<QueryFilteredURLsRequest> request2 =
-      new history::QueryFilteredURLsRequest(
-          base::Bind(&HistoryBackendTest::OnQueryFiltered,
-                     base::Unretained(static_cast<HistoryBackendTest*>(this))));
-  cancellable_request.MockScheduleOfRequest<QueryFilteredURLsRequest>(
-      request2.get());
   filter.SetFilterTime(tested_time + one_hour);
   filter.SetFilterWidth(one_hour);
-  backend_->QueryFilteredURLs(request2, 100, filter, false);
+  backend_->QueryFilteredURLs(100, filter, false, &filtered_list);
 
-  ASSERT_EQ(3U, get_filtered_list().size());
-  EXPECT_EQ(std::string(google), get_filtered_list()[0].url.spec());
-  EXPECT_EQ(std::string(yahoo), get_filtered_list()[1].url.spec());
-  EXPECT_EQ(std::string(yahoo_sports), get_filtered_list()[2].url.spec());
+  ASSERT_EQ(3U, filtered_list.size());
+  EXPECT_EQ(std::string(google), filtered_list[0].url.spec());
+  EXPECT_EQ(std::string(yahoo), filtered_list[1].url.spec());
+  EXPECT_EQ(std::string(yahoo_sports), filtered_list[2].url.spec());
 
   // Time limit is between |tested_time| - 2 hours and |tested_time|.
-  scoped_refptr<QueryFilteredURLsRequest> request3 =
-      new history::QueryFilteredURLsRequest(
-          base::Bind(&HistoryBackendTest::OnQueryFiltered,
-                     base::Unretained(static_cast<HistoryBackendTest*>(this))));
-  cancellable_request.MockScheduleOfRequest<QueryFilteredURLsRequest>(
-      request3.get());
   filter.SetFilterTime(tested_time - one_hour);
   filter.SetFilterWidth(one_hour);
-  backend_->QueryFilteredURLs(request3, 100, filter, false);
+  backend_->QueryFilteredURLs(100, filter, false, &filtered_list);
 
-  ASSERT_EQ(3U, get_filtered_list().size());
-  EXPECT_EQ(std::string(google), get_filtered_list()[0].url.spec());
-  EXPECT_EQ(std::string(yahoo_sports_soccer),
-            get_filtered_list()[1].url.spec());
-  EXPECT_EQ(std::string(yahoo_sports), get_filtered_list()[2].url.spec());
+  ASSERT_EQ(3U, filtered_list.size());
+  EXPECT_EQ(std::string(google), filtered_list[0].url.spec());
+  EXPECT_EQ(std::string(yahoo_sports_soccer), filtered_list[1].url.spec());
+  EXPECT_EQ(std::string(yahoo_sports), filtered_list[2].url.spec());
 
   filter.ClearFilters();
   base::Time::Exploded exploded_time;
   tested_time.LocalExplode(&exploded_time);
 
   // Today.
-  scoped_refptr<QueryFilteredURLsRequest> request4 =
-      new history::QueryFilteredURLsRequest(
-          base::Bind(&HistoryBackendTest::OnQueryFiltered,
-                     base::Unretained(static_cast<HistoryBackendTest*>(this))));
-  cancellable_request.MockScheduleOfRequest<QueryFilteredURLsRequest>(
-      request4.get());
   filter.SetFilterTime(tested_time);
   filter.SetDayOfTheWeekFilter(static_cast<int>(exploded_time.day_of_week));
-  backend_->QueryFilteredURLs(request4, 100, filter, false);
+  backend_->QueryFilteredURLs(100, filter, false, &filtered_list);
 
-  ASSERT_EQ(2U, get_filtered_list().size());
-  EXPECT_EQ(std::string(google), get_filtered_list()[0].url.spec());
-  EXPECT_EQ(std::string(yahoo_sports_soccer),
-            get_filtered_list()[1].url.spec());
+  ASSERT_EQ(2U, filtered_list.size());
+  EXPECT_EQ(std::string(google), filtered_list[0].url.spec());
+  EXPECT_EQ(std::string(yahoo_sports_soccer), filtered_list[1].url.spec());
 
   // Today + time limit - only yahoo_sports_soccer should fit.
-  scoped_refptr<QueryFilteredURLsRequest> request5 =
-      new history::QueryFilteredURLsRequest(
-          base::Bind(&HistoryBackendTest::OnQueryFiltered,
-                     base::Unretained(static_cast<HistoryBackendTest*>(this))));
-  cancellable_request.MockScheduleOfRequest<QueryFilteredURLsRequest>(
-      request5.get());
   filter.SetFilterTime(tested_time - base::TimeDelta::FromMinutes(40));
   filter.SetFilterWidth(base::TimeDelta::FromMinutes(20));
-  backend_->QueryFilteredURLs(request5, 100, filter, false);
+  backend_->QueryFilteredURLs(100, filter, false, &filtered_list);
 
-  ASSERT_EQ(1U, get_filtered_list().size());
-  EXPECT_EQ(std::string(yahoo_sports_soccer),
-            get_filtered_list()[0].url.spec());
+  ASSERT_EQ(1U, filtered_list.size());
+  EXPECT_EQ(std::string(yahoo_sports_soccer), filtered_list[0].url.spec());
 
   // Make sure we get debug data if we request it.
-  scoped_refptr<QueryFilteredURLsRequest> request6 =
-      new history::QueryFilteredURLsRequest(
-          base::Bind(&HistoryBackendTest::OnQueryFiltered,
-                     base::Unretained(static_cast<HistoryBackendTest*>(this))));
-  cancellable_request.MockScheduleOfRequest<QueryFilteredURLsRequest>(
-      request6.get());
   filter.SetFilterTime(tested_time);
   filter.SetFilterWidth(one_hour * 2);
-  backend_->QueryFilteredURLs(request6, 100, filter, true);
+  backend_->QueryFilteredURLs(100, filter, true, &filtered_list);
 
   // If the SegmentID is used by QueryFilteredURLs when generating the debug
   // data instead of the URLID, the |total_visits| for the |yahoo_sports_soccer|
   // entry will be zero instead of 1.
-  ASSERT_GE(get_filtered_list().size(), 2U);
-  EXPECT_EQ(std::string(google), get_filtered_list()[0].url.spec());
-  EXPECT_EQ(std::string(yahoo_sports_soccer),
-      get_filtered_list()[1].url.spec());
-  EXPECT_EQ(4U, get_filtered_list()[0].extended_info.total_visits);
-  EXPECT_EQ(1U, get_filtered_list()[1].extended_info.total_visits);
+  ASSERT_GE(filtered_list.size(), 2U);
+  EXPECT_EQ(std::string(google), filtered_list[0].url.spec());
+  EXPECT_EQ(std::string(yahoo_sports_soccer), filtered_list[1].url.spec());
+  EXPECT_EQ(4U, filtered_list[0].extended_info.total_visits);
+  EXPECT_EQ(1U, filtered_list[1].extended_info.total_visits);
 }
 
 TEST_F(HistoryBackendTest, UpdateVisitDuration) {
@@ -2540,32 +2849,27 @@ TEST_F(HistoryBackendTest, MigrationVisitDuration) {
   backend_->Closing();
   backend_ = NULL;
 
-  base::FilePath old_history_path, old_history, old_archived;
+  base::FilePath old_history_path, old_history;
   ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &old_history_path));
   old_history_path = old_history_path.AppendASCII("History");
   old_history = old_history_path.AppendASCII("HistoryNoDuration");
-  old_archived = old_history_path.AppendASCII("ArchivedNoDuration");
 
   // Copy history database file to current directory so that it will be deleted
   // in Teardown.
-  base::FilePath new_history_path(getTestDir());
+  base::FilePath new_history_path(test_dir());
   base::DeleteFile(new_history_path, true);
   base::CreateDirectory(new_history_path);
   base::FilePath new_history_file =
       new_history_path.Append(chrome::kHistoryFilename);
-  base::FilePath new_archived_file =
-      new_history_path.Append(chrome::kArchivedHistoryFilename);
   ASSERT_TRUE(base::CopyFile(old_history, new_history_file));
-  ASSERT_TRUE(base::CopyFile(old_archived, new_archived_file));
 
-  backend_ = new HistoryBackend(new_history_path,
-                                new HistoryBackendTestDelegate(this),
-                                &bookmark_model_);
+  backend_ = new HistoryBackend(
+      new_history_path, new HistoryBackendTestDelegate(this), &history_client_);
   backend_->Init(std::string(), false);
   backend_->Closing();
   backend_ = NULL;
 
-  // Now both history and archived_history databases should already be migrated.
+  // Now the history database should already be migrated.
 
   // Check version in history database first.
   int cur_version = HistoryDatabase::GetCurrentVersion();
@@ -2582,23 +2886,6 @@ TEST_F(HistoryBackendTest, MigrationVisitDuration) {
       "SELECT visit_duration FROM visits LIMIT 1"));
   ASSERT_TRUE(s.Step());
   EXPECT_EQ(0, s.ColumnInt(0));
-
-  // Repeat version and visit_duration checks in archived history database
-  // also.
-  cur_version = ArchivedDatabase::GetCurrentVersion();
-  sql::Connection archived_db;
-  ASSERT_TRUE(archived_db.Open(new_archived_file));
-  sql::Statement s1(archived_db.GetUniqueStatement(
-      "SELECT value FROM meta WHERE key = 'version'"));
-  ASSERT_TRUE(s1.Step());
-  file_version = s1.ColumnInt(0);
-  EXPECT_EQ(cur_version, file_version);
-
-  // Check visit_duration column in visits table is created and set to 0.
-  s1.Assign(archived_db.GetUniqueStatement(
-      "SELECT visit_duration FROM visits LIMIT 1"));
-  ASSERT_TRUE(s1.Step());
-  EXPECT_EQ(0, s1.ColumnInt(0));
 }
 
 TEST_F(HistoryBackendTest, AddPageNoVisitForBookmark) {
@@ -2745,7 +3032,7 @@ TEST_F(HistoryBackendTest, DeleteMatchingUrlsForKeyword) {
   const URLID url1_id = backend_->db()->AddURL(url_info1);
   EXPECT_NE(0, url1_id);
 
-  TemplateURLID keyword_id = 1;
+  KeywordID keyword_id = 1;
   base::string16 keyword = base::UTF8ToUTF16("bar");
   ASSERT_TRUE(backend_->db()->SetKeywordSearchTermsForURL(
       url1_id, keyword_id, keyword));
@@ -2759,7 +3046,7 @@ TEST_F(HistoryBackendTest, DeleteMatchingUrlsForKeyword) {
   const URLID url2_id = backend_->db()->AddURL(url_info2);
   EXPECT_NE(0, url2_id);
 
-  TemplateURLID keyword_id2 = 2;
+  KeywordID keyword_id2 = 2;
   ASSERT_TRUE(backend_->db()->SetKeywordSearchTermsForURL(
       url2_id, keyword_id2, keyword));
 
@@ -2796,17 +3083,13 @@ TEST_F(HistoryBackendTest, DeleteMatchingUrlsForKeyword) {
 TEST_F(HistoryBackendTest, RemoveNotification) {
   scoped_ptr<TestingProfile> profile(new TestingProfile());
 
-  ASSERT_TRUE(profile->CreateHistoryService(false, false));
-  profile->CreateBookmarkModel(true);
-  BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile.get());
-  test::WaitForBookmarkModelToLoad(model);
-
   // Add a URL.
   GURL url("http://www.google.com");
-  bookmark_utils::AddIfNotBookmarked(model, url, base::string16());
-
-  HistoryService* service = HistoryServiceFactory::GetForProfile(
-      profile.get(), Profile::EXPLICIT_ACCESS);
+  HistoryClientMock history_client;
+  history_client.AddBookmark(url);
+  scoped_ptr<HistoryService> service(
+      new HistoryService(&history_client, profile.get()));
+  EXPECT_TRUE(service->Init(profile->GetPath()));
 
   service->AddPage(
       url, base::Time::Now(), NULL, 1, GURL(), RedirectList(),
@@ -2814,6 +3097,7 @@ TEST_F(HistoryBackendTest, RemoveNotification) {
 
   // This won't actually delete the URL, rather it'll empty out the visits.
   // This triggers blocking on the BookmarkModel.
+  EXPECT_CALL(history_client, BlockUntilBookmarksLoaded());
   service->DeleteURL(url);
 }
 
@@ -2821,7 +3105,7 @@ TEST_F(HistoryBackendTest, RemoveNotification) {
 TEST_F(HistoryBackendTest, DeleteFTSIndexDatabases) {
   ASSERT_TRUE(backend_.get());
 
-  base::FilePath history_path(getTestDir());
+  base::FilePath history_path(test_dir());
   base::FilePath db1(history_path.AppendASCII("History Index 2013-05"));
   base::FilePath db1_journal(db1.InsertBeforeExtensionASCII("-journal"));
   base::FilePath db1_wal(db1.InsertBeforeExtensionASCII("-wal"));
@@ -2848,4 +3132,214 @@ TEST_F(HistoryBackendTest, DeleteFTSIndexDatabases) {
   EXPECT_TRUE(base::PathExists(db2_actual));  // Symlinks shouldn't be followed.
 }
 
+// Common implementation for the two tests below, given that the only difference
+// between them is the type of the notification sent out.
+void InMemoryHistoryBackendTest::TestAddingAndChangingURLRows(
+    int notification_type) {
+  const char kTestTypedURLAlternativeTitle[] = "Google Search Again";
+  const char kTestNonTypedURLAlternativeTitle[] = "Google News Again";
+
+  // Notify the in-memory database that a typed and non-typed URLRow (which were
+  // never before seen by the cache) have been modified.
+  URLRow row1(CreateTestTypedURL());
+  URLRow row2(CreateTestNonTypedURL());
+  SimulateNotification(notification_type, &row1, &row2);
+
+  // The in-memory database should only pick up the typed URL, and should ignore
+  // the non-typed one. The typed URL should retain the ID that was present in
+  // the notification.
+  URLRow cached_row1, cached_row2;
+  EXPECT_NE(0, mem_backend_->db()->GetRowForURL(row1.url(), &cached_row1));
+  EXPECT_EQ(0, mem_backend_->db()->GetRowForURL(row2.url(), &cached_row2));
+  EXPECT_EQ(row1.id(), cached_row1.id());
+
+  // Try changing attributes (other than typed_count) for existing URLRows.
+  row1.set_title(base::UTF8ToUTF16(kTestTypedURLAlternativeTitle));
+  row2.set_title(base::UTF8ToUTF16(kTestNonTypedURLAlternativeTitle));
+  SimulateNotification(notification_type, &row1, &row2);
+
+  // URLRows that are cached by the in-memory database should be updated.
+  EXPECT_NE(0, mem_backend_->db()->GetRowForURL(row1.url(), &cached_row1));
+  EXPECT_EQ(0, mem_backend_->db()->GetRowForURL(row2.url(), &cached_row2));
+  EXPECT_EQ(base::UTF8ToUTF16(kTestTypedURLAlternativeTitle),
+            cached_row1.title());
+
+  // Now decrease the typed count for the typed URLRow, and increase it for the
+  // previously non-typed URLRow.
+  row1.set_typed_count(0);
+  row2.set_typed_count(2);
+  SimulateNotification(notification_type, &row1, &row2);
+
+  // The in-memory database should stop caching the first URLRow, and start
+  // caching the second URLRow.
+  EXPECT_EQ(0, mem_backend_->db()->GetRowForURL(row1.url(), &cached_row1));
+  EXPECT_NE(0, mem_backend_->db()->GetRowForURL(row2.url(), &cached_row2));
+  EXPECT_EQ(row2.id(), cached_row2.id());
+  EXPECT_EQ(base::UTF8ToUTF16(kTestNonTypedURLAlternativeTitle),
+            cached_row2.title());
+}
+
+TEST_F(InMemoryHistoryBackendTest, OnURLsModified) {
+  TestAddingAndChangingURLRows(chrome::NOTIFICATION_HISTORY_URLS_MODIFIED);
+}
+
+TEST_F(InMemoryHistoryBackendTest, OnURLsVisisted) {
+  TestAddingAndChangingURLRows(chrome::NOTIFICATION_HISTORY_URL_VISITED);
+}
+
+TEST_F(InMemoryHistoryBackendTest, OnURLsDeletedPiecewise) {
+  // Add two typed and one non-typed URLRow to the in-memory database.
+  URLRow row1(CreateTestTypedURL());
+  URLRow row2(CreateAnotherTestTypedURL());
+  URLRow row3(CreateTestNonTypedURL());
+  SimulateNotification(chrome::NOTIFICATION_HISTORY_URLS_MODIFIED,
+                       &row1, &row2, &row3);
+
+  // Notify the in-memory database that the second typed URL and the non-typed
+  // URL has been deleted.
+  SimulateNotification(chrome::NOTIFICATION_HISTORY_URLS_DELETED,
+                       &row2, &row3);
+
+  // Expect that the first typed URL remains intact, the second typed URL is
+  // correctly removed, and the non-typed URL does not magically appear.
+  URLRow cached_row1;
+  EXPECT_NE(0, mem_backend_->db()->GetRowForURL(row1.url(), &cached_row1));
+  EXPECT_EQ(0, mem_backend_->db()->GetRowForURL(row2.url(), NULL));
+  EXPECT_EQ(0, mem_backend_->db()->GetRowForURL(row3.url(), NULL));
+  EXPECT_EQ(row1.id(), cached_row1.id());
+}
+
+TEST_F(InMemoryHistoryBackendTest, OnURLsDeletedEnMasse) {
+  // Add two typed and one non-typed URLRow to the in-memory database.
+  URLRow row1(CreateTestTypedURL());
+  URLRow row2(CreateAnotherTestTypedURL());
+  URLRow row3(CreateTestNonTypedURL());
+  SimulateNotification(chrome::NOTIFICATION_HISTORY_URLS_MODIFIED,
+                       &row1, &row2, &row3);
+
+  // Now notify the in-memory database that all history has been deleted.
+  scoped_ptr<URLsDeletedDetails> details(new URLsDeletedDetails());
+  details->all_history = true;
+  BroadcastNotifications(chrome::NOTIFICATION_HISTORY_URLS_DELETED,
+                         details.PassAs<HistoryDetails>());
+
+  // Expect that everything goes away.
+  EXPECT_EQ(0, mem_backend_->db()->GetRowForURL(row1.url(), NULL));
+  EXPECT_EQ(0, mem_backend_->db()->GetRowForURL(row2.url(), NULL));
+  EXPECT_EQ(0, mem_backend_->db()->GetRowForURL(row3.url(), NULL));
+}
+
+void InMemoryHistoryBackendTest::PopulateTestURLsAndSearchTerms(
+    URLRow* row1,
+    URLRow* row2,
+    const base::string16& term1,
+    const base::string16& term2) {
+  // Add a typed and a non-typed URLRow to the in-memory database. This time,
+  // though, do it through the history backend...
+  URLRows rows;
+  rows.push_back(*row1);
+  rows.push_back(*row2);
+  backend_->AddPagesWithDetails(rows, history::SOURCE_BROWSED);
+  backend_->db()->GetRowForURL(row1->url(), row1);  // Get effective IDs from
+  backend_->db()->GetRowForURL(row2->url(), row2);  // the database.
+
+  // ... so that we can also use that for adding the search terms. This way, we
+  // not only test that the notifications involved are handled correctly, but
+  // also that they are fired correctly (in the history backend).
+  backend_->SetKeywordSearchTermsForURL(row1->url(), kTestKeywordId, term1);
+  backend_->SetKeywordSearchTermsForURL(row2->url(), kTestKeywordId, term2);
+}
+
+TEST_F(InMemoryHistoryBackendTest, SetKeywordSearchTerms) {
+  URLRow row1(CreateTestTypedURL());
+  URLRow row2(CreateTestNonTypedURL());
+  base::string16 term1(base::UTF8ToUTF16(kTestSearchTerm1));
+  base::string16 term2(base::UTF8ToUTF16(kTestSearchTerm2));
+  PopulateTestURLsAndSearchTerms(&row1, &row2, term1, term2);
+
+  // Both URLs now have associated search terms, so the in-memory database
+  // should cache both of them, regardless whether they have been typed or not.
+  URLRow cached_row1, cached_row2;
+  EXPECT_NE(0, mem_backend_->db()->GetRowForURL(row1.url(), &cached_row1));
+  EXPECT_NE(0, mem_backend_->db()->GetRowForURL(row2.url(), &cached_row2));
+  EXPECT_EQ(row1.id(), cached_row1.id());
+  EXPECT_EQ(row2.id(), cached_row2.id());
+
+  // Verify that lookups will actually return both search terms; and also check
+  // at the low level that the rows are there.
+  EXPECT_EQ(1u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term1));
+  EXPECT_EQ(1u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term2));
+  EXPECT_TRUE(mem_backend_->db()->GetKeywordSearchTermRow(row1.id(), NULL));
+  EXPECT_TRUE(mem_backend_->db()->GetKeywordSearchTermRow(row2.id(), NULL));
+}
+
+TEST_F(InMemoryHistoryBackendTest, DeleteKeywordSearchTerms) {
+  URLRow row1(CreateTestTypedURL());
+  URLRow row2(CreateTestNonTypedURL());
+  base::string16 term1(base::UTF8ToUTF16(kTestSearchTerm1));
+  base::string16 term2(base::UTF8ToUTF16(kTestSearchTerm2));
+  PopulateTestURLsAndSearchTerms(&row1, &row2, term1, term2);
+
+  // Delete both search terms. This should be reflected in the in-memory DB.
+  backend_->DeleteKeywordSearchTermForURL(row1.url());
+  backend_->DeleteKeywordSearchTermForURL(row2.url());
+
+  // The typed URL should remain intact.
+  // Note: we do not need to guarantee anything about the non-typed URL.
+  URLRow cached_row1;
+  EXPECT_NE(0, mem_backend_->db()->GetRowForURL(row1.url(), &cached_row1));
+  EXPECT_EQ(row1.id(), cached_row1.id());
+
+  // Verify that the search terms are no longer returned as results, and also
+  // check at the low level that they are gone for good.
+  EXPECT_EQ(0u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term1));
+  EXPECT_EQ(0u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term2));
+  EXPECT_FALSE(mem_backend_->db()->GetKeywordSearchTermRow(row1.id(), NULL));
+  EXPECT_FALSE(mem_backend_->db()->GetKeywordSearchTermRow(row2.id(), NULL));
+}
+
+TEST_F(InMemoryHistoryBackendTest, DeleteAllSearchTermsForKeyword) {
+  URLRow row1(CreateTestTypedURL());
+  URLRow row2(CreateTestNonTypedURL());
+  base::string16 term1(base::UTF8ToUTF16(kTestSearchTerm1));
+  base::string16 term2(base::UTF8ToUTF16(kTestSearchTerm2));
+  PopulateTestURLsAndSearchTerms(&row1, &row2, term1, term2);
+
+  // Delete all corresponding search terms from the in-memory database.
+  KeywordID id = kTestKeywordId;
+  mem_backend_->DeleteAllSearchTermsForKeyword(id);
+
+  // The typed URL should remain intact.
+  // Note: we do not need to guarantee anything about the non-typed URL.
+  URLRow cached_row1;
+  EXPECT_NE(0, mem_backend_->db()->GetRowForURL(row1.url(), &cached_row1));
+  EXPECT_EQ(row1.id(), cached_row1.id());
+
+  // Verify that the search terms are no longer returned as results, and also
+  // check at the low level that they are gone for good.
+  EXPECT_EQ(0u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term1));
+  EXPECT_EQ(0u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term2));
+  EXPECT_FALSE(mem_backend_->db()->GetKeywordSearchTermRow(row1.id(), NULL));
+  EXPECT_FALSE(mem_backend_->db()->GetKeywordSearchTermRow(row2.id(), NULL));
+}
+
+TEST_F(InMemoryHistoryBackendTest, OnURLsDeletedWithSearchTerms) {
+  URLRow row1(CreateTestTypedURL());
+  URLRow row2(CreateTestNonTypedURL());
+  base::string16 term1(base::UTF8ToUTF16(kTestSearchTerm1));
+  base::string16 term2(base::UTF8ToUTF16(kTestSearchTerm2));
+  PopulateTestURLsAndSearchTerms(&row1, &row2, term1, term2);
+
+  // Notify the in-memory database that the second typed URL has been deleted.
+  SimulateNotification(chrome::NOTIFICATION_HISTORY_URLS_DELETED, &row2);
+
+  // Verify that the second term is no longer returned as result, and also check
+  // at the low level that it is gone for good. The term corresponding to the
+  // first URLRow should not be affected.
+  EXPECT_EQ(1u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term1));
+  EXPECT_EQ(0u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term2));
+  EXPECT_TRUE(mem_backend_->db()->GetKeywordSearchTermRow(row1.id(), NULL));
+  EXPECT_FALSE(mem_backend_->db()->GetKeywordSearchTermRow(row2.id(), NULL));
+}
+
 }  // namespace history